Everything for the Nothing

Somewhat Random nerdy things that happen to me and others.

Recent Comments

Powered by Disqus
Mon Feb 9

Convert TGAs to PNGs

So I gave myself a little project over the weekend.  I needed to convert a bunch of Targa files over to PNG to help save space on my server. I decided to do it with Python.

Why convert the Targa image files to PNGs?  Well, file size was the first reason.  The PNG format stores 8 bit per pixel files in a nice small package. Smaller, even, than Tiff or OpenEXR.  They do take a bit longer to create than the aforementioned, but time is on my side, so it’s not an issue.  And just to make sure that I didn’t mess things up with the actual contents of the files, I took the original Targa and did a difference in Photoshop then cranked up the levels to see if there were any changes in the image data that would affect quality.  They were exactly the same including the alpha channel. The only difference was the file size.

The savings on file size are fantastic! The original size of the files was between 6 and 8 megabytes each and there were about 100,000 files to convert.  On average they were reduced to about a third their original size without any quality loss.  And because the script delets the Targas (only after it creates the PNG file) when its done I end up getting a ton of room on my drive.

So, here I give you, the Python script.  You will need to install PIL (Python Image Library) and pyGame (some files have meta data and couldn’t be opened with PIL but could with pyGame) to run this script.  It’s best to just run py2exe on it and then attach it to your context sensitive menu for your file browser.  That way you can just right click on a folder and run the script.

ImageConvert.py

Comments (View)
blog comments powered by Disqus