When it comes to websites, keeping the image files as small as possible helps your sites to load faster. You may find numerous plugins out there for WordPress. Plugins are handy, however, resizing or compressing your images using plugins is an extra burden for your web server. It’s a good practise to compress the images on your local machine & upload the compressed version to the web site.
In this article, we will guide you on how to resize and compress your images using Mac’s terminal. In general, using a command-line program for such tasks is ideal as it won’t consume many resources of your computer. Also processing through a terminal is much faster than using a GUI application for bulk tasks.
For this example, we took 3 images. All the images are above 4900px in width & the total size of the images is 7.2MB. After processing the images with the width of 800px, the total size came down to 184KB
How to achieve this?
ImageMagick is an open-source suite of command-line tools for manipulating digital images. It is useful for batch processing a large number of images, or to quickly perform precise image modification tasks.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Once Homebrew is installed, use the command below to install ImageMagick;
brew install imagemagick
ImageMagick depends on Ghostscript fonts. To install;
brew install ghostscript
To verify the installation;
Compress / Resize Images
Important: Take a backup of your images before manipulating them ✨
cd to your image directory
Use below command to check your image sizes & dimensions. Use * to process all the images in the directory
Now paste below command to start processing the bulk resize / compress;
mogrify * -resize 800 *
800 is the image width (in Pixels). Replace it your desired value.
This is a handy tool to have if you are uploading images to your website regularly. This tool is not limited to only resize or compress. You can even use this tool to convert image formats, rename in bulk, etc. All it’s use cases can be found here.
Bookmarking this page is a good idea for you to refer whenever you need to process your images 😍