TIL that macOS ships with a default CLI command called "sips", for "scriptable image processing system" - and it can convert webp images to PNG, but it can also generate entirely new images from scratch using an almost entirely undocumented canvas-based JavaScript API! https://til.simonwillison.net/macos/sips
sips: Scriptable image processing system

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 i

As far as I can tell the only documentation on how to use the JavaScript API is this unofficial documentation here https://github.com/manicmaniac/sips-js-api
GitHub - manicmaniac/sips-js-api: An unofficial documentation of sips's JavaScript API.

An unofficial documentation of sips's JavaScript API. - GitHub - manicmaniac/sips-js-api: An unofficial documentation of sips's JavaScript API.

GitHub
@simon Wow, I've used sips a lot but had absolutely no idea that existed
@simon wrong link?
GitHub - manicmaniac/sips-js-api: An unofficial documentation of sips's JavaScript API.

An unofficial documentation of sips's JavaScript API. - GitHub - manicmaniac/sips-js-api: An unofficial documentation of sips's JavaScript API.

GitHub
@glaforge oops, thanks - fixed (hooray for the edit button)
@simon that’s interestingness I’ve always installed a utility like ImageMagik, etc for that kind of thing. Can’t wait to try it out.
@simon This is exactly the kind of MacOS trick I've been looking for. Saved! Good alternatives to ImageMagick are just so tough to find.
@simon Thank you! This solves a problem I have.
@simon sips also can print the size of an image, and had some nice resize modes
@simon soooo... who is going to build a wrapper around this that implements a Node/Deno-like stdlib so we can have ~0kb JS CLI's on MacOS?
@developit it supports console.log() so yeah, you could totally use it like that
@simon I smell a weekend project brewing
@developit @simon macOS does ship with jsc (https://furbo.org/2021/08/25/jsc-my-new-best-friend/) too so I don’t think you need to build it around an image processing tool
jsc: My New Best Friend • furbo.org

A friend of mine recently pointed me at a well hidden command line tool. In the JavaScript framework used by Safari and other parts of Apple’s products, there is a tool called jsc. It’s a command line interface for JavaScript that uses the same code as the rest of the system. You can find the […]

Furbo.org by Craig Hockenberry
@juri @simon oh dang, nice. That would make this project.... very easy! haha

@developit @juri @simon

I’m pretty sure JSC is JavaScriptCore, which is what Bun is built on top of.

https://github.com/oven-sh/bun

GitHub - oven-sh/bun: Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one - oven-sh/bun

GitHub
@styfle @developit @simon yes, thank you. I was sure I had seen something like that but couldn’t remember the name. And yeah, jsc is the CLI interface to JavaScriptCore.
@developit @simon There’s also the jsc command line tool buried inside JavaScriptCore.framework that you can use standalone, minus the image processing features of sips. It’s pretty bare bones though.

@simon Interesting… i was hoping it could replace this https://formulae.brew.sh/formula/webp but not the right this.

Lol @ “I asked ChatGPT for an example, but it halucinated something that didn't actually work.”

webp

Homebrew’s package index

Homebrew Formulae
@simon well that is extremely interesting

@aurynn @simon

I believe it can also generate .icns files from PNGs.

@simon: Thanks! This looks very interesting.
@simon @[email protected] Ooh, also, Simon, looks like sips can be used with AppleScript, which makes complete sense on the js side, that’s actually probably where it comes from. https://ss64.com/osx/sips.html
sips MAN page Man Page - macOS - SS64.com

@simon I adopted sips for my scripts years ago, after a long time installing ImageMagick on every Mac just to convert, resize and rotate images. Never looked back. Great tool, all around.
@simon I had no idea it had a JS API!?!
@simon I haven’t use the JS features but there’s a section in my book where you learn to wrap a GUI around sips. https://www.kodeco.com/books/macos-by-tutorials
macOS by Tutorials

macOS by Tutorials is a series of epic-length tutorials where you’ll learn to build four complete native macOS apps! Each app explores a different style of interface and takes you step-by-step from start to finish. By the end of the book, you’ll be experienced enough to turn your ideas into real apps you can sell! You also get full source code, image files, and other resources you can re-use for your own projects. This book for developers with some experience developing for iOS using Swift and SwiftUI.

kodeco.com
@simon I had SIPS in some production tooling for a decade and if it had the JS feature back then I totally missed it

@simon @objectObject

> I asked ChatGPT for an example, but it halucinated something that didn't actually work.

This feels like the TL;DR of ChatGPT.

@simon

Related tip:

If you quickly want to convert an image in MacOS you can do that under quick actions in the right click menu.

@simon interesting stuff. I see too, for #python fans, there are hooks into it in the PyPI package generate-iconset

> pip install generate-iconset

@simon Nice! I’ve often been frustrated trying to convert .webp pages.
@simon I wish sips supported outputting to newer formats such as WebP and AVIF, which would make it very useful in generating image sets for the web when you don’t have an automated processing pipeline in place.
@simon I always forget that sips exists … as I do forget the textutil shell utiliy.
@simon imagemagick 2.0. Is it open-source?

@simon this is really interesting timing. I reckon sips will ship on RealityOS for the Apple headset.

* alpha transparency will enable occlusion
* JavaScript based API for Web Experiences

@simon

Me: "Finally a post that's not about ChatGPT!"

I followed the link, read first line, then died

@Sandra hah! Maybe I should have used a content warning

I did get in a little dig at it later on though:

> I asked ChatGPT for an example, but it halucinated something that didn't actually work.

@simon That reminded me slightly of Brian Kernighan's PIC markup language.
@simon I love imagemagick and the rmagick ruby wrapper AND i'm going to have to check this out. Would be great to have some sort of mac specific fun cli app with this! Gratuitous plug: My Firefox Support Question "barcode" in WIP https://github.com/rtanglao/firefox-emoji-barcode/blob/main/createDailyFirefoxEmojiBarcode.rb
firefox-emoji-barcode/createDailyFirefoxEmojiBarcode.rb at main · rtanglao/firefox-emoji-barcode

Daily Firefox Emoji barcode from support.mozilla.org (SUMO) Firefox Desktop support questions - firefox-emoji-barcode/createDailyFirefoxEmojiBarcode.rb at main · rtanglao/firefox-emoji-barcode

GitHub