As a web developer, you’ll inevitably end up needing to resize a bunch of images at some point.
Obviously, you can now fire up your favourite image editing software suite like Photoshop, Gimp, etc. to get the job done or turn to dedicated tools for the sole purpose of (batch) image resizing.
While many tools can fulfill the task it can be very tedious to resize a batch of images at once with the same configuration.
Sips is a command line tool that has been around quite some time and comes pre-installed with every Mac and (in my eyes) doesn’t get enough credit for what an awesome and easy-to-use tool it is.
Let’s assume you have a bunch of images as jpegs that need to be resized so they do not exceed a width of 320px. A sample original image could look like this:
To get this image resized to a maximum width of 320px while maintaining the image ratios (who wants distorted images on his site anyways?) run
to resample all
jpg files in the current folder to a width of 320px.
Be aware that without specifying the
--out option, the original images will be overridden without any confirmation prompt.
The above command will nicely resize our original image to the width of 320px.
Similarly, you can use sips to resize images to a maximum height of 320px
sips --resampleHeight 320 *.jpg
or to limit both height and width to some value:
sips -Z 320 *.jpg
For the people not feeling comfortable with the command line you also turn to the built-in preview app as described here.
Btw: sips can do far more for you than just resizing a bunch of images. It’s functionality can also be used in AppleScript under the name “Image Events”.
You can find all the options and commands for sips by running
sips --help or
man sips. Here’s the sample output for version 10.4.4: