2

I have these files under ./:

a.jpg
b.jpg
256/a.jpg

I'm running this command to convert files to 256px:

mogrify -path ./256/ -resize 256x256 *.jpg

But this command always overrides the existing files in 256, such as 256/a.jpg. Even though the images look the same, git diff still detects changes in the file. How can I avoid overwriting existing files with mogrify?

Versions:

ImageMagick 7.0.10-23 Q16 x86_64 2020-07-05
64bit Mac OS X 10.15.6 19G73

Edit:

My desired result is:

a.jpg
b.jpg
256/a.jpg (Unchanged)
256/b.jpg (Created)

@Sam Forbis' Answer
Using convert -resize 256x256 *.jpg -append ./256/*.jpg would result in:

a.jpg
b.jpg
256/a.jpg (Unchanged)
255/a-0.jpg (Created)
256/a-1.jpg (Created)
Hykilpikonna
  • 169
  • 6
  • The `-write` option does what you want. `for f in *; do mogrify -quality 0.75 -resize 1024x1024 -write out-$f $f; done` – jno May 02 '23 at 06:28

1 Answers1

5

You should use the command convert instead of mogrify. From the man page for mogrify:

Mogrify overwrites the original image file, whereas, convert writes to a different image file.

Looks like the input options are identical for convert. You just need to specify output options and an output file name as specified by the man page for convert:

convert [input-options] input-file [output-options] output-file
Sam Forbis
  • 2,684
  • 1
  • 11
  • 18
  • Thanks for your contribution! But a member in the forum said that [*You cannot use wildcards for both input and output with magick/convert. To process a folder of images, you need to use magick mogrify*](https://www.imagemagick.org/discourse-server/viewtopic.php?t=33140). And I've edited my question to include the results of using `convert`. – Hykilpikonna Aug 03 '20 at 23:17
  • 1
    @Hykilpikonna after reading your edits to your question, it looks like what you're trying to do cannot be accomplished with mogrify and/or convert alone. You will need to write a bash or batch script to assist you in your task. – Sam Forbis Aug 04 '20 at 13:21