Page 1 of 1
Calculating with varaiables
Posted: 2017-02-26T12:39:54-07:00
by Videomajk
Hello
I have a question regarding how to use parameters definde with -set option together with fx percent escapes.
This is an example from
http://www.imagemagick.org/Usage/distorts/#distort:
Code: Select all
convert rose: -set option:rw %w -set option:rh %h +delete \
logo: -alpha set -virtual-pixel transparent \
+distort Affine '0,0 0,0 %w,0 %[rw],0 0,%h 0,%[rh]' \
+repage logo_sized_as_rose.png
This example saves the dimensions from one image and resize another image to match the size of the first one.
The width and height for the original image is first defined in the first line into the parameters rw and rh, and then used in the distort command by a percent escape: %[rw] and %[rh].
OK, now to my question. Let's say I would like the new image to be twice the size of the original image. Is it possible to use the rh and rh parameters in an fx commands, something like this:
Code: Select all
+distort Affine '0,0 0,0 %w,0 %[fx:rw*2],0 0,%h 0,%[fx:rh*2]'
I've tried this particular way of writning, but it doesn't work. Is there a way of doing this?
I'm using IM 6.9.7 on Win 10
Re: Aclculating with varaiables
Posted: 2017-02-26T12:44:44-07:00
by fmw42
Do the calculations in the -set option part.
-set option:rw "%[fx:w*2]"
Code: Select all
convert rose: -set option:rw "%[fx:w*2]" -set option:rh "%[fx:h*2]" +delete \
logo: -alpha set -virtual-pixel transparent \
+distort Affine '0,0 0,0 %w,0 %[rw],0 0,%h 0,%[rh]' \
+repage logo_sized_as_rose.png
Re: Aclculating with varaiables
Posted: 2017-02-26T13:00:11-07:00
by Videomajk
Hello and thank you.
I have figured that out, but If I want to do something more complicated than this example, where I need different fractions of the rh and rw for different part of the image. Is the only way to do that to set different parameters with -set:option?
Re: Aclculating with varaiables
Posted: 2017-02-26T14:33:53-07:00
by GeeMack
Videomajk wrote: ↑2017-02-26T13:00:11-07:00... but If I want to do something more complicated than this example, where I need different fractions of the rh and rw for different part of the image. Is the only way to do that to set different parameters with -set:option?
You should be able to do those calculations directly in the "-distort" operation. Something like...
Code: Select all
... +distort Affine '0,0 0,0 %[w],0 %[fx:w*2],0 0,%[h] 0,%[fx:h/3]' ...
These sorts of calculations can only be done in limited places with IM6, "-set", "-format", and "-distort" probably are the most commonly used. If you have a way to migrate to a newer version, you can use "%[fx:...]" calculations almost anywhere with IM7.
Re: Calculating with varaiables
Posted: 2017-02-26T14:40:10-07:00
by Videomajk
Okey, then I might concider migrating to IM7. My problem is that I have a Lightroom plugin that not yet support IM7 and I doubt that I can have both versions installed at the same time.
Re: Calculating with varaiables
Posted: 2017-02-26T14:46:56-07:00
by GeeMack
Videomajk wrote: ↑2017-02-26T14:40:10-07:00Okey, then I might concider migrating to IM7. My problem is that I have a Lightroom plugin that not yet support IM7 and I doubt that I can have both versions installed at the same time.
I have IM6 and IM7 both installed on my Windows 10 64 machine, and both work perfectly. I installed them in different folders, of course, something like "C:\Program Files\ImageMagick\" and "C:\Program Files\ImageMagick6\". I made a point of using the "static" version of each so they don't have any shared or common libraries. The "portable" versions would probably work that way, too. I'm not sure how it might act with the "dll" versions.
Re: Calculating with varaiables
Posted: 2017-02-26T14:58:11-07:00
by snibgo
Videomajk wrote:I'm using IM 6.9.7 on Win 10
I'm on Windows 8.1. Like GeeMack, I have multiple version of IM installed, and they work fine.
But I don't use Lightroom. I suppose that uses the first IM on the system path, or in some declared directory, or something.
Re: Calculating with varaiables
Posted: 2017-02-26T22:42:55-07:00
by Videomajk
snibgo wrote: ↑2017-02-26T14:58:11-07:00
But I don't use Lightroom. I suppose that uses the first IM on the system path, or in some declared directory, or something.
In the plugin I'm using (LR/Mogfrify 2) I need to point out the path to mogrify.exe, so I suppose that won't be a problem. I'll try to install IM 7. It seems to be better in many ways.
Thanks!