Hello Everyone
I have discovered ImageMagick through my php development and would like to know if ImageMagick offers sufficient control to solve my problem.
I have a list of jpg files, together with a list of (x,y) coordinates for these files, and need to construct a master file that puts all these images in the file at the required coordinates. Reading through the documentation, I can't work out out yet whether montage (for example) would let me set the coordinates of each image, or whether it deals with just the overall image dimensions.
So my question is, can ImageMagick actually do what I need it to do, or is this asking too much and should I look elsewhere?
Many thanks
Bob
Will I be able to do this with ImageMagick
-
- Posts: 5
- Joined: 2011-01-29T16:41:23-07:00
- Authentication code: 8675308
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Will I be able to do this with ImageMagick
You would need to write a script to overlay each image on a background at the correct location, if the number of images is large. IM can use a file with a list of images, but the commands you need have to have the coordinates manually specified unless you script it. Then the script can access the file of images and coordinates and loop over each one and place it at the desired location.
But if you only have a few images that can be specified in a simple list of images in one command line, then IM can flatten or mosaic a number of images into a larger image with each one specified to a given x,y coordinate in the composite image.
For new IM users good reading is at http://www.imagemagick.org/Usage/
For your specific problem, see
http://www.imagemagick.org/Usage/layers/
and especially
http://www.imagemagick.org/Usage/layers/#flatten
http://www.imagemagick.org/Usage/layers/#mosaic
But if you only have a few images that can be specified in a simple list of images in one command line, then IM can flatten or mosaic a number of images into a larger image with each one specified to a given x,y coordinate in the composite image.
For new IM users good reading is at http://www.imagemagick.org/Usage/
For your specific problem, see
http://www.imagemagick.org/Usage/layers/
and especially
http://www.imagemagick.org/Usage/layers/#flatten
http://www.imagemagick.org/Usage/layers/#mosaic
-
- Posts: 5
- Joined: 2011-01-29T16:41:23-07:00
- Authentication code: 8675308
Re: Will I be able to do this with ImageMagick
Many thanks! I have had a play with the composite function and it seems I can do exactly what I want. I have become an overnight IM fan. I had been doing my thumbnail processing with php/GD and thought I would also combine my images in GD, but the memory requirements were ridiculous. Now it seems I can generate the final image off-line running these commands in a script.
Thanks again.
Thanks again.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Will I be able to do this with ImageMagick
You may be interested in the examples shown at
http://www.imagemagick.org/Usage/layers/#example
this has a look generating images and piping it in a stream to a separate image machine 'layering' command.
http://www.imagemagick.org/Usage/layers/#example
this has a look generating images and piping it in a stream to a separate image machine 'layering' command.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
-
- Posts: 5
- Joined: 2011-01-29T16:41:23-07:00
- Authentication code: 8675308
Re: Will I be able to do this with ImageMagick
Thanks Anthony. I am still learning my way around IM and all these tips are very useful. Initially I was doing stuff like this:
and it was taking forever. Presummably that was very inefficient as it allocated an image at the start that was as big as I would need at the end of the process and kept having to process the big image. Now I am doing stuff like this: where the image is incrementally increased in size, so the execution time is manageable (still 5mins, but I can possibly live with that). With more experience I hope to reduce that further. I have read that running commands from PHP can be quicker than running from the command line so hope to ty that later. Thanks for your input.
Code: Select all
convert -size 6733x4607 xc:white -fill white -stroke black^
-strokewidth 2 -draw "rectangle 1,1,6732,4606" al1_main_design.gif
composite -geometry +295+340 small_ollie.gif al1_main_design.gif al1_main_design.gif
composite -geometry +1559+340 small_ollie.gif al1_main_design.gif al1_main_design.gif
composite -geometry +2823+340 small_ollie.gif al1_main_design.gif al1_main_design.gif
composite -geometry +4087+340 small_ollie.gif al1_main_design.gif al1_main_design.gif
composite -geometry +5351+340 small_ollie.gif al1_main_design.gif al1_main_design.gif
composite -geometry +295+1377 small_ollie.gif al1_main_design.gif al1_main_design.gif
composite -geometry +5351+1377 small_ollie.gif al1_main_design.gif al1_main_design.gif
composite -geometry +295+2414 small_ollie.gif al1_main_design.gif al1_main_design.gif
composite -geometry +5351+2414 small_ollie.gif al1_main_design.gif al1_main_design.gif
composite -geometry +295+3451 small_ollie.gif al1_main_design.gif al1_main_design.gif
composite -geometry +1559+3451 small_ollie.gif al1_main_design.gif al1_main_design.gif
composite -geometry +2823+3451 small_ollie.gif al1_main_design.gif al1_main_design.gif
composite -geometry +4087+3451 small_ollie.gif al1_main_design.gif al1_main_design.gif
composite -geometry +5351+3451 small_ollie.gif al1_main_design.gif al1_main_design.gif
Code: Select all
convert -page +295+340 small_ollie.gif -page +1559+340 small_ollie.gif^
-page +295+340 small_ollie.gif^
-page +1559+340 small_ollie.gif^
-page +2823+340 small_ollie.gif^
-page +4087+340 small_ollie.gif^
-page +5351+340 small_ollie.gif^
-page +295+1377 small_ollie.gif^
-page +5351+1377 small_ollie.gif^
-page +295+2414 small_ollie.gif^
-page +5351+2414 small_ollie.gif^
-page +295+3451 small_ollie.gif^
-page +1559+3451 small_ollie.gif^
-page +2823+3451 small_ollie.gif^
-page +4087+3451 small_ollie.gif^
-page +5351+3451 small_ollie.gif^
-page +1+1 line.gif^
-page +6234+4603 line.gif^
-background white -layers merge +repage seb_a1.gif
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Will I be able to do this with ImageMagick
It is certainly worth trying, but you might want to see some timing tests at viewtopic.php?f=4&t=16779I have read that running commands from PHP can be quicker than running from the command line so hope to ty that later.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Will I be able to do this with ImageMagick
Yes and as it was saving to gif all teh IM IM had to so a lot of work and an lot of IO.bobthebuilder wrote:Thanks Anthony.
it was taking forever. Presummably that was very inefficient as it allocated an image at the start that was as big as I would need at the end of the process and kept having to process the big image.
Your second method will avoid much of that.
Actually IM -layers option will scan though the image and calculate the final image size once, and create it (with the current background color). It them composes each image at the virtual offset (page) given onto that larger image, and junk everything.where the image is incrementally increased in size, so the execution time is manageable (still 5mins, but I can possibly live with that).
However one speed up is to NOT read that one image over an over. (assuming you are only composing that single image). But read it once and clone it. However you will need to change the page offset of the clone (already in memory) rather tha using -page to set it for an image being read in.
Code: Select all
convert small_ollie.gif \
\( -clone 0 -repage +295+340 \) \
\( -clone 0 -repage +1559+340 \) \
\( -clone 0 -repage +2823+340 \) \
....
-delete 0 \
-background white -layers merge +repage result.gif
PS if you know what the final size, and want the 'origin' (0,0 pixel), then you can just set the size using the first image. No need for the final repage in that case.
Code: Select all
convert -page 6235x4604 small_ollie.gif \
\( -clone 0 -repage +295+340 \) \
...
-background white -layers mosaic result.gif
Read the other parts of the layered image examples.
http://www.imagemagick.org/Usage/layers/
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/