2

I have a folder of images of varying sizes and quality. Is there a way with ImageMagic that I could automatically resize them to be no bigger 1100px x 1100px and less than 160kb. And not to re-size if they are smaller than those parameters. Also not to distort the image so it fits within but to only re-size so for example an image which is 2200px by 1000px would become 1100px by 500px.

I'm working on Ubuntu with ImageMagick 6.7.7-10.

Holly
  • 7,462
  • 23
  • 86
  • 140

1 Answers1

2

Try this on a copy of your files:

mogrify -define jpeg:extent=160k -resize 1100x1100\> *.jpg

I am assuming your files are JPEG images. The command will largely work for other image types too, but it can only enforce the 160kB limit for JPEG files - not PNG, or TIFF etc.

Example

With version: ImageMagick 6.9.1-10 Q16 x86_64 2015-08-06

convert -size 2000x2000 xc:gray +noise random a.jpg

ls -lrt a.jpg
-rw-r--r--  1 mark  staff  6969601 21 Aug 18:28 a.jpg            # <--- 7MB

mogrify -define jpeg:extent=160k -resize 1100x1100\> a.jpg

ls -lrt a.jpg
-rw-r--r--  1 mark  staff  147938 21 Aug 18:28 a.jpg             # <--- 160kB

identify a.jpg
a.jpg JPEG 1100x1100 1100x1100+0+0 8-bit sRGB 148KB 0.000u 0:00.000
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • that only resized them, it did not reduce the file size. I was able to almost get the result I wanted with `mogrify -path . -resize 1100x1100\> -quality 85% *.jpg`, although for some files 85% is too little and possible too much – Holly Aug 21 '15 at 16:35
  • Version: ImageMagick 6.7.7-10 2014-03-06 Q16 http://www.imagemagick.org , what version have you got – Holly Aug 21 '15 at 17:09
  • Whe I run the command the file size goes down to approx 1.6mb on some of the files, not 160kb – Holly Aug 21 '15 at 17:15
  • Please try upgrading, the command should definitely work as I gave it. – Mark Setchell Aug 21 '15 at 17:31
  • I think I have the latest version. When I run `sudo apt-get install ImageMagick` it says `imagemagick is already the newest version` – Holly Aug 21 '15 at 17:36
  • Given that mine is over a year and many revisions newer, I think not. Maybe you `apt-get` isn't looking in the best place. – Mark Setchell Aug 21 '15 at 18:21
  • 1
    The date presented by ImageMagick's -version is misleading. It's the date it was compiled. The actual release date for your version (6.7.7-10) is 2012-06-28 according to the ChangeLog. – Glenn Randers-Pehrson Aug 21 '15 at 18:42