Hidden gems - sips on macOS

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 to the rescue!

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.

How-To

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:

Original Image

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

sips --resampleWidth 320 --out resampled/ *.jpg

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.

Image resized to 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

Non command-line alternatives

For the people not feeling comfortable with the command line you also turn to the built-in preview app as described here.

More command-line options

If sips doesn’t provide enough options and capabilities for you, you might wanna take a look at imagemagick, one of the most powerful image editing command line tools, which can also be used in many scripting languages like php, python or javascript.

Sips documentation

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:

sips 10.4.4 - scriptable image processing system.
This tool is used to query or modify raster image files and ColorSync ICC profiles.
Its functionality can also be used through the "Image Events" AppleScript suite.

  Usages:
    sips [-h, --help]
    sips [-H, --helpProperties]

    sips [image-query-functions] imagefile ...

    sips [profile-query-functions] profile ...

    sips [image modification functions] imagefile ...
         [--out result-file-or-dir]

    sips [profile modification functions] profile ...
         [--out result-file-or-dir]


  Profile query functions:
    -g, --getProperty key
    -X, --extractTag tag tagFile
    -v, --verify

  Image query functions:
    -g, --getProperty key
    -x, --extractProfile profile

  Profile modification functions:
    -s, --setProperty key value
    -d, --deleteProperty key
        --deleteTag tag
        --copyTag srcTag dstTag
        --loadTag tag tagFile
        --repair

  Image modification functions:
    -s, --setProperty key value
    -d, --deleteProperty key
    -e, --embedProfile profile
    -E, --embedProfileIfNone profile
    -m, --matchTo profile
    -M, --matchToWithIntent profile intent
        --deleteColorManagementProperties
    -r, --rotate degreesCW
    -f, --flip horizontal|vertical
    -c, --cropToHeightWidth pixelsH pixelsW
    -p, --padToHeightWidth pixelsH pixelsW
        --padColor hexcolor
    -z, --resampleHeightWidth pixelsH pixelsW
        --resampleWidth pixelsW
        --resampleHeight pixelsH
    -Z, --resampleHeightWidthMax pixelsWH
    -i, --addIcon
    -o, --optimizeColorForSharing