Fork me on GitHub

Project Notes

sips

Using sips - scriptable image processing system on MacOSX.

Notes

TIL there’s a “scriptable image processing” tool hiding in the MacOSX distribution: sips

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.

Note: sips -h and sips -H give much more information than man sips.

Inspecting Images

See sips -H for property details. CAn get individual properties, or to get all:

$ sips -g all examples/*.png
/.../LittleCodingKata/tools/sips/examples/example-original.png
  pixelWidth: 2514
  pixelHeight: 1658
  typeIdentifier: public.png
  format: png
  formatOptions: default
  dpiWidth: 144.000
  dpiHeight: 144.000
  samplesPerPixel: 4
  bitsPerSample: 8
  hasAlpha: yes
  space: RGB
  profile: Color LCD

Converting File Format

Use setProperty to change the format:

$ sips -s format jpeg examples/example-original.png --out examples/converted_format.jpg
/.../LittleCodingKata/tools/sips/examples/example-original.png
  /.../LittleCodingKata/tools/sips/examples/converted_format.jpg
$ sips -g all examples/converted_format.jpg
/.../LittleCodingKata/tools/sips/examples/converted_format.jpg
  pixelWidth: 2514
  pixelHeight: 1658
  typeIdentifier: public.jpeg
  format: jpeg
  formatOptions: default
  dpiWidth: 144.000
  dpiHeight: 144.000
  samplesPerPixel: 3
  bitsPerSample: 8
  hasAlpha: no
  space: RGB
  profile: Color LCD

Converting Image Dimensions

Re-sampling with a max limit, preserves aspect ratio:

sips -s format jpeg --resampleHeightWidthMax 1024 examples/example-original.png --out examples/converted_format_and_size.jpg

Batch Conversion

Either convert in-situ by not specifying an output:

$ sips -s format jpeg --resampleHeightWidthMax 1024 examples/*.png

Or target an output directory, and glob the input files:

$ sips -s format jpeg --resampleHeightWidthMax 1024 examples/*.png --out examples/batch1
/.../LittleCodingKata/tools/sips/examples/example-original.png
Warning: Output file suffix changed to jpg
  /.../LittleCodingKata/tools/sips/examples/batch1/example-original.png
/.../LittleCodingKata/tools/sips/examples/example-original2.png
Warning: Output file suffix changed to jpg
  /.../LittleCodingKata/tools/sips/examples/batch1/example-original2.png

Credits and References

About LCK#168 tools
Project Source on GitHub Return to the Project Catalog

This page is a web-friendly rendering of my project notes shared in the LittleCodingKata GitHub repository.

LittleCodingKata is my collection of programming exercises, research and code toys broadly spanning things that relate to programming and software development (languages, frameworks and tools).

These range from the trivial to the complex and serious. Many are inspired by existing work and I'll note credits and references where applicable. The focus is quite scattered, as I variously work on things new and important in the moment, or go back to revisit things from the past.

This is primarily a personal collection for my own edification and learning, but anyone who stumbles by is welcome to borrow, steal or reference the work here. And if you spot errors or issues I'd really appreciate some feedback - create an issue, send me an email or even send a pull-request.