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.
Before
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
After
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.
Install ImageMagick
The easiest & recommended way of installing ImageMagick is via Homebrew. Let’s install Homebrew first. Open up your Terminal and paste following command;
/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;
magick --version
Compress / Resize Images
Important: Take a backup of your images before manipulating them ✨
cd
to your image directory
cd [your-directory-path]
Use below command to check your image sizes & dimensions. Use * to process all the images in the directory
identify *
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 😍
Is there any programs available for windows?
Hi Hayley, thanks for your comment. Yes, ImageMagick itself available on Windows. If you are looking for an alternative, IrfanView is a very good GUI program with multiple features for image processing.
Awesome, thank you!
You’re most welcome, Hayley.
Testing for GTM