Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resize a list of images in line command

I would like to resize a list of images, all in the directory. To achieve that, I use convert from imagemagick. I would like to resize

image1.jpg
image2.jpg
...

into

image1-resized.jpg
image2-resized.jpg
...

I was wondering if there is a method to achieve this in a single command line. An elegant solution could be often useful, not only in this case.

EDIT:

I would like a non script-like solution, ie. without for loop.

like image 628
Jérôme Avatar asked Feb 18 '09 16:02

Jérôme


2 Answers

If you want to resize them to 800x600:

for file in *.jpg; do convert -resize 800x600 -- "$file" "${file%%.jpg}-resized.jpg"; done

(works in bash)

like image 54
Johannes Weiss Avatar answered Sep 17 '22 15:09

Johannes Weiss


ls *.jpg|sed -e 's/\..*//'|xargs -I X convert X.jpg whatever-options X-resized.jpg

You can eliminate the sed and be extension-generic if you're willing to accept a slightly different final filename, 'resized-image1.jpg' instead of 'image1-resized.jpg':

ls|xargs -I X convert X whatever-options resized-X
like image 20
chaos Avatar answered Sep 19 '22 15:09

chaos