I wanted to convert some .webp
images to .png
on my Mac. I asked ChatGPT:
On MacOS use CLI to convert webp images to PNG
And it told me about sips
:
sips -s format png image.webp --out image.png
Or to run it against all PNGs in a folder:
for file in *.webp; do sips -s format png "$file" --out "${file%.*}.png"; done
I had never heard of sips
before – but apparently it’s been a default command on macOS for a very long time.
It stands for “scriptable image processing system”. man sips
starts like this:
NAME
sips – scriptable image processing system.
SYNOPSIS
sips [image-functions] imagefile ...
sips [profile-functions] profile ...
DESCRIPTION
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. It also supports executing JavaScript to either
modify or generate images.
It can run JavaScript!
I asked ChatGPT for an example, but it halucinated something that didn’t actually work.
After some searching I found manicmaniac/sips-js-api which is the only place online I could see that documented how to use the sips --js
option. Here’s their example – save this in smile.js
:
const canvas = new Canvas(150, 150) canvas.beginPath() canvas.arc(75, 75, 50, 0, Math.PI * 2, true) canvas.moveTo(110, 75) canvas.arc(75, 75, 35, 0, Math.PI, false) canvas.moveTo(65, 65) canvas.arc(60, 65, 5, 0, Math.PI * 2, true) canvas.moveTo(95, 65) canva