Use image property/attribute in image transformations

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
oleksiy
Posts: 12
Joined: 2014-11-22T16:53:32-07:00
Authentication code: 6789

Use image property/attribute in image transformations

Post by oleksiy »

Is there any way to set an image property (in sequence for example) and use that property for crop/resize/etc?

For example I can do the following (pseudocode):

Code: Select all

image.jpg ( -size 300x300 -annotate 0x0+0+0 "TEXT' -set option:textsize '%wx%h+0+0' ) ( -clone 0 -annotate 0x0+0+0 '%[textsize]' ) -composite
And I will get the correct dimensions string "printed".

But I can't do the following:

Code: Select all

image.jpg ( -size 300x300 -annotate 0x0+0+0 "TEXT' -set option:textsize '%wx%h' ) ( -clone 0 -crop '%[textsize]' -blur 0x7 ) -composite
It seems that -crop simply doesn't parse/resolve this variable.

Is there any way to use variables (options) set with -set in -crop/-resize/etc and not only -label and -annotate?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Use image property/attribute in image transformations

Post by fmw42 »

Not that I know in IM 6 that way. In IM 7, you will be able to do things like that. IM 6 has limited functions that recognize -set options. I do not think crop and resize (or anything which uses geometry) can do that. In -distort, however, you can do computations right in the arguments and in the virtual-canvas that controls size and offset. So you can use -distort SRT to change size and use the viewport to crop. See

http://www.imagemagick.org/Usage/distor ... t_viewport
http://www.imagemagick.org/Usage/distor ... red_square
http://www.imagemagick.org/Usage/distorts/#srt
oleksiy
Posts: 12
Joined: 2014-11-22T16:53:32-07:00
Authentication code: 6789

Re: Use image property/attribute in image transformations

Post by oleksiy »

Many thanks!
Post Reply