Joining images with different sizes

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
iuiz
Posts: 2
Joined: 2011-02-15T14:05:05-07:00
Authentication code: 8675308

Joining images with different sizes

Post by iuiz »

Hi,

I got several Images that are mostly sized by times of 40. For example 40x40 or 40x80 or 80x200. I want to combine all these images into a single image (to use in a tile editor). However the problem is that there are a few Images that have the wrong size. For example 38x40 or 40x200. Splitting them when they are larger then 40nx40m with n, m beeing natural numbers is no problem. But the images have to be at least 40x40.

Example: If I have these 5 Images (with one letter representing 20x20 pixels):

Code: Select all

Img1   Img2   Img3   Img4   Img5
xx      b       oo     yyy    ww
xx      b       oo     yyy    ww
                              ww 
I want to get the following result:

Code: Select all

xxb ooyyy wwww
xxb ooyyy ww     
With spaces also beeing 20x20 pixels.

What I am currently trying:
montage -adjoin -geometry +0+0 -tile 20x -Crop 40x40 ...LONG_LIST_OF_IMAGES... -background none foo.png

(-background none is for keeping the alpha channels of the pictures)

I hope you can help me.


Greetings,

iuiz
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Joining images with different sizes

Post by anthony »

I am not quite certain what you want. is each letter a 'croped tile'?

In the resulting images seems to be different sizes. Montage will generally always produce the same number of 'tiles' per image


Also -adjoin is an output setting. You probably should have that at the end.

Simularly your images being input should be at the start of the command

Code: Select all

   montage   input_images    .....  -adjoin   output_%d.jpg
Finally control settings for 'montage' (like -geometry) should be at near the end, so they don't interfer with your other per-processing of images before passing them to monage's control at the end.

See the example in,,,
http://www.imagemagick.org/Usage/montage/#reuse
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
iuiz
Posts: 2
Joined: 2011-02-15T14:05:05-07:00
Authentication code: 8675308

Re: Joining images with different sizes

Post by iuiz »

Hi,
sorry if I had troubles explaining my problem. I uploaded an example, that should show my problems, with a screenshot of the tile ediotor for which explains why I need this ;).
http://rapidshare.com/files/448272466/example.tar.gz

The command I try on this example is the following: montage -crop 40x40 -tile 20x c1-bm.png c1-r1.png tab-bb.png tab-bl.png -adjoin -geometry +0+0 output.png

I just want to have each of the file split into 40x40 pictures and merged together in one picture. Most things work, but what is currently missing, is that images that are smaller then n times 40 are scaled to n times 40. But the normal scale will not work, as I want to fill the new space with transparent pixels.
So if I have a picture that has 38 pixels I want to add 2 transparent pixels.

Thx,

iuiz
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Joining images with different sizes

Post by anthony »

OK I think I understand.

First forget montage, it is a specialised application designed for generate arrays of labeld and resized thumbnails. You will end up fighting its normal processing to get your exact requirements.

Next you need to remember that when you do a -crop 40x40 to generate 'tiles' you may not get 40x40 pixel tiles. The images also retain there original 'offset' from which they came, as some people want to save that information with each image. Remove that offset (and original canavs size) info using +repage. See Tile Cropping
http://www.imagemagick.org/Usage/crop/#crop_tile

The actual images will be 40x40 or smaller. but for source images that are not a multiple of this size you will get smaller images.

The solution -extent 40x40 to 'pad-out' the images to exactly 40x40 pixels with the current background color (white by default, unless the source image has its own default (EG: GIF file format) so for transparency you need to ensure the images has 'alpha' -alpha Set, and you set the background color with -background None.

See Extent for more details and options.
http://www.imagemagick.org/Usage/crop/#extent

then you just need to +append (the plus is for horizontal append)
http://www.imagemagick.org/Usage/layers/#append

So here is the command, each line being a specific image process for easier reading...

Code: Select all

   convert images...  -alpha Set \
       -crop 40x40 +repage \
       -background None -extent 40x40 \
       +append    tile_image.png
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply