Sean's Musings as a Service

Sean's Musings as a Service

Chew up your images to more manageable sizes

  • Published:
  • categories: linux
  • tags: linux, bash, imagemagick, convert, photos, photography

Hi I’m Hercules

So now that I have this fancy camera that takes images that are gigantic and are pretty much useless for sharing or uploading anywhere So I have to jump through hoops to make the images a reasonable size before I can even think about doing any work on editing the photo as it is. So I came up with a few helpers to just do batch resizing and quality changes based on my camera defaults. Who the eff needs images a 5MB file at 3072x2304 in R-L? It’s cool an all for the original files especially if there is some cool detail, but for my point and click shooting of people, places, and animals it is a bit much. I shoot for cutting down the initial resolution and image size to a few hundred KB and under ~800x900 so no one has to zoom out to view it, those images where you can see brain through someone’s nose are not generally that sexy…

Running through the grass

Check out the referenced page from the ImageMagick online documentation, I just do a batch through and run a convert command with a few choice options:

If you have more advanced needs, I imagine that you already now more about this than I do, so why are you here? For the rest of us simple folk looking to copy commands from the internet I provide a few simple commands that give the most bang for the buck for the rest of us who have convert installed.


convert ${input} -resize 25% ${output}_s0.jpeg

convert ${input} -shave 10% -quality 60 -resize 25% ${output}_s1.jpeg

convert ${input} -shave 15% -quality 70 -resize 25% ${output}_s2.jpeg

convert ${input} -shave 20% -quality 70 -resize 40% ${output}_s3.jpeg
convert ${input} -thumbnail 150x150\! ${output}_t.jpeg

convert ${output}_s3.jpeg -thumbnail 150x150\! ${output}_ts3.jpeg

So after a bit of testing I came up with a decent set of values for general use, try some out to see what you like and where you are loosing too much.

So after some playing around this is my little script:


: ${1?"Usage: $0 directory "}

for i in $1/*.JPG; do
echo -n "Processing ${i}, "
img_file=`basename $i`
echo -n "resizing to ${new_file}, "
convert $i -shave 20% -quality 70 -resize 40% $new_file
echo -n ", thumbnail @ ${new_thumb}, "
convert $new_file -thumbnail 150x150\! $new_thumb
echo "done."

So now I have the script sitting around, I should take some pictures of my girlfriends new dog to see how it works…

sgw@taint:~/pics/2008-09-01/processed$ ../orig
Processing ../orig/IMG_0469.JPG, resizing to IMG_0469_r.jpeg, , thumbnail @ IMG_0469_t.jpeg, done.
Processing ../orig/IMG_0470.JPG, resizing to IMG_0470_r.jpeg, , thumbnail @ IMG_0470_t.jpeg, done.
Processing ../orig/IMG_0471.JPG, resizing to IMG_0471_r.jpeg, , thumbnail @ IMG_0471_t.jpeg, done.
Processing ../orig/IMG_0472.JPG, resizing to IMG_0472_r.jpeg, , thumbnail @ IMG_0472_t.jpeg, done.
Processing ../orig/IMG_0473.JPG, resizing to IMG_0473_r.jpeg, , thumbnail @ IMG_0473_t.jpeg, done.
Processing ../orig/IMG_0474.JPG, resizing to IMG_0474_r.jpeg, , thumbnail @ IMG_0474_t.jpeg, done.
Processing ../orig/IMG_0475.JPG, resizing to IMG_0475_r.jpeg, , thumbnail @ IMG_0475_t.jpeg, done.
Processing ../orig/IMG_0478.JPG, resizing to IMG_0478_r.jpeg, , thumbnail @ IMG_0478_t.jpeg, done.
Processing ../orig/IMG_0479.JPG, resizing to IMG_0479_r.jpeg, , thumbnail @ IMG_0479_t.jpeg, done.
Processing ../orig/IMG_0481.JPG, resizing to IMG_0481_r.jpeg, , thumbnail @ IMG_0481_t.jpeg, done.
sgw@taint:~/pics/2008-09-01/processed$ cd ..
sgw@taint:~/pics/2008-09-01$ du -sh orig/ processed/
37M orig/
1.1M processed/

Alright, I’ll have to warn you he is ferocious… Grrrr

Migrated: from blogger 03-July-2014