views:

322

answers:

3

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.

+4  A: 

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)

Johannes Weiß
+1 This is exactly the same thing I use
David Zaslavsky
A: 

If your image files have different extensions:

for f in *; do convert -resize 800x600 -- "$f" "${f%.*}-resized.${f##*.}"; done
Cirno de Bergerac
+2  A: 
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
chaos
this was the kind of trick I was thinking about, nice one ;)
claferri
Right! That's what I want! Without the sed pipe would be perfect, no matter if resize is in the beginning
Jérôme