When using png files on the web it is often preferred to use tools like pngcrush on them to optimize their size. This is usually a manual process where a command line tool or website is used to process each image file. I decided to automate this process for me via macOS Automator.
To crush png images I use the opensource tool PNG Crush.
If you have Xcode installed, the pngcrush tool is included as a part of the iOS SDK and there is no additional download required.
If you do not have Xcode you may install PNG Crush via Homebrew using the following command.
If using Xcode method, the pngcrush binary will be at
If using Homebrew, the pngcrush binary will be at
For the rest of the article I will assume the Homebrew method is used. You just need to adjust the paths for the binary if the Xcode method is used.
To crush a PNG image via Terminal you can run the below command.
Automating the process using Automator on macOS.
- Launch Automator via Spotlight Search.
- Select File, New from the menu. Select Quick Action and click the Choose button.
- In the new windows that loads, select the options as below.
- Workflow receives current - image files
- in - Finder.app
- In the search box, type Shell and select the Run Shell Script option to add to the automation on the right by double clicking on it.
- Change the Pass Input option to as arguments.
- Enter the below script commands in the Shell Script box.
- Save the automation as PNG Crush.
You may now browse to any png file(s) in Finder and right click, select Services -> PNG Crush.
While the automation is running you will see a spinning cog in you Menu bar in the top right. When the cog disappears the automation is done and your images have been processed by pngcrush.