Christopher Barker wrote:
Jim Vickroy wrote:
The attachment is a simple script that creates a 2D array of unsigned,
8-bit integers and uses matplotlib to save it as a PNG file.
Unfortunately, the PNG file is much larger than expected -- apparently
because it is True-Color; on my MS Windows machine, bit depth, for the
file, is listed as 32 rather than the expected 8.
Can matplotlib be used to accomplish this? If so, could someone direct
me to where this is discussed?
I don't think so directly. MPL uses a 32 bit image buffer internally,
and that's what gets saved out in the PNG.
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
------------------------------------------------------------------------------
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