PNG Optimizer

This macro is basically a GUI wrapper for the pngquant command line tool, with some additional features.

Pngquant is a very efficient, lossy quantization and compression tool for png and other image formats. If you have a website where you regularly upload screenshots or other non-jpeg images you are probably familiar with pngquant.

[Contrary to ImageAlpha which is also a GUI for pngquant, this macro gives you access to the full feature set of the command line tool, most notably to the full range of quality and dither settings.]

For the macro to work you need to have the pngquant command line tool installed on your Mac. A comfortable way to install the latest version is via Homebrew:

brew install --HEAD pngquant

Make sure that Homebrew’s bin path (usually /usr/local/bin) is available to Keyboard Maestro by setting the ENV_PATH variable accordingly in Keyboard Maestro’s preferences.

If you don’t like Homebrew you can also get the latest pngquant binary from here.

How to Use the Macro

  1. Select one or more png, tiff, gif or bmp images in the Finder.
  2. Launch the macro. You’ll be presented with this setup dialog:
  3. Select the desired settings. To get some tooltip information you can hover with the mouse over the checkboxes and menus. Further information is available on pngquant’s homepage.

Some Additional Features

Most of the settings translate to pngquant’s command line options. But I’ve added some comfort features:

File Naming

In addition to pngquant’s standard suffixes .or8/.fs8 or overwriting, you have the option to append a unique suffix to each output file. This makes it easy to test various settings on the source image file consecutively without having to rename the output files manually.

(The unique suffix is built of the number of seconds since the last restart of the Mac.)

Write Comment

Writes a Finder comment to the file with information about the selected settings and the effectively achieved results.

For example:

Very useful if you want to find out the best settings for a given type of image. The part before the “—” is for pngquant, the part after is for advpng (see below).

Deflate with advpng

This will automatically launch advpng on the file after pngquant has finished. Advpng is a pure deflate compressor and can further reduce file size by 5–20% (losslessly).

To use advpng you need to have it installed on your Mac. Similar to pngquant you can install it via Homebrew (thanks to @Onan for the find):

brew install advancecomp

Alternatively you’ll find the source code for the latest version here (scroll down to “AdvanceCOMP”; the instructions are in the “INSTALL” file and usually it compiles w/o any problems).

There are lots of png optimizers/compressors available but in my experience advpng gives good results in combination with pngquant while still being very fast.

Hand Over to ImageOptim

If you are using ImageOptim you can select this to pass the file to ImageOptim at the end.

ImageOptim is an all-in-one GUI wrapper for a plethora of lossless png optimizers/compressors, so you can try different ones instead of advpng. Please note that the optimizers included in the ImageOptim app bundle are not always the latest versions.

Happy Optimizing!


↧Download


Macro structure:

4 Likes

Hey Tom,

Interesting.  :smiley:

FYI:

pngquant and AdvanceCOMP are also available via Macports.

-Chris

does this still exist?:wink:

Both seem to be outdated on Macports, advpng slightly (1.20 is current), pngquant horribly (2.6.0 is current!)

Yeowch! I'll see about tweaking the tails of the maintainers.

Thanks.

-Chris

advpng 1.20 is already in the pipeline (as of about 12 hours ago). It should be available for updating in the next few days if not sooner.

pngquant is unknown at present, but I have a query out to the maintainer.

I'll file a ticket if I don't hear back from him, but in the meantime there's an OSX binary available on the pngquant homepage.

-Chris

Yes, this is mentioned in my description above.

Hey Tom,

Nice job! Works perfectly, except the "Hand over to ImageOptim". I get the following error:

"/var/folders/99/xq_fy6n13092rqg5tssd7c200000gn/T/Keyboard-Maestro-Script-C12FF574-92C8-4753-A926-74E839B8556A: line 1: open: command not found"

ImageOptim is installed:

—
Cary

Just tested it here with Handing over to ImageOptim and it worked as usual.

What is disconcerning me is the “open: command not found” thingy in your post. Did you alter the macro (the bash script) in any way?

No, I haven’t changed anything.

—
Cary

So, what is the path to ImageOptime on your volume?

/Applications/ImageOptim.app

—
Cary

Weird. The same path here.

A (probably) stupid question:

  • It it is set to jpg or tiff, right?

[Edit 2016-04-22:]
The above comment was for the Enhanced Screenshot Macro. So, forget it.

You mean I selected a JPEG or TIFF? No, only PNG.

—
Cary

Please see my edited post above. I have to grab some sleep right now, you’ll here from m soon :roll_eyes:

Tom,

I found something strange. If I set the ENV_PATH variable = /usr/local/bin, all the shell scripts available in Keyboard Maestro cease to function. All of them return “xxx: command not found”. If I delete the ENV_PATH variable from the preferences, the shell scripts work again but, of course, PNG Optimizer ceases to function.
—
Cary

Cary, doing that removes the default paths to the other programs. If you set the ENV_PATH variable in the preferences, you need to include the base paths along with any additional paths. So you would set ENV_PATH to be /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

Tom: FYI if you want to update the top post, the AdvanceCOMP package, containing advpng, can be installed with brew install AdvanceCOMP. A good alternative to downloading the source and compiling it.

1 Like

Great find! Thanks! I was already wondering why it was missing in Homebrew but I was too stupid to have a closer look at the repository…

[Edit:] A added your tipp to the post above and to the Enhanced Screenshot post. Thanks again.

I would put the the more “current” (specialized) local paths at the front, like this:

/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin

1 Like