Montage: files with different dimension, but right proportions

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?".
myspacee
Posts: 153
Joined: 2007-06-14T02:09:35-07:00

Montage: files with different dimension, but right proportions

Post by myspacee »

Hello,
i've a 'ghetto' IM PHP PicM0nkey tool published on my intranet. It does its job well and simple.

I implemented mosaic tool in these days, and obtain some good result:
Image

Now I need IM magic to avoid too PHP coding. My 'web' tool cut uploaded images in proportion to fit white rectangles you see above.
In proportion, because i don't want to touch uploaded user images. So i obtain, for this example, five images.
http://gazzettannunci.gazzettadimantova ... frm/01.png
http://gazzettannunci.gazzettadimantova ... frm/02.png
http://gazzettannunci.gazzettadimantova ... frm/03.png
http://gazzettannunci.gazzettadimantova ... frm/04.png
http://gazzettannunci.gazzettadimantova ... frm/05.png

How Montage them and obtain this result using IM ?
(Windows ImageMagick 6.9.1-10 Q16 x86 2015-07-25 version)
http://gazzettannunci.gazzettadimantova ... ontage.jpg
Image

thank you for all magic,
m.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Montage: files with different dimension, but right proportions

Post by fmw42 »

Montage cannot do that.

Use -append to stack images 4 and 5. Use -append to stack images 2 and 3. Then use +append to place image1, image2-3, image4-5 side-by-side

Code: Select all

convert 01.png \( 02.png 03.png -append \) \( 04.png 05.png -append \) +append result.png
If you image are too big or not the right dimensions, then you will need to resize and/or crop them to make them fit. This can be done within each parenthesis for each image

Code: Select all

convert \
\( 01.png -resize ... -crop ... +repage \)  \
\( 02.png  -resize ... -crop ... +repage \) \( 03.png  -resize ... -crop ... +repage \) -append \) \
\( 04.png  -resize ... -crop ... +repage \) \( 05.png  -resize ... -crop ... +repage \) -append \) \
+append result.png
myspacee
Posts: 153
Joined: 2007-06-14T02:09:35-07:00

Re: Montage: files with different dimension, but right proportions

Post by myspacee »

Thank you for reply fmw,
i think different approach. I cannot known upload image size (HxW).
So I choose to crop, via web, the right 'slice', in proportion.
(eg:01.png posted is in the right proportion to fit exactly in first rectangle)

My web tool always return 5 'puzzle card', that may fit each other, except for their size.

I think to create a canvas with fixed width and height
(eg: for above example 2000 x 3000 pixel)

Then resize each 'puzzle card' to reach 'reserved' place width and height. (small pieces will be enlarged, large ones shrinked). Then

Code: Select all

convert 01.png \( 02.png 03.png -append \) \( 04.png 05.png -append \) +append result.png
Can be a different, but also valid, way to face up this task ?

thank you for reading,
m.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Montage: files with different dimension, but right proportions

Post by fmw42 »

If you know the size you want to resize for each image, then just include that as per my command above. You can choose to crop or pad if you use -resize and -background and -extent in each parenthesis as I mentioned above. You do not need to know the input sizes, if you know the sizes that you want for each section.

If the images are already the proper aspect ratios, then just append them as in my original command and then resize the result to the final size you want.
myspacee
Posts: 153
Joined: 2007-06-14T02:09:35-07:00

Re: Montage: files with different dimension, but right proportions

Post by myspacee »

Hello,
made some test with raw code :

Code: Select all

convert 01.png -resize 1000 01_res.png
convert 02.png -resize 1000 02_res.png
convert 03.png -resize 1000 03_res.png
convert 04.png -resize 1000 04_res.png
convert 05.png -resize 1000 05_res.png

convert 02_res.png 03_res.png -append result23.png
convert 04_res.png 05_res.png -append result45.png
convert result23.png result45.png +append resultd2345.png
convert 01_res.png resultd2345.png +append -resize 1000 -quality 75 result123456.jpg
On this server we have an old IM installation so Windows/dos syntax is only way to obtain my final goal.

Can you optimize above spartan script, and speed-up things if possible ?
How remove white on bottom image ?
(i think this is due to the fact that the PHP calculations are a bit approximate)

Thank you for all support,
m.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Montage: files with different dimension, but right proportions

Post by fmw42 »

Code: Select all

