Page 1 of 1

How to get dimensions after resize?

Posted: 2007-08-18T22:21:57-07:00
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.

Re: How to get dimensions after resize?

Posted: 2007-08-21T00:47:52-07:00
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.

Re: How to get dimensions after resize?

Posted: 2007-08-21T07:28:10-07:00
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.

Re: How to get dimensions after resize?

Posted: 2007-08-22T00:24:04-07:00
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.