LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-13-2009, 02:55 PM   #1
diN0bot
LQ Newbie
 
Registered: Mar 2009
Posts: 3

Rep: Reputation: 0
Compose two smaller images into one larger image


Hi,

I've been using python's PIL (import Image in py2.5) and the command line utility ImageMagick to add text to images and compose images.

I can't figure out how to get the composed image not to crop. That is, suppose I compose A onto B to create C. A is short and wide, while B is tall and narrow. I'd like C to be tall and wide, but instead it has the same dimensions as B.

Code:
A = [-------]
B = [x]
    [x]
    [x]

desired
C = [-------]
    [x......]
    [x......]
The width of A is determined by dynamic text. My current solution is to get the width and height of A and B, and then create a maximally sized image, T, onto which I compose B and then A.

I'm just wondering if there is some way to streamline this. Can ImageMagick do this for me? These operations take a non-trivial amount of time.

Thx.
 
Old 03-13-2009, 07:40 PM   #2
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,196

Rep: Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044
Code:
convert a.svg b.gif -append c.jpg
Of course this works for all files in the same format as well. It does exactly what you describe.

The only thing is, it is not fast. If you say that these operations take a non trivial amount of time, I assume you mean execution time.

When I appended a 1024x70 and a 700x1050 image, I estimate the time at 1-2 seconds on a 1700+ MHz AMD Duron.

The culprit seems to be identify: indentiying 1024x70 is instantaneous, identifying the 700x1050 to a noticable amount of time. I think that IM does what you did in 3 statements.

jlinkels
 
Old 03-13-2009, 09:31 PM   #3
diN0bot
LQ Newbie
 
Registered: Mar 2009
Posts: 3

Original Poster
Rep: Reputation: 0
jlinkels, thanks for the reply.

-append is not the option i'm looking for. It literally appends (or stacks) images one after the other:

Code:
A = [xx]
B = [yyy]

convert A B -append C

C = [xx.]
    [yyy]

I'd like to do the equivalent of python's Image.paste, or ImageMagick's convert/compose -draw option:

Code:
A = [xx]
B = [yyy]

compose A B C

C = [xxy]
 
Old 03-14-2009, 08:14 AM   #4
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,196

Rep: Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044
Code:
A = [xx]
B = [yyy]

convert A B -append C

C = [xx.]
    [yyy]
I see. You want to put the banner on top of the narrow image, and thereby you want the large image to cause the narrow image's background to stretch so it accomodates the wide one.

What if you
1. create an image out of the wide one, but reduce it to 1 pix in height
2. append the narrow one to this one pix image, will cause to stretch the background.
3. Then paste the wide banner on top of the composite what you got

It will not be cropped (the image is widened now), and only one pixel higher than it should be.
If you are a purist, paste the wide banner with y=+1 offset, and crop the composite image to cut off the 1 pixel high helper image.

Does that make sense?

jlinkels
 
Old 03-15-2009, 12:45 AM   #5
diN0bot
LQ Newbie
 
Registered: Mar 2009
Posts: 3

Original Poster
Rep: Reputation: 0
thanks for sticking with this topic, though i have to confess that it's not a big deal. i end up with something kind of like what you suggest, only i simply create an appropriately sized image from the get go, rather than appending (your steps 1 and 2). perhaps appending is much faster?

my biggest problem is actually that photoshop compressed png's get mucked up somehow, and when i past a masked icon on top of the image it comes out noisy. it's as though white is used as the transparency color, even though that part is not supposed to be transparent. works fine on pngs created using open source image programs.

photoshop is known for ignoring image formats in favor of proprietary formats, so perhaps that's the problem. perhaps it's the compression. unfortunately, i expect users will use photoshop a bunch. i'm not sure how to test for position failure, though, so it's a sticky situation.

the final images have to be les than 800kb, so compression is likely.

you can check out the app here: http://whynoti.org
 
  


Reply

Tags
imagemagick, python


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy Image of System to larger drive villumanati Fedora 3 03-16-2009 10:57 PM
Restored Partimage image on a larger partition, problems. Romanus81 Linux - Hardware 1 01-02-2009 12:34 AM
Create Smaller USB Flash Drive Image? Githlar Linux - Software 3 09-25-2007 01:07 PM
smaller drive to larger drive duplication mystery midlifecrisis Solaris / OpenSolaris 6 02-01-2006 08:23 AM
Help Making Topologilinux 5 Image File Larger Garibaldi3489 Slackware 1 10-31-2004 12:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration