How to get dimensions after resize?

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
indigoe

How to get dimensions after resize?

Post by indigoe »

Hello,

I'm resizing images to a fixed width but the height varies every time. I would like to add a rounded border which requires knowing the dimensions of the new image. The following code creates an image of some text on white background with some padding.

Code: Select all

convert -background white -fill black \
-font Helvetica -pointsize 200 label:"TEXT HERE" \
-bordercolor white -border 20x20 \
-resize 300 \
image.png
According to one of the usage pages I could use 'roundrectangle 1,1 %[fx:w-10],%[fx:h-10] 15,15' but the parameters are not substituted in the -draw command. Is there a solution other than using a temp file? I would like to have all this done in the same pass. Is this possible?

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

Re: How to get dimensions after resize?

Post by anthony »

Currently that is next to imposible from the same command using the command line. It is easy in a language API where you can stop to extract information about images to create the arguments for later operations.

One method using multiple commands is shown in ...
http://www.imagemagick.org/Usage/thumbn ... ded_border
A shell can also read the output from identify and calculate the arguments for the next command, but that means saving the intermediate image in some temporary file such as MIFF: of MPC: See IM exmaples 'files' for details of these formats.

Also look at the script "de-pixelate" and "jigsaw" in IM example scripts area for ways to handling temporary files.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
indigoe

Re: How to get dimensions after resize?

Post by indigoe »

Thank you for the reply. I got it working now in 3 commands and if I can come up with something cool I will probably look at the php library.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to get dimensions after resize?

Post by anthony »

There is plans to add some special extra syntax to set command line arguments basied on images in memory. It is on hold while I think about it and finish up some other additions to IM (distortion resampling and color auto-levels). Though even that solution would not pass that type of into into 'draw' commands as that interface is rescrited by its need to handle SVG images correctly.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply