Re: [Matplotlib-users] Reducing png file size
Jesper Larsen writes: > Unfortunately the files are quite big (up to ~300 kb). I have however > tried using the Linux tool pngnq to reduce the file size with a factor > ~3-4 with almost no degradation of the result. > Pixel depth (Pixel Depth): 32 > Colour Type (Photometric Interpretation): RGB with alpha channel > Pixel depth (Pixel Depth): 8 > Colour Type (Photometric Interpretation): PALETTED COLOUR (256 > colours, 0 transparent) This means pngnq has quantized the original RGBA image with 8 bits per channel to an image with a 256-color palette. I don't think Agg has any support for rendering directly to a paletted image, so to achieve similar results, you would have to do the quantization in a separate pass anyway. > I am not using transparency for anything. For a web application a > reduction from 300 kb to 90 kb is really important so I hope you have > some good ideas. A web application needs to be fast, right? According to its home page, pngnq "is limited mostly to off-line uses rather than real time image delivery". You could take a look at PIL to see if it has any fast quantization algorithms, and pass your result to it as in the to_numeric.py example (see also webapp_demo.py for how to avoid using the pylab machinery for figure management). If not, you could always implement some fast quantization algorithm in numpy: http://en.wikipedia.org/wiki/Color_quantization My guess is that if you always produce similar-looking images, you could fix the palette off-line using whatever fancy algorithm you like, and then the actual conversion could be done pretty fast, especially if you can forgo dithering - perhaps for many types of charts it is not necessary. -- Jouni K. Seppänen http://www.iki.fi/jks -- Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Reducing png file size
Hi mpl-users, I have a web application in which I produce png files using matplotlib. Unfortunately the files are quite big (up to ~300 kb). I have however tried using the Linux tool pngnq to reduce the file size with a factor ~3-4 with almost no degradation of the result. I therefore wondered whether it is possible to setup matplotlib to do something similar (from the source code the savefig method for png files does not seem to use any keyword arguments). Here is the output of the command pnginfo for the matplotlib output file and the pngnq processed file: 0.0.0.0.0.0.20090517t00z.768.png... Image Width: 768 Image Length: 328 Bitdepth (Bits/Sample): 8 Channels (Samples/Pixel): 4 Pixel depth (Pixel Depth): 32 Colour Type (Photometric Interpretation): RGB with alpha channel Image filter: Single row per byte filter Interlacing: No interlacing Compression Scheme: Deflate method 8, 32k window Resolution: 5039, 5039 (pixels per meter) FillOrder: msb-to-lsb Byte Order: Network (Big Endian) Number of text strings: 0 of 0 Offsets: 0, 0 0.0.0.0.0.0.20090517t00z.768-nq8.png... Image Width: 768 Image Length: 328 Bitdepth (Bits/Sample): 8 Channels (Samples/Pixel): 1 Pixel depth (Pixel Depth): 8 Colour Type (Photometric Interpretation): PALETTED COLOUR (256 colours, 0 transparent) Image filter: Single row per byte filter Interlacing: No interlacing Compression Scheme: Deflate method 8, 32k window Resolution: 0, 0 (unit unknown) FillOrder: msb-to-lsb Byte Order: Network (Big Endian) Number of text strings: 0 of 0 Offsets: 0, 0 I am not using transparency for anything. For a web application a reduction from 300 kb to 90 kb is really important so I hope you have some good ideas. Otherwise I guess I will have to put in a call to pngnq in my code (although I prefer to avoid calls to external programs in the Python code when possible). Best regards, Jesper -- Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users