Saturday, 1 January 2011

Trying to compress PNGs with foreign characters in the filenames

This morning I was working on some more articles for my photography tips website. Not actually writing the articles, just finding relevant CC licensed Flickr photos and Amazon products to illustrate and break up the articles. The actual articles are from articlesbase.com.

One of the articles was advertising a product that accepts affiliates. So I signed up to their affiliate program, but then they didn't seem to actually offer promoting that particular product as an affiliate! I spent quite a while trying to see if it was possible, since it seems strange that they would allow you to promote most of their products as an affiliate, but just not that particular one.

In the afternoon I started getting some pog images ready to update my pog website. Some of the images (PNGs) had Japanese or Chinese characters in the filenames, and when it came to optimising them with PNGGauntlet, I found that it skipped all the ones with the foreign characters.

After doing some googling, I couldn't find any other reports of this, or a solution, so I thought I'd try an alternative to PNGGauntlet / PNG-OUT. I found the website smush.it, which allows you to upload you PNG files. It then compresses them, and provides a zip file of the compressed files for you to download.

While smush.it did compress the PNG files, and it displayed the filenames on the website correctly, the filenames in the actual zip file it provided for download were all mangled, like
04-Nobisuke-Nobi-(Úçĵ»ö-Òü«Òü¦Õè®).png

So I looked to see if there was a linux program I could use, since Linux is much better with unicode / utf-8 support than windows. I found there was a linux port of PNG-OUT (seems weird for a command line utility to be ported from windows to linux, usually it is the other way round).

Next I needed to know how to use the command line PNG-OUT as I'm used to the ease of the PNGGauntlet GUI. I found this tutorial, which gives all the command line options for PNGOUT on windows: PNGOUT Tutorial. Now I just needed to know how PNGOUT wanted to command line parameters in Linux.

I tried running pngout --help, the --help wasn't actually recognised, but it output the options / help by default anyway. The answer was just that pngout on linux uses a dash "-" instead of a switch "/" on windows.

But when I tried running pngout on linux to compress a folder of png files, it wouldn't work. After some messing about, I could only think that pngout only supports compressing one file at a time, and doesn't support batch processing.

So I had to write a bash script:
for f in $1/*.png
do
 ./pngout -s0 -kt -y $f
done;
I placed it in the same folder as pngout and made it executable, and it worked quite nicely like
./pngoutbatch.sh ~/folder-with-pngs-in

What a lot of palaver just to compress some PNGs with foreign characters in the filenames!

In the evening I watched an episode of Star Trek TOS with Mauser and Bo. I did a Japanese lesson with Mauser, then went on Animal Crossing.

No comments: