7

Images can be resized using mogrify from the ImageMagick suite:

mogrify -resize 256x256 *.jpg

But this will resize images so that the largest dimension is 256px, including images that are smaller than 256px to begin with (like 100x100px avatars).

How can I exclude the smaller images from being affected? i.e. I want the largest dimension to be no more than 256px

(Preferably I will be able to do this with ImageMagick suite, or at least without installing anything additional).

2 Answers 2

7

Try

mogrify -resize '1280x1024>' *.jpg

Do make sure to back up though.

1
  • 2
    While it works, it still opens and re-saves the images it doesn't resize (it can make a Windows Paint PNG smaller without affecting the image's pixels). While harmless quality-wise, it eats CPU and disk bandwidth needlessly...
    – Medinoc
    Feb 26, 2015 at 11:00
1

mogrify -resize '256x256>' *.jpg also modifies images it doesn't resize and changes their image data. This doesn't:

identify -format '%w %h %i\n' *.jpg|awk '$1>256||$2>256{print$3}'|xargs mogrify -quality 93 -resize 256x256

Or if the paths of the files contain spaces, single quotes, double quotes, or tabs:

identify -format '%w %h %i\n' *.jpg|awk '$1>256||$2>256'|cut -d\ -f3-|xargs -d\\n mogrify -quality 93 -resize 256x256

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .