Page 1 of 1

How to use image -format / info: in same command-line ?

Posted: 2018-03-30T23:10:28-07:00
by Alexvb6
Hi,

Under Dos, with IM v7, sometimes I need to identify the Width of the image using convert, then use this variable later in my connvert command, without any pipe.
I'm a little lost on how about to perform this...

Here, I am trying to reduce image Width by its width minus 12 pixels, for example :
(I know my syntax is not the good one, and this code does not work...)

Code: Select all

convert ^
 c:\source.png
 -resize ([%w]-12)x100%
 c:\destination.png
PS: My example is only for "example purpose"... What I need is really a way to extract some data about the image thanks to the "Percent Escape Properties", and re-use this information later in my command-line.

Would someone have an idea ? The docs are not very "verbose" about it ;) http://www.imagemagick.org/Usage/basics/#identify_alt
Thank you (and sorry for this newb' question)

Re: How to use image -format / info: in same command-line ?

Posted: 2018-03-30T23:31:18-07:00
by fmw42
You cannot mix pixel width with percent width in the resize arguments. So you would have to use [fx:100*(w-12)/w]x100% or %[fx:w-12]x%[fx:h].

If you want to save a calculation, use -set option:size "%[fx:w-12]x%[fx:h]", then later -resize "%[size] in IM 7

IM 6 does not allow inline calculations to be used later for -resize or most other operators (except for -distort).

If using IM 7, then replace convert with magick (or convert.exe with magic.exe). In IM 6 be sure you are not confusing the Window convert.exe with the Imagemagick convert.exw.

Re: How to use image -format / info: in same command-line ?

Posted: 2018-03-31T01:53:22-07:00
by snibgo
To resize the image so the width reduces by 12 and the height is unchanged, the obvious command, in v7, is:

Code: Select all

magick in.png -resize %[fx:w-12]x out.png
Note that for "-resize WxH", I have not supplied a height, so that isn't changed.

More generally, if you want to save a value for use later in the command, use "-set option", eg:

Code: Select all

magick in.png -set option:NewW %[fx:w-12] -resize %[NewW]x out.png
If using these in Windows BAT scripts, double every %.

Re: How to use image -format / info: in same command-line ?

Posted: 2018-04-02T11:55:48-07:00
by Alexvb6
Hi Fred, Hi Snibgo,

Thank you very much : Using dynamic variables works perfectly in command-line : I really thank you for this, I was not able to make that work in the past !

However, As I am using the COM+ Object, unsing variables seems not possible using the 'Convert' tool (Even in command-line, dynamic variables only work with the "Magick" tool).
Do you confirm me that there is not way to use variables using "convert" ?

I will try to post that question in the "COM+ Object" forum, even if it is not very busy, sadly.

Re: How to use image -format / info: in same command-line ?

Posted: 2018-04-02T12:14:36-07:00
by snibgo
IM V7 will accept an %[fx:...] expression in most places it expects a number, such as in "-resize".

IM v6 is more restricted. %[fx:...] expressions can only be used in certain places (like "-distort SRT"), but not in "-resize".

Of course, if you are using IM within a programming language, you can evaluate expressions in that language.

Re: How to use image -format / info: in same command-line ?

Posted: 2018-04-02T12:17:48-07:00
by Alexvb6
Yes Snibgo, I am currently using VBScript to evaluate expressions, but between several IM command-lines.
In some cases, I could gain speed and improve performance by letting IM do simple computing in dynamic variables (such as for exemple dividing a number, or substracting ...)

Re: How to use image -format / info: in same command-line ?

Posted: 2018-04-07T00:19:26-07:00
by Alexvb6
FYI, the support for the "magick" command in the COM+ Object is planned to be added in the next release of ImageMagick, as I suggested it in this ticket :
https://github.com/ImageMagick/ImageMagick/issues/1083