Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
384 views
in Technique[技术] by (71.8m points)

windows - convert and mogrify: The correct way to use them in modern versions of ImageMagick

To create an image thumbnail using an older version of ImageMagick, it was possible in the following ways:

(To aid in futher referencing, examples are numbered.)

1. convert.exe image.jpg -thumbnail 100x100 ./converted/converted_image.jpg
2. mogrify.exe -thumbnail 100x100 -path ./converted image.png

Now I have ImageMagick 7 (downloaded just yesterday), and during installation I intentionally turned "Install legacy utilities (e.g. convert.exe)" checkbox off. That is, I have only one utility in my ImageMagick directory: magick.exe.

I'm trying to understand what is the correct and future-proof way to perform above-mentioned operations according to modern ImageMagick versions.

A quote from https://imagemagick.org/script/porting.php#cli:

animate, compare, composite, conjure, convert, display, identify, import, mogrify, montage, stream

To reduce the footprint of the command-line utilities, these utilities are symbolic links to the magick utility. You can also invoke them from the magick utility, for example, use magick convert logo: logo.png to invoke the magick utility.

In the same source:

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.

Hmm...

Works:

3. magick.exe convert image.jpg -thumbnail 100x100 ./converted/converted_image.jpg
4. magick.exe mogrify -thumbnail 100x100 -path ./converted image.png

Still works (the same way as magick.exe convert):

5. magick.exe image.jpg -thumbnail 100x100 ./converted/converted_image.jpg

However, the following one doesn't work (expected: should work the same way as magick.exe mogrify):

6. magick.exe -thumbnail 100x100 -path ./converted image.png

My question is: Which syntax should I use for convert and for mogrify? 3 and 4, or 4 and 5, or something different?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

AFAIK, and I am happy to add any corrections suggested, it works like this.

The first idea is that you should use version 7 if possible and all the old v6 commands, WITH THE EXCEPTION OF convert should be prefixed with magick. That means you should use these

magick ...                # in place of `convert`
magick identify ...       # in place of `identify`
magick mogrify ...        # in place of `mogrify`
magick compare ...        # in place of `compare`
magick compose ...        # in place of `compose`

If you use magick convert you will get old v6 behaviour, so you want to avoid that!

Furthermore, v7 is more picky about the ordering. You must specify the image you want something done to before doing it. That means old v6 commands like:

convert -trim -resize 80% input.jpg output.jpg

must now become:

magick input.jpg -trim -resize 80% output.jpg     # magick INPUT operations OUTPUT

So, looking specifically at your numbered examples:

  1. Should become:

    magick image.jpg -thumbnail 100x100 ./converted/converted_image.jpg

  2. Should become:

    magick mogrify -thumbnail 100x100 -path ./converted image.png

  3. invokes old v6 behaviour because you use magick convert instead of plain magick, and should be avoided

  4. Is correct, modern syntax

  5. Is correct, modern syntax

  6. Looks like you meant magick mogrify because you didn't give input and output filenames and because you use -path, but it looks like you accidentally omitted mogrify. If you didn't accidentally omit mogrify, then you probably meant to use the old convert-style command, and need an input and an output file and you need to specify the input file before the -thumbnail.

Keywords: Usage, wrong, modern, v7 syntax, prime.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...