Home » Optimise images for the web on MacOS / Linux using free Open Source software.

How to optimise images for the web

Optimise images for the web on MacOS / Linux using free Open Source software.

I store all my master images in iPhoto on Mac, which is great but where you export them, or drag them into WordPress they are too big for web usage. What was needed is a simple, quick and reliable way to optimise images for web on Mac and Linux which is where I mostly work these days.

I was looking for a simple workflow to allow me to export a collection of images into a temporary directory and then batch optimise them.

There are lots of ways to do this but I settled on Image Magick as it has good cross platform support and has support for the new Webp file format when I want to start using that.

How to install Image Magick on MacOS

To install Image Magick on MacOS you need to use the following command:

brew install imagemagick

On Linux you should be able to use apt-get, yum or whatever package manager your system uses to install this.

Exporting images from iPhoto

I then create a temporary directory and export my photo’s from iPhoto into this.

Running the image optimisation for the web process

Using Finder I then locate the new directory and open terminal, this is easily done using the bar at the botton of the window.

I then create a sub directory

mkdir Converted

And finally I run the following Image Magick command

for X in *.jpeg; do convert “$X” -resize 1024 -strip -quality 86 “converted/$X”; done

This loops through all the photos in the temporary directory and converts them to 1024 pixels wide with an 86% quality. This works nicely for me reducing 6MB files to 200K to 300K. You are welcome to play around with these settings if you want more aggressive optimisation.

Putting it all together into a shell script

I’ve actually now just put these two commands together into a script called webify.sh in my home directory (using nano ~/webify.sh)

mkdir Converted

for X in *.jpeg; do convert “$X” -resize 1024 -strip -quality 86 “converted/$X”; done

Save the file using CTRL O then CTRL X

Finally make it executable by doing chmod +x ~/webify.sh

I can now just create a temp directory, save the pictures into it, open it in terminal and enter the command

~/webify.sh

to run the conversion.

Good luck with this and do let me know how you get on. If you have any questions please feel free to leave them below.




You May Also Like…

Find similar blogs in these categories: Apple MacOS / OSX | wordpress
0 Comments
Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.