Windows batch file - width / height operations

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
queensoft
Posts: 14
Joined: 2014-02-14T09:12:48-07:00
Authentication code: 6789

Windows batch file - width / height operations

Post by queensoft »

I use ImageMagick 6.8.2-8 2013-02-09 Q16 under Windows 7 x64 SP1 Ultimate.
I 'm trying to apply Perspective distort, but I need to use width / height coordinates.
This works OK:

Code: Select all

convert out_textured.jpg -alpha set -virtual-pixel transparent -distort Perspective 0,0,9,95,0,"%%h",0,"%%h","%%w","%%h","%%w","%%h","%%w",0,"%%w",0 out_pers.png
But this is what I need:

Code: Select all

convert out_textured.jpg -alpha set -virtual-pixel transparent -distort Perspective 0,0,9,95,0,"%%h",0,"%%h"-70,"%%w","%%h","%%w","%%h","%%w",0,"%%w",0 out_pers.png
The difference is height minus 70 pixels - "%%h"-70
I have tried these and they do not work:
"%%h"-70
"%%h-70"
""%%h"-70"
Please help. Thanks.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Windows batch file - width / height operations

Post by snibgo »

You can do the calculation before the convert, eg:

Code: Select all

FOR /F "usebackq" %%L IN (`%IM%identify -format "WW=%%w\nHH=%%h\nHHm70=%%[fx:h-70]" %SRC%`) DO set %%L
then use %WW%, %HH% and %HHm70%

Or you can include %[fx:] within the distort:

Code: Select all

convert ^
  in.png ^
  -distort "0,0,9,95,0,"%%h",0,%%[fx:h-70],"%%w","%%h","%%w","%%h","%%w",0,"%%w",0" ^
  out.png
snibgo's IM pages: im.snibgo.com
queensoft
Posts: 14
Joined: 2014-02-14T09:12:48-07:00
Authentication code: 6789

Re: Windows batch file - width / height operations

Post by queensoft »

Great, THANKS !!
Second one worked like a charm (with fx).
Thanks again !
Post Reply