Eric Firing wrote:
You can post-process the image with something like ImageMagick.
Another alternative is to use PIL -- you can grab the matplotlib buffer,
make a PIL image out of it, and use PIL to convert to an 8-bit palleted
image.
For that matter, you could probably bypass MPL, and use numpy to create
the 8-bit image you want, and PIL to save it as a PNG.
-Chris
Thanks much for the helpful information. I will revisit PIL; I tried
matplotlib because of other requirements (colorbar, various figure annotations)
which did not appear to be readily available in PIL. At this stage, it depends
on how important the requirement is to reduce the size of the PNG images.
-- jv
Try optipng:
http://optipng.sourceforge.net/
Here I am running it on a gray-scale image created by mpl; it was
generated in such a way that there are only 100 distinct shades of gray.
You can see that it reduces the file size by quite a bit, converting it
from RGBA to grayscale. This is lossless. For this to work, you have
to make sure you have no more than 256 distinct colors--they don't have
to be gray.
-rw-rw-r-- 1 efiring efiring 8458 2010-07-22 16:26 grayfig.png
efir...@manini:~$ optipng grayfig.png
OptiPNG 0.6.3: Advanced PNG optimizer.
Copyright (C) 2001-2009 Cosmin Truta.
** Processing: grayfig.png
800x600 pixels, 4x8 bits/pixel, RGB+alpha
Reducing image to 8 bits/pixel, grayscale
Input IDAT size = 8352 bytes
Input file size = 8458 bytes
Trying:
zc = 9 zm = 8 zs = 0 f = 0 IDAT size = 3721
zc = 9 zm = 8 zs = 0 f = 5 IDAT size = 3301
zc = 9 zm = 8 zs = 1 f = 5 IDAT size = 3286
Selecting parameters:
zc = 9 zm = 8 zs = 1 f = 5 IDAT size = 3286
Output IDAT size = 3286 bytes (5066 bytes decrease)
Output file size = 3377 bytes (5081 bytes = 60.07% decrease)
efir...@manini:~$ ll grayfig.png
-rw-rw-r-- 1 efiring efiring 3377 2010-07-22 16:26 grayfig.png
Eric
------------------------------------------------------------------------------
Thanks much for this information and also for taking the additional time
to try the optipng tool. It is very helpful.
Since the above mentioned PNG generation is one step in a "near"
real-time products generation system, I was hoping to avoid the addition
of another component (i.e., PNG compression) in the stream, but it
appears unavoidable.
-- jv
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users