Using IM v6 and v7 with "-set option:distort:scale"

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
User avatar
GeeMack
Posts: 753
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Using IM v6 and v7 with "-set option:distort:scale"

Post by GeeMack »

Trying to use "-set option:distort:scale" with no-op "-distort" to scale several images in various parts of a command. I've run into a discrepancy between IM v6 and IM v7.

First, to describe my desired result, here's a simplified command using IM 6.9.10-78 on Windows 10 or IM 6.8.9-9 on bash...

Code: Select all

convert logo: wizard: rose: -set option:distort:scale %[fx:300/s.w] -distort SRT 0 info:
The output below shows all three images have been rescaled to be 300 pixels wide. It looks like the "-set" applies a different "option:distort:scale" attribute according to each image's width. This is the result I want.

Code: Select all

logo:[0] GIF 300x225 300x225+0+0 8-bit sRGB 28576B 0.234u 0:00.077
wizard:[1] GIF 300x400 300x400+0+0 8-bit sRGB 99674B 0.219u 0:00.049
rose:[2] PNM 300x197 300x197+0+0 8-bit sRGB 9673B 0.031u 0:00.018
When running the same command with IM 7.0.9-8 on Windows, the "-set" applies the "option:distort:scale" setting of the first image to all the images in the list. This command...

Code: Select all

magick logo: wizard: rose: -set option:distort:scale %[fx:300/s.w] -distort SRT 0 info:
Generates this result...

Code: Select all

logo:[0] GIF 300x225 300x225+0+0 8-bit sRGB 28576B 0.172u 0:00.072
wizard:[1] GIF 225x300 225x300+0+0 8-bit sRGB 99674B 0.078u 0:00.036
rose:[2] PNM 33x22 33x22+0+0 8-bit sRGB 9673B 0.000u 0:00.008
The question would be, is this the expected behavior of IM v7, or should it behave more like IM v6 and output images with matching widths with the same command?

User avatar
fmw42
Posts: 26273
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Using IM v6 and v7 with "-set option:distort:scale"

Post by fmw42 »

This does not work either:

Code: Select all

magick logo: wizard: rose: -distort SRT "%[fx:300/s.w] 0" -format "%wx%h\n" info:

User avatar
magick
Site Admin
Posts: 11218
Joined: 2003-05-31T11:32:55-07:00

Re: Using IM v6 and v7 with "-set option:distort:scale"

Post by magick »

The IMv7 CLI parser evaluates command-line options in a strict, do-it-as-you-see it order. So the -set option is evaluated once, whereas the legacy parser evaluates the option for each image. You can utilize the legacy parser in IMv7 by using `magick convert` rather than `magick`.

Fred, your command appears to be working. It returns SRT arguments of `0.46875 0`, `0.625 0`, and `4.28571 0` respectively. The results are:

Code: Select all

640x480
480x640
70x46
You get these same results with the legacy parser.

User avatar
fmw42
Posts: 26273
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Using IM v6 and v7 with "-set option:distort:scale"

Post by fmw42 »

I am now puzzled. Why does -resize work with fx:s, but -set option does not?

magick logo: wizard: rose: -resize "%[fx:s.w]x%[fx:s.h]" -format "%wx%h\n" info:
640x480
480x640
70x46

magick logo: wizard: rose: -resize "%[fx:s.w-10]\!x%[fx:s.h-10]\!" -format "%wx%h\n" info:
630x470
470x630
60x36

User avatar
magick
Site Admin
Posts: 11218
Joined: 2003-05-31T11:32:55-07:00

Re: Using IM v6 and v7 with "-set option:distort:scale"

Post by magick »

With the IMv7 parser, activated by the `magick` utility, settings are applied to each image in memory in turn (if any). While an option: only need to be applied once globally. Using the other utilities directly, or as an argument to the `magick` CLI (e.g. `magick convert`) utilizes the legacy parser.

Post Reply