103

Current image folder path:

public_html/images/thumbs

Output image folder path:

public_html/images/new-thumbs

I have 10 video thumbs per video in current folder, named of image thumbs:

1-1.jpg
1-2.jpg
1-3.jpg
1-4.jpg
1-5.jpg (Resize)
1-6.jpg
1-7.jpg
1-8.jpg
1-9.jpg
1-10.jpg

2-1.jpg
2-2.jpg
2-3.jpg
2-4.jpg
2-5.jpg (Resize)
2-6.jpg
2-7.jpg
2-8.jpg
2-9.jpg
2-10.jpg

I want to resize all 5th images(*-5.jpg) to the new folder. I've tried below command but no luck:

mogrify 
-path 
  public_html/images/thumbs/*-5.jpg 
-resize 16×12 
-quality 100 
  public_html/images/new-thumbs/*-5.jpg
richard
  • 1,456
  • 4
  • 15
  • 22

4 Answers4

144

"Mogrify" should be called from the directory with the original thumbnails, while the -path parameter is for pointing target directory.

mkdir public_html/images/new-thumbs
cd public_html/images/thumbs
magick mogrify -resize 16x12 -quality 100 -path ../new-thumbs *.jpg

http://www.imagemagick.org/Usage/basics/#mogrify

The last arguments are the list of files, so you can filter by name 1-*.jpg for example.

Dmytro Vyprichenko
  • 4,654
  • 2
  • 23
  • 15
  • 17
    You are right, but you can also call `mogrify` from any directory, for example I convert originary jpeg into png with `mogrify -path /destination/path/ -adaptive-resize 5000 -unsharp 0x1 -format png /originary/path/*.jpeg` – Tenaciousd93 Oct 22 '14 at 11:36
  • 17
    Note that output directories you're pointing to *must exist*, as ImageMagick will no create them, causing a `mogrify: unable to open image` error. – Matthew Morek Jan 26 '16 at 12:55
  • This don't work with i try with png and put 1024x600 , all images are resized to 800x600 instead 1024x600 – inukaze Jan 30 '18 at 23:00
  • 2
    Well great, I specified `path` but it nuked the original files nonetheless. Is there something wrong with my command line? This is Windows, hence the back slashes: `mogrify -resize 2752 *.tif -path E:\1\ ` – Violet Giraffe Dec 28 '20 at 14:07
  • 2
    @VioletGiraffe, options order matters, it should have been like that: `mogrify -resize 2752 -path E:\1\ *.tif` (note that *.tif is in the end). What you tried was like passing an image [setting or operator](https://stackoverflow.com/questions/26579299/imagemagick-command-line-option-order-and-categories-of-command-line-parameters), but it is not applicable to mogrify, _afaik_. – Dmytro Vyprichenko Jan 04 '21 at 14:00
  • 1
    I see, thank you very much for this answer-comment as well as the main answer! – Violet Giraffe Jan 04 '21 at 15:54
  • For someone who always gets confused with width and height. Width comes first. width x height – yajnesh Apr 15 '21 at 15:27
18

Suggested solutions do not work properly on the latest ImageMagick (at least, on macOS). Command, that works overwriting source images is as follows:

magick mogrify -path ./ -resize 50% -quality 80 *.jpg

To avoid overwriting the original images, write to a new folder:

magick mogrify -path path/to/destination/folder/ -resize 50% -quality 80 *.jpg

ProfDFrancis
  • 8,816
  • 1
  • 17
  • 26
Nigidoz
  • 360
  • 2
  • 6
  • If you resize by 50% then reduce the quality by 20% then it will only be 40% of the original quality? i.e. 0.5 * 0.8 – Paolo Tormon Oct 07 '22 at 16:06
  • 1
    @PaoloTormon: No. -resize changes the size in pixels, -quality changes the compression of the file. For PNG, -quality alters the ratio between file size and time to decompress, but the format is lossless so you won't see any difference between files compressed with different "qualities". For JPEG, you will see a difference but it's more complex than making the product of the two parameters. – Xr. Mar 16 '23 at 07:44
10

In ImageMagick 7 versions its built into the magick ...so..

magick mogrify -resize 16x12 -quality 100 -path ../new-thumbs *.jpg

Make sure that the folder you specify in path exists. It will not be created by ImageMagick.

Find more information here https://www.imagemagick.org/script/mogrify.php

JoschJava
  • 1,152
  • 12
  • 20
virtuvious
  • 2,362
  • 2
  • 21
  • 22
  • 1
    This is exactly the same as the accepted answer, only 4 years later. Why? (I guess you added the word "magick" to the front of it, but it runs fine without that (no added value) – ashleedawg Dec 30 '18 at 17:03
  • 3
    @ashleedawg, without `magick` I get `Cannot find file at '..\\lib\imagemagick.tool\tools\mogrify.exe'` in output in my Windows for ImageMagick 7. See [**this answer**](https://stackoverflow.com/a/41094852/5951529) for details. +1 from me to mahesh madhusudan. Thanks. – Саша Черных Jan 23 '19 at 08:07
  • 1
    Thank you very much @СашаЧерных ....!!! I was trying to recollect why I had done this... as it was long back ago.... – virtuvious Jan 23 '19 at 18:32
  • @СашаЧерных That shouldn't require a separate answer; a comment at best. – Shidouuu Sep 02 '23 at 16:59
2

For those having Shotwell installed on Ubuntu/Debian, following may be more easy to export selected images in a folder to another folder through processing the images as needed.

  • Open Shotwell
  • Select the images you want to export
  • File > Export
  • Adjust the values to your needs
  • Select the folder to export
Bricktop
  • 67
  • 3