Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch resize images into new folder using ImageMagick

I have a folder of images over 4MB - let's call this folder dsc_big/. I'd like to use convert -define jpeg:extent=2MB to convert them to under 2MB and copy dsc_big/* to a folder dsc_small/ that already exists.

I tried convert dsc_big/* -define jpeg:extent=2MB dsc_small/ but that produces images called -0, -1, and so on.

What do I do?

like image 364
tekknolagi Avatar asked Jan 03 '12 03:01

tekknolagi


People also ask

How do I resize an image in Imagemagick?

To resize an image to specific dimensions, use the convert command with an input file, the -resize parameter, your preferred dimensions, and an output filename: convert original. png -resize 100x100 new.

How do I resize an image in a group?

Select a group of images with your mouse, then right-click them. In the menu that pops up, select “Resize pictures.” An Image Resizer window will open. Choose the image size that you want from the list (or enter a custom size), select the options that you want, and then click “Resize.”


1 Answers

convert is designed to handle a single input file as far as I can tell, although I have to admit I don't understand the output you're getting. mogrify is better suited for batch processing in the following style:

mogrify -path ../dsc_small -define jpeg:extent=2MB dsc_big/* 

But honestly I consider it dangerous for general usage (it'll overwrite the original images if you forget that -path) so I always use convert coupled with a for loop for this:

for file in dsc_big/*; do convert $file -define jpeg:extent=2MB dsc_small/`basename $file`; done 

The basename call isn't necessary if you're processing files in the current directory.

like image 115
Eduardo Ivanec Avatar answered Oct 17 '22 03:10

Eduardo Ivanec