Anth's Computer Cave

PicMod. Bulk image-modification tool

3rd November, 2018

Aaimi PicMod is a bulk image-modification tool that automatically resize images and adjusts their quality to acheive incredible file-size reductions. It works on Linux, using ImageMagick via Python.

I use a lot of images in the tutorials in the Cave, and a lot of work goes into preparing the images for display on the web.

Much of this involves reducing the file-size. Web page images must be small enough to load quickly in a browser. Modern cameras take massive images, generally at-least 3MB, and just one of those images would bog-down a browser, especially over a slow Internet connection. A page full of those images would make the page unusable.

The challenge is to reduce the file-size for the images as much as possible, while maintaining their quality enought to serve their purpose.

Below is an example of the program in action. I ran it on a folder of full-size images for an article on my new robot, Stirling.

The size comparison of images before and after using AAIMI PicMod. Picture: Anthony Hartup.

The program first resized the images down to 800 pixels wide, then reduced the quality of the each to 60%, then renamed the images, leaving the originals untouched.

If you look at the size column you can see the first image has been reduced from 2960 KB down to 22 KB. That's a 99% file-size reduction!

Below you can see the actual resized image, stirling1.jpg, at just 22 KB.

An image resized using AAIMI PicMod. Picture: Anthony Hartup.

You can see that despite reducing the file-size by 99%, the image is clear, and about the right size for my Stirling robot article.

For some websites you may need larger images, better-quality images that display full-screen in the browser. You can adjust all of the settings I used for my images. For example you could set the width to 1200 pixels and quality to 80% and still get substantial file-size reductions.

You can choose which operations the program performs.

Options include rename, resize, reduce_quality, convert to JPG, and strip EXIF data.

Download and set up AAIMI PicMod

Note that this program automatically modifies files. Back up your images before you use AAIMI PicMod.

You can download PicMod from The AAIMI Project. Extract the folder and move the file to a directory above your image folders.

All of the options are in the Settings section of the code starting on line 38 of

Chosing a folder AAIMI PicMod. Picture: Anthony Hartup.

The folder variable on line 38 is the relative path to the folder containing your images. Left blank it will modify images in the current folder.

Renaming images with AAIMI PicMod. Picture: Anthony Hartup.

The rename variable on line 42 denotes whether to rename the files during the operation. If not blank, images will be renamed to this rename value, with a number appended. For my robot article pics I chose stirling.

The keep_original variable on line 44 tells the program whether to keep or overwrite the existing images. This only applies if you have chosen to rename the images.

The resize variable on line 48 is the width in pixels to resize landscape images. Set this to 0 if you don't want the program to resize images. Portrait images will instead be resized so their height matches the resize value to keep the same overall dimensions as their landscape equivelents.

Chosing a size and quality level for images in AAIMI PicMod. Picture: Anthony Hartup.

On line 51 you can set the quality level for your images to between 1% and 99%. Set this to 0 if you don't want to reduce quality.

On line 54 you can choose to convert .PNG images to .JPG. This can drastically reduce file-size on some PNG images, particularly images with lots of detail. However, PNG images with less detail and plain backgrounds may actually increase in file-size when converted. Keep that in mind if you have both plain and detailed images in the folder.

Converting file-types and removing EXIF data with AAIMI PicMod. Picture: Anthony Hartup.

On line 57 you can choose to strip the EXIF data from the images. Digital cameras include lots of data within the images, including camera model, location and much more. You may not want these details publicly available in pictures on your website. Stripping this data also reduces the file-size further, usually by about 15 KB.

Thats all the setting you need to change. When you run the program it will perform all of your chosen operations in one sweep.

Run AAIMI PicMod

Open a terminal and navigate to the location of the file. Type:


It will take a few seconds to modify all images in your chosen folder. If you wish to modify other folders, just change the folder variable on line 16 and run the program again.





Leave a comment on this article