Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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).

share|improve this question
up vote 7 down vote accepted

try mogrify -resize '1280x1024>' *.jpg do make sure to backup though.

share|improve this answer
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 '15 at 11:00

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.