
ImageMagick: How to Optimize Images
Updated
Learn how to optimize images for the web using ImageMagick

Before we start, make sure you have ImageMagick installed on your computer and your photo ready in a folder. If you don't have it yet, run this command:
brew install imagemagick
First, open your terminal and navigate to the folder that has your photo. To optimize it for the web, run this command:
magick input.jpg -sampling-factor 4:2:0 -strip -quality 85 -interlace Plane output.jpg
The -strip option removes the hidden camera data, and -quality 85 compresses the file without a visible difference. The -sampling-factor 4:2:0 option keeps the brightness sharp while reducing the color detail, and -interlace Plane saves a progressive JPG that loads smoothly. Just remember to replace input.jpg with your actual filename.
To compare the sizes, run ls -lh input.jpg output.jpg. In the video, a 3.7M photo drops to 1.2M and still looks the same. Open output.jpg to confirm.
One more tip: for even smaller files, switch to WebP by running magick input.jpg -strip -quality 75 output.webp.
