since the images only use a couple colors each, just run length encode it. Depending on the image, you may be able to get a super small size that way, and avoid the whole mess.<br><br><div class="gmail_quote">On Sat, Mar 27, 2010 at 11:32 PM, Harishankar <span dir="ltr"><<a href="mailto:v.harishankar@gmail.com">v.harishankar@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><div></div><div class="h5">On Sat, 27 Mar 2010 19:44:54 -0700, Stephen Hansen wrote:<br>
<br>
> On 2010-03-27 08:17:46 -0700, Alain Ketterlin said:<br>
><br>
>> Stephen Hansen <apt.shansen@gmail.invalid> writes:<br>
><br>
>>> If not, are there any decent other image libraries out there that<br>
>>> anyone's familiar with? The only one I could find was PythonMagick,<br>
>>> which seems completely undocumented. Or I'm blind.<br>
>><br>
>> I don't know PythonMagick, but it is based on ImageMagick, which is<br>
>> kind of a swiss-knife in image manipulation and conversion. You could<br>
>> try the standalone tools first, to see if you get what you want/need.<br>
><br>
> Well, I know it -can- do what I need, except the subprocess business<br>
> isn't something I want to deal with. And the library seems utterly<br>
> undocumented. :(<br>
><br>
>> Hmm, a 16x16 image. Don't expect much from the most sophisticated<br>
>> formats (e.g, PNG), because their overhead (headers etc.) may well be<br>
>> above the size of the data. Compression isn't usually targeted at small<br>
>> files.<br>
><br>
> Yeah, I don't expect much from PNG. The images are very small but I<br>
> might be sending a LOT of them over a pipe which is fairly tight, so<br>
> 50-60 bytes matters. That's why I selected GIF.<br>
><br>
>> (BTW: "slight tweaking" may have an effect on file-size if it<br>
>> introduces new colors, because GIF uses a color-table. I guess you know<br>
>> all this.)<br>
><br>
> Yeah, I know this is possible, which is why the tweaking was to be very<br>
> careful: these images all have only a couple indexed colors each, and I<br>
> should be able to do the tweaks and not increase the size excessively.<br>
><br>
> However, the problem is: I left out all the tweaks and it still exploded<br>
> in size.<br>
><br>
> Just opening, and then saving the same file with no changes at all,<br>
> resulted in a 72 byte file growing to 920.<br>
><br>
> I thought it was GIF87a vs GIF89a... but have since come to determine it<br>
> doesn't appear to be. I decided to give PNG a try again, since those<br>
> extra 50 bytes *matter*, but if I can't get GIF to work, 50 is better<br>
> then 900. Unfortunately, I hit the same wall there.<br>
><br>
> If I convert these itty-bitty images into PNG, they're about 120 bytes<br>
> or so. Opening one in PNG, making no changes, and saving, results in the<br>
> new file being 900 bytes too :(<br>
><br>
> So I wonder if there's just some hyper-optimization Photoshop does that<br>
> PIL can't round-trip.<br>
><br>
>> GIF uses the LZW algorithm, and so does zip and gzip (the latter with<br>
>> an additional layer of Huffmann coding). If your images are of fixed<br>
>> size, you _may_ be better off compressing the raw data with a general<br>
>> purpose compressor (i.e., gzip). Check the packages gzip and zlib.<br>
><br>
> Hm. I hadn't thought of compressing the saved version. I could do that,<br>
> I suppose: it just seems there is so much extra stuff which shouldn't be<br>
> needed that's being saved out.<br>
<br>
</div></div>This might not be of much use to you, but I've found by experience that<br>
PNGs are almost always bigger or equal to GIFs of the same resolution,<br>
colour depth and so on. I've never yet seen a PNG file that is smaller<br>
than a GIF for the same set of pixels.<br>
<br>
As mentioned above, compressing raw data stream might be more beneficial<br>
in this situation.<br>
<br>
Also try the pngcrush utility and see what size it gives you.<br>
<a href="http://pmt.sourceforge.net/pngcrush/" target="_blank">http://pmt.sourceforge.net/pngcrush/</a><br>
<font color="#888888"><br>
--<br>
Harishankar (<a href="http://harishankar.org" target="_blank">http://harishankar.org</a> <a href="http://literaryforums.org" target="_blank">http://literaryforums.org</a>)<br>
</font><div><div></div><div class="h5">--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</div></div></blockquote></div><br>