How to crop multiple images and place them in one image?

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
kleinstadtmc

How to crop multiple images and place them in one image?

Post by kleinstadtmc »

i try to crop four images and place them resized into one new image
but it doesnt work right
maybe somebody know it better
here is my code:

Code: Select all

usr/bin/convert -size 70x50 xc:skyblue \ 
one.jpg -crop 153x229+0+0 -geometry 31x21+2+2 -composite \ 
two.jpg -crop 153x229+0+0 -geometry 31x21+36+2 -composite \ 
three.jpg -crop 281x375+1+1 -geometry 31x21+2+26 -composite \ 
four.jpg -crop 281x375+0+0 -geometry 31x21+36+26 -composite \ 
final.jpg
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to crop multiple images and place them in one image?

Post by fmw42 »

Your crop size and geometry size are not consistent and your crop size is bigger than your skyblue background.

If you want a self-expanding background, then see layers composite
http://www.imagemagick.org/Usage/layers/#merge
kleinstadtmc

Re: How to crop multiple images and place them in one image?

Post by kleinstadtmc »

the new image must have a fix size

but i have to crop and resize the four images before i place them into the new image,
and i don't want to save the four images before on my webspace

is it possible to do this all in one ?
1. cropping the four images
2. resize the four images
3. place them into a new image
4. save the new image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to crop multiple images and place them in one image?

Post by fmw42 »

convert -size BACKGROUNDWIDTHxBACKGROUNDHEIGHT xc:BACKGROUNDCOLOR \
\( IMAGE1[CROPWIDTH1xCROPHEIGHT1+CROPLOCX1+CROPLOCY1] -resize NEWWIDTH1xNEWHEIGHT1 \) \
-geometry +PLACEMENTX1+PLACEMENTY1 -compose COMPOSEMETHOD -composite \
\( IMAGE2[CROPWIDTH2xCROPHEIGHT2+CROPLOCX2+CROPLOCY2] -resize NEWWIDTH2xNEWHEIGHT2 \) \
-geometry +PLACEMENTX2+PLACEMENTY2 -compose COMPOSEMETHOD -composite \
... etc for all other images ... OUTPUTIMAGE

see the use of \(...\)

http://www.imagemagick.org/Usage/basics/#parenthesis

see the use of [...] brackets for cropping

http://www.imagemagick.org/script/comma ... essing.php


The BACKGROUND SIZE determines how big your output image will be.
kleinstadtmc

Re: How to crop multiple images and place them in one image?

Post by kleinstadtmc »

this seemed to be the right solution but te final image has not the right size
it has 30x21 not 70x50

here is my code:

Code: Select all

/usr/bin/php-smed/convert -size 70x50 xc:skyblue \ 
\( one.jpg[333x220+0+0] -resize 31x45 \) \ 
-geometry +2+2 -compose src-over -composite \ 
\( two.jpg[151x229+0+0] -resize 31x21 \) \ 
-geometry +36+2 -compose src-over -composite \ 
\( three.jpg[174x262+37+10] -resize 31x21 \) \ 
-geometry +36+26 -compose src-over -composite \ 
final.jpg
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to crop multiple images and place them in one image?

Post by fmw42 »

try:

/usr/bin/php-smed/convert -size 70x50 xc:skyblue \
\( one.jpg[333x220+0+0] -resize 31x45 \) \
-geometry +2+2 -compose src-atop -composite \
\( two.jpg[151x229+0+0] -resize 31x21 \) \
-geometry +36+2 -compose src-atop -composite \
\( three.jpg[174x262+37+10] -resize 31x21 \) \
-geometry +36+26 -compose src-atop -composite \
final.jpg

or

/usr/bin/php-smed/convert -size 70x50 xc:skyblue \
\( one.jpg[333x220+0+0] -resize 31x45 \) \
-geometry 31x45+2+2 -compose src-atop -composite \
\( two.jpg[151x229+0+0] -resize 31x21 \) \
-geometry 31x21+36+2 -compose src-atop -composite \
\( three.jpg[174x262+37+10] -resize 31x21 \) \
-geometry 31x21+36+26 -compose src-atop -composite \
final.jpg

Note there is no src-over. You want either over or src-atop.

If that does not work, post links to your images and I will test it out
kleinstadtmc

Re: How to crop multiple images and place them in one image?

Post by kleinstadtmc »

ok i tried it without the -resize
now the size of the final.jpg is right

but the size of the three images not...
the first pic should have 31x45 but it is 31x20
the second pic should have 31x21 but it is 16x21
and so on...

where is the problem?

Code: Select all

/usr/bin/php-smed/convert -size 70x50 xc:skyblue \ 
\( one.jpg[326x215+0+0] \) \ 
-geometry 31x45+2+2 -compose src-atop -composite \ 
\( two.jpg[159x215+0+0] \) \ 
-geometry 31x21+36+2 -compose src-atop -composite \ 
\( three.jpg[159x215+0+0] \) \ 
-geometry 31x21+36+26 -compose src-atop -composite \ 
final.jpg
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to crop multiple images and place them in one image?

Post by fmw42 »

I never said to remove the -resize. However, -composite does allow you to use the -geometry size to do resizing, but I have never tried it to be sure it works.

Post links to your pictures so we can test.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to crop multiple images and place them in one image?

Post by anthony »

Your original problem is that -crop crops ALL images, not just the last read image!!!!!

only -geometry does not do this and it is a special command.


Solution use Parenthesis. See IM examples, Basics.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply