PNG Optimizer

Also available from Macports.

port info AdvanceCOMP
sudo port -v install AdvanceCOMP

Confirmed that it installs advancecomp v1.20.

-Chris

Thanks guys,

Everything works fine now. Including ImageOptim :grinning:

—
Cary

Updated for macOS Sierra

If you are using Sierra (10.12) please redownload the updated macro from the download link in the original post. (It should work with both El Capitan and Sierra.)

1.0.1

  • HTML prompt updated for macOS Sierra.
  • Spotlight comment now gets written also when advpng is disabled.
  • Changed some defaults: Speed -> 1, Dither -> 1, advpng -> 7z.

Do you know of a way to reduce screenshots saved to the clipboard? I often save notes about software in a Scrivener file and save the file first to the desktop and then drag it into Squash and then drag the output image into Scrivener to keep the file size down. There is of course way too much friction in that when I am trying to take notes and keep in the flow of what I am doing.

I’ll continue searching but thought I would ask since this seems close to what I am trying to do.

Do you know of a way to reduce screenshots saved to the clipboard?

As far as I know the clipboard always holds the uncompressed image data (public.tiff). So I don’t think it’s possible.

I also tried it with with pbpaste and pngquant in the shell, but it seems pngquant only reads from file (?).
‌

I often save notes about software in a Scrivener file and save the file first to the desktop and then drag it into Squash and then drag the output image into Scrivener to keep the file size down. There is of course way too much friction in that when I am trying to take notes and keep in the flow of what I am doing.

Not sure if I understand correctly, but assuming you speak about screenshots which are part of your software notes, I would do this workflow:

  1. Drag your (unoptimized) screenshot PNGs into Scrivener. (Into the sidebar, not into a text document!)

  2. Once you have collected a fair number of PNGs open the Scrivener document bundle in the Finder (right-click, Show Package Contents).

  3. Select all the PNGs. It should look like this:

  4. Run my PNG Optimizer macro on the selected files (in one go). Important:

  • Select “Overwrite existing files”
  • Select File naming: “Overwrite original file”
  1. The result will be something like this:

This way it takes about 30s to optimize 30 PNGs. As long as you don’t change the output file names, Scrivener will be content.

Thanks Tom for the help with this and the details on the Scrivener workflow.

That is interesting in your picture that you got all those images below your trash. I didn't think and can't get anything below my trash it always has to stay in the research folder. Regardless that is a pretty cool idea that helps some but mostly my files are always stored in the text document which as you know Scrivener saves as .rtf so I can't optimize the images at that point.

I'll keep hunting for a solution if possible.

Uhps, don’t do that! If you drag them into the RTF the image data gets hex-encoded and you get twice the file size, no matter if the PNG was optimized before or not. If you leave them stored as individual files inside the document bundle (as shown) they keep their original format and size.

That is interesting in your picture that you got all those images below your trash. I didn't think and can't get anything below my trash it always has to stay in the research folder.

I think it doesn’t matter if they are inside the Research folder or just in the sidebar. If you open the document bundle they seem to be always in the “Docs” subfolder.

Yikes, I never checked that, now I am even more depressed about what I have been doing than before! I just did a test and a 2.1MB image made a new document jump to 4.2MB. Optimizing that same image made the image 1.2MB and then when dragged into Scrivener went up to 3.4MB so more than double but not quite as much as the none optimized image (I see no noticeable difference between the optimized and not optimized when using Squash.app).

I might just be stuck with bloating my Scrivener files because I need them inline with the text I am typing and see no other way around it. Your information was much like watching the daily news, I feel informed yet sad. In all seriousness though thank you for making me aware of that.

I see no noticeable difference between the optimized and not optimized when using Squash.app

I don’t know what exactly Squash does. Judging by the reviews on the MAS and on macupdate, it doesn’t seem very promising.

Virtually all good PNG tools are open source or freeware, e.g. pngquant or advpng (which I’m both using in my macro).

Pngquant can reduce the size by a huge degree, but it is not lossless, since it reduces the number of colors. However you can set the amount of quantization by setting the desired percentage of the original quality, which is very handy. And for things like screenshots (large areas of uniform colors, not much halftones) 256 colors or less are more than enough.

Advpng is lossless and thus not as efficient as pngquant. It optimizes the PNG compression by applying more efficient algorithms.

A combination of both yields very good results which are hard to beat IMO.
‌

I might just be stuck with bloating my Scrivener files because I need them inline with the text I am typing and see no other way around it.

If you need them inline, a couple of possibilities come to mind:

  • Produce HTML documents
  • Use Apple’s RTF implementation (aka TextEdit). If you add images to an Apple-RTF the document will be converted to .rtfd, which is a document bundle that contains the text (RTF) file and the unchanged images.
  • Use Ulysses
  • Use iA Writer
  • Use Nisus Writer
  • Use Quiver
1 Like

Thank you I have purchased DevonThink Pro and Papers but they were a bit more than what I needed in the end and just got in the way.

I actually have Quiver and considered it but it doesn't seem to add images inline but I will have to mess with that some more. Seems like I purchased Ulysses in a bundle but I will have to look for that if I really did or not.

Thanks for the help and tips.

I actually have Quiver and considered it but it doesn't seem to add images inline but I will have to mess with that some more.

Well, you can drag images into a Text cell. But, since the whole Quiver is based on cells, I think this qualifies as “inline” :wink:

I have purchased DevonThink Pro and Papers but they were a bit more than what I needed in the end and just got in the way.

If you’re looking for something like DevonThink that does not get in the way have a look at EagleFiler. There exists an entire thread about the “DevonThink aggravation”, and I’ve posted a short summary of EagleFiler there.

1 Like

Thank you Tom this is great and I look forward very much to using EagleFlier, I just read through the thread you posted to and look forward to trying out your macros you made for EagleFiler. Always great to learn and know others tried and experienced the same pain I felt when using DevonThink Pro. I just kept thinking I need to give it a better chance and spend more time with it but the non integration with the Finder really was the show stopper and made me wonder why I even purchased in the first place at the extreme cost.

Hi skillet,

and look forward to trying out your macros you made for EagleFiler

Happy to hear that you want to try my macros, but…

Eagle Filer works perfectly fine without my macros! My macros are pure luxury, they only add some UI comfort. (They do not add functionality or work-arounds for bugs.)

So, if you are new to EagleFiler, my macros may even be confusing :wink: and it would perhaps be better to get familiar with EagleFiler (without any macros) first.

Just a thought…

2 Likes

Hi all, I am getting the following error:
I installed home-brew -
pngquant and I believe I set the path for home-brew correctly
/usr/local/bin

any help is appreciated
error message follows:

MACRO ERROR  on  2017-02-27 09:18:37

This info was pulled from the KM Engine Log for the
Last Macro error that occured.

Macro: Trying
Action: Search Variable ‘pqScriptOut’ Using Regular Expression (case sensitive)
Status: cancelled
Error: Search Variable failed to match (?m)-color image as (.*?)$

Log File: ~/Library/Logs/Keyboard Maestro/Engine.log

Enter /usr/local/bin/pngquant in the Terminal and hit Return, to see if pngquant is found.

If it isn’t found, then find out where it has been installed.

If it is found:

Have you set KM’s ENV_PATH variable to include the /usr/local/bin path? (KM Editor > Preferences > Variables)
‌

If ENV_PATH is not correctly set, then (create and) set the variable in KM’s preferences. For example to:

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

Note: You can also choose to set different paths. The important thing is that /usr/local/bin is included, and preferably at the beginning. Otherwise KM does not know where to find the Homebrew-installed tools.

See also Wiki.
‌

Then test with this macro, to see if pngquant is found now:

_[test] Shell Test.kmmacros (1.4 KB)

1 Like

pngquant is found:


I'm not clear on what the path should be set to, I had:
/usr/local/bin
But you had this:
/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin

I ran the shell test and get the following.

/var/folders/xt/7vy03w2x6t5gbpvdmj2mp7s80000gn/T/Keyboard-Maestro-Script-464A0ECF-DADA-4C47-B032-39CE2673426F: line 1: pngquant: command not found

thanx

/usr/local/bin works also. Make sure there is no newline (Return) at the end (after the bin).

Edit:

I.e., this is correct:

This is wrong:

no carriage return there
/usr/local/bin

Odd.

The variable is named exactly ENV_PATH (case sensitive), right?

Try the Test macro with the explicit path:

Maybe the png I’m selecting isn’t 32 bit? would that be an error?

correct, case sensitive. ENV_PATH
ran with /usr/local/bin/pngquant

result:

pngquant, 2.9.0 (December 2016), by Kornel Lesinski, Greg Roelofs.
Color profiles are supported via Cocoa. Using libpng 1.6.28.

usage: pngquant [options] [ncolors] – pngfile [pngfile …]
pngquant [options] [ncolors] - >stdout <stdin

options:
–force overwrite existing output files (synonym: -f)
–skip-if-larger only save converted files if they’re smaller than original
–output file destination file path to use instead of --ext (synonym: -o)
–ext new.png set custom suffix/extension for output filenames
–quality min-max don’t save below min, use fewer colors below max (0-100)
–speed N speed/quality trade-off. 1=slow, 3=default, 11=fast & rough
–nofs disable Floyd-Steinberg dithering
–posterize N output lower-precision color (e.g. for ARGB4444 output)
–strip remove optional metadata (default on Mac)
–verbose print status messages (synonym: -v)

Quantizes one or more 32-bit RGBA PNGs to 8-bit (or smaller) RGBA-palette.
The output filename is the same as the input name except that
it ends in “-fs8.png”, “-or8.png” or your custom extension (unless the
input is stdin, in which case the quantized image will go to stdout).
The default behavior if the output file exists is to skip the conversion;
use --force to overwrite. See man page for full list of options.