Page 1 of 1

-set option:

Posted: 2008-05-24T07:01:34-07:00
by rmabry
This works; I get an image of text showing the size of the rose:

Code: Select all

convert rose: -set option:mylabel "%wx%h" -delete 0 label:"%[mylabel]" option1.png 
Image

This works; I get the same thing but I can specify the height of the image:

Code: Select all

convert rose: -set option:mylabel "%wx%h" -delete 0 ( -size x100 label:"%[mylabel]" ) option2.png 
Image

But to what extent can I plop mylabel into other places, such as an argument to -size or inside a -draw string? The following does not work (error messages follow). I'm trying to grab the size of rose: and use it for sizing a gradient. Is it futile or is my syntax wrong?

Code: Select all

convert rose: -set option:mylabel "%wx%h" -delete 0 ( -size "%[mylabel]" gradient:yellow-red ) option.png
convert: Must specify image size `yellow-red'.
convert: missing an image filename `option.png'.

(Changing "%[mylabel]" to 20x20 works just fine, so the syntax seems otherwise correct.)

I'm on WinXP, IM 6.4.1.

Rick

Re: -set option:

Posted: 2008-05-24T08:11:11-07:00
by Bonzo
Anthony did something like that a while ago using FX but I can not remember how he did it or what post it was on !

Re: -set option:

Posted: 2008-05-24T08:39:47-07:00
by rmabry
Bonzo wrote:Anthony did something like that a while ago using FX but I can not remember how he did it or what post it was on !
Hi Bonzo,

I was actually browsing Anthony's examples when I learned of it in the first place.
Now I'm trying to see how far it extends.

Here's where I encountered it:

http://www.imagemagick.org/Usage/transform/#fx_other

It is clear from my examples that it isn't restricted to FX. So my question is, what are its restricted usages, and why?

Rick

Re: -set option:

Posted: 2008-05-26T17:02:27-07:00
by anthony
The 'option:' settings are essentially 'out of band' user string settings that the format % escape can access.

It was added as a step toward trying to get IM to use image options in setting other options. For example. To create an image 10 pixels larger than an example image, or with a specific color directly extracted from an image. This of course is not yet available, in the command line API, but easy in other programmed API's.

Also see See "User Defined Escapes"
http://imagemagick.org/Usage/text/#user_escapes

-draw does NOT use % escapes as it interfers with SVG, however annotate does do % escapes. So you can draw the string on other image using -annotate.

The format escape %[fx:...] can also access (and do math) on the information from any image in the current image sequence too.

Fred is now making use of this to do some basic image math in his scripts for floating point and to avoid OS differences, and 'bc' difficulties.

Re: -set option:

Posted: 2008-05-26T18:18:48-07:00
by rmabry
Thanks, Anthony.

From what you say I am left with the opinion that I came with, which is that such "escaped" info is available for strings but not (yet) for input into options such as -size.

In case you've been following the thread, Text with gradient stroke?, what I'm up to is trying to get a gradient, automatically sized, for use in -fill or -strokefill. Any advice for froesi (see the end of that thread) would be appreciated, I am sure. I ran out of ideas, other than to use PerlMagick or an API, as you mentioned.

Rick

Re: -set option:

Posted: 2008-05-26T21:08:03-07:00
by anthony
The problem is that '%' is often a special flag to options like -size that have a geomerty type argument.

One of the solutions we have thought about is that if the option argument is prefixed with a '=' then the whole argument that follows that inital '=' will be put though escape expandion.

However the problem is that the convert/mogrify command line API is very old with a lot of old handling from previous versions, such as IMv5 and legacy argument handling. For example it current processes the command line twice!!!!

What is really needed is for the command line API to be re-written in such as way as to allow...
  • argument processing, purely in the IMv6 argument ordering
  • the ability to read all arguments from a file (convert scripts!). This could allow you to call IM, such as from PHP, without needing to do so though a shell wrapper. That is
    start IM as a piped open, and feed the commands to it.
  • a proper separation of command line API from the IM core library
  • a fully defined argument processing methology
  • argument string from file ("@filename")
  • insertion of numbers (with/without math processing) of values extracted from images already in memory
  • a proper handling of global settings, verses image attribute settings. Say snapshot and restore global settings.
  • Posible loop mechisims. Such as Loop over images, repeat X times, or look with some number, accessable as a percent escape.
  • if-then-else constructs for command line/script handling.
This re-write may require some re-coding of mogrify which current does some very weird argument handling to seperate the list of images to process, from the operations and settings needed to process them. For example some settings need to be pre-set before reading the first image!

Actually is a "loop over image list" type construct is implemented, then it may be posible to make 'morgify' a special case of convert, just as 'montage' is a special convert with post processing of the final image list in memory.

This new command line API could in fact be done as a separate command to convert, but will need someone to get the ball rolling and keep it moving. One previous attempt that failed (probably was done before IM was ready for it) was "conjure". the new version would have to be BOTH command line and script capable, and do what convert does to properly replace convert.

This may be a good topic for discussion on the devlopers forum!