convert 01.png 02.png 03.png 04.png 05.png -resize 1000 ^
( -clone 1,2 -append ) ^
( -clone 3,4 -append ) ^
-delete 1-4 +append -resize 1000 -quality 75 result123456.jp
clone indices start at 0, so -clone 1 refers to 02.png after resizing

or

Code: Select all

convert 01.png 02.png 03.png 04.png 05.png -resize 1000 ^
( -clone 1,2 -append ) -delete 1,2 ^
( -clone 1,2 -append ) -delete 1,2 ^
+append -resize 1000 -quality 75 result123456.jp
myspacee
Posts: 153
Joined: 2007-06-14T02:09:35-07:00

Re: Montage: files with different dimension, but right proportions

Post by myspacee »

Thank you,
return an error, but maybe Windows bin are too old ? !

Code: Select all

convert.exe: UnrecognizedOption `-append)' @ error/convert.c/ConvertImageComman
d/739.
m.
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Montage: files with different dimension, but right proportions

Post by GeeMack »

myspacee wrote: 2017-12-04T14:57:13-07:00Thank you,
return an error, but maybe Windows bin are too old ? !

Code: Select all

convert.exe: UnrecognizedOption `-append)' @ error/convert.c/ConvertImageComman
d/739.
Make sure you leave a space after "-append" and before the parentheses ")" like this...

Code: Select all

... ( -clone 1,2 -append ) ...
You'll get an error if anything is touching either side of the parentheses that surround code segments.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Montage: files with different dimension, but right proportions

Post by fmw42 »

I made a mistake. There needs to be spaces between text and parentheses. I have corrected that. Thanks GeeMack for catching that.
myspacee
Posts: 153
Joined: 2007-06-14T02:09:35-07:00

Re: Montage: files with different dimension, but right proportions

Post by myspacee »

THANK YOU !
m.
myspacee
Posts: 153
Joined: 2007-06-14T02:09:35-07:00

Re: Montage: files with different dimension, but right proportions

Post by myspacee »

Hello,
take some time to learn how assemble some models, but users are happy.

Another request, how spacing images using fmw42 syntax ?
Try to add:

Code: Select all

 -bordercolor "#ffffff" -border 6
but I want to border all images and then assemble together

Thank you for any help
m.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Montage: files with different dimension, but right proportions

Post by fmw42 »

Code: Select all

convert 01.png 02.png 03.png 04.png 05.png -resize 1000 -bordercolor white  -border 6 ^
( -clone 1,2 -append ) ^
( -clone 3,4 -append ) ^
-delete 1-4 +append -resize 1000 -quality 75 result123456.jp
myspacee
Posts: 153
Joined: 2007-06-14T02:09:35-07:00

Re: Montage: files with different dimension, but right proportions

Post by myspacee »

Thank you again, Picmonk3y trembles :)
myspacee
Posts: 153
Joined: 2007-06-14T02:09:35-07:00

Re: Montage: files with different dimension, but right proportions

Post by myspacee »

Hello again,
try another model but hit my face with my IM limit...

Try to assemble images horizontally :

Code: Select all

convert 01.png 02.png 03.png 04.png -resize 1000 -bordercolor white -border 12 ( -clone 0,1 +append ) -delete 0,1 ( -clone 0,1 +append ) -delete 0,1 -append -resize 1000 -quality 75 1234.png
to obtain this :
Image

And obtain :
Image

Images are in proportion as usual, i think that :

Code: Select all

-resize 1000
horizontally messed up things.

Post my original images there :
http://gazzettannunci.gazzettadimantova ... ert/01.png
http://gazzettannunci.gazzettadimantova ... ert/02.png
http://gazzettannunci.gazzettadimantova ... ert/03.png
http://gazzettannunci.gazzettadimantova ... ert/04.png

if you want help me to learn something new.

Thank you and sorry for questions,
m.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Montage: files with different dimension, but right proportions

Post by fmw42 »

Images 1 and 2 do not have the same height, so +append will add white space to make them both the same height. Similarly for 3 and 4. Thus your images are not the right proportions to append the way you want. You may want to resize the image to have the same heights. With imagemagick 6, you will have to determine the dimension with by preprocessing to figure them out. With imagemagick 7, you can do that inline with -set option:

Try this (unix syntax):

Code: Select all

convert \
\( \( 01.png -resize x498 \) \( 02.png \) +append \) \
\( \( 03.png -resize x497  \) \( 04.png -resize x497 \) +append \) \
-append \
result.png
Post Reply