Skip to content
Advertisement

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.

Advertisement

Answer

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
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement