Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch resize images and output images to new folder with ImageMagick

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 
like image 571
richard Avatar asked Jan 13 '13 14:01

richard


People also ask

How do I resize multiple images in python?

You can resize multiple images in Python with the awesome PIL library and a small help of the os (operating system) library. By using os. listdir() function you can read all the file names in a directory. After that, all you have to do is to create a for loop to open, resize and save each image in the directory.


2 Answers

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

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 pp*.jpg for example.

like image 80
Dmytro Vyprichenko Avatar answered Sep 20 '22 02:09

Dmytro Vyprichenko


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

like image 45
Nigidoz Avatar answered Sep 21 '22 02:09

Nigidoz