Density escape values in FX expressions?

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Density escape values in FX expressions?

Post by GeeMack »

Using ImageMagick 7.0.0-0 Q16 x64 2015-12-19 from the command line and batch files in Windows 7 Pro 64.

I'm building some scripts to make various labels to print with finished sizes and crop marks in inches and fractions. I'd like to calculate some dimensions in my IM7 commands using the resolution, or density values. These are available as IM escape characters "x" and "y" in the "identify -format..." command or when printing the density values in a "label:" or "-annotate" command. I'd like to use the density escapes in FX expressions, too.

As a simplified example, where this command works...

Code: Select all

magick -size 400x400 xc:blue -gravity center -extent %[fx:w+(72/2)]x%[fx:h+(72/2)] clipboard:
... a command like this fails...

Code: Select all

magick -size 400x400 xc:blue -gravity center -extent %[fx:w+(x/2)]x%[fx:h+(y/2)] clipboard:
It would be great if I could feed source images to some scripts without manually checking the resolutions and calculating those values. Is there any chance the %[x] and %[y] density escapes might be used in FX expressions in future releases of IM7?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Density escape values in FX expressions?

Post by fmw42 »

see http://www.imagemagick.org/script/fx.php

try using resolution.x and resolution.y rather than x and y
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Density escape values in FX expressions?

Post by GeeMack »

fmw42 wrote:try using resolution.x and resolution.y rather than x and y
I was looking at that page earlier and apparently was thinking I'd find what I wanted in the single letter symbols. Yep, I overlooked the perfect answer just a few lines later. That does exactly what I was looking for. Thanks much for your speedy reply!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Density escape values in FX expressions?

Post by fmw42 »

I do not believe that all string formats listed at http://www.imagemagick.org/script/escape.php can be used directly in fx escape computations. For many you will have to get the string format and put it into a variable first. Then use the variable in the fx escape calculation. At least that is how it is in IM 6. IM 7 may be different.
Post Reply