LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Compose two smaller images into one larger image (https://www.linuxquestions.org/questions/linux-software-2/compose-two-smaller-images-into-one-larger-image-711414/)

diN0bot 03-13-2009 01:55 PM

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.

jlinkels 03-13-2009 06:40 PM

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

diN0bot 03-13-2009 08:31 PM

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]


jlinkels 03-14-2009 07:14 AM

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

diN0bot 03-14-2009 11:45 PM

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


All times are GMT -5. The time now is 02:01 PM.