How to resize, compose and save as multiple file?

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
immortaz

How to resize, compose and save as multiple file?

Post by immortaz »

Hi,

I'm totally new to this but willing to learn.

Below are what I want to do.

I have a few big images as background. The image dimension is 500x500 - ratio 1:1
I want to resize to multiple dimension eg. 100x100, 300x400, 400x300.
Note that some of the dimensions are not in 1:1 ratio. I am using the -shave and -crop to overcome that.

Next, I have another few images with transparent background. Dimension is also 500x500.
I want to embed the image on the previous background. I need to do the resizing first to make sure the image is properly position at the center of the background.

I know I can do this using multiple call of convert command but this is not the best way to do it. I think it can be done using a single convert command. I tried many times but still failed.

Note that this is not watermarking processes because it involves multiple background images with multiple object images.

Hope someone can help me out.

Thanks and best regards,
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to resize, compose and save as multiple file?

Post by fmw42 »

I believe that you can only do the processing for one output image at a time. But you can put all the steps inside one command. Here is a simple case assuming that the foregroundimg contains (alpha-channel) transparent areas:

convert \( backgroundimg -resize 100x100! \) \( forgroundimg -resize 100x100! \) -compose over -composite outimage


see:

http://www.imagemagick.org/Usage/compose/
http://www.imagemagick.org/Usage/layers/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to resize, compose and save as multiple file?

Post by anthony »

You can also write and discard images that are generated before moving to the next image all in the same command.
http://imagemagick.org/Usage/files/files/#write

As for resizing you may like to look at IM examples Thumbnailing for some methods.


Basically you can do al lot, it is just a matter of figuring out, or finding the right recipe.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
immortaz

Re: How to resize, compose and save as multiple file?

Post by immortaz »

Hi,

Thanks for the prompt replies.

I managed to get this command works :)

convert background-img.png ( +clone -resize 130x -write C:\im\bg-final\130x130\12345.gif +delete ) ( +clone -resize x160 -shave 20x0 -write C:\im\bg-final\120x160\12345.gif +delete ) ( +clone -resize x320 -shave 56x0 -write C:\im\bg-final\208x320\12345.gif +delete ) null:

It can resize the background image in multiple sizes and save to predefine directory.

I am having problems to add the foreground image which have transparent area onto the background images to create a final composite images. I am not really get the ideas on how to achieve this using single convert command yet especially on file handling and how the command works for multiple operation.

I need your advise on how to combine both operation (resize and compose) and save in a predefine directory based on the image dimensions.

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

Re: How to resize, compose and save as multiple file?

Post by anthony »

Basically the command is a list of settings and operations.
read an image
start a new image sequence and copy (clone) the previous image into that sequence)
rezise it, write it and delete it before closing the (now empty) sequence)
Repeat as many times as needed.

The Delete just removes the just saved results, otherwise each image will be added to the end of the master, or toplevel image sequnence. +clone only copies the LAST image of the previous (master) image sequence. For a specific image you can use -clone {number} to specify an image (counting from zero).

If you want to do other things you can just add them to the list of things to do.

For example, within a sequence you can read (or clone into the sequence) another image compose it, then write/delete the result before closing the sequence.

Code: Select all

  convert   image.png  logo.png \
         \( -clone 0 -resize 130x -clone 1 -geometry +50+50 -composite \
               -write output_130.png  +delete \) \
         \( .... \) \
         \( .... \) \
         \( .... \) \
        null:
This will resize the background image, but not the logo being composed on top of each resized clone of the image.
For more on Parenthesis, Clone etc, See IM Examples, Basics.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply