|
Save GIF using 8bit versus 2bit |
Posted by James Moberg on Jun-16-2011 06:22 |
|
I'm using ColdFusion 9's CFDocument tag to create FlashPaper and PDF documents using chart images generated by ChartDirector.
I'm having an issue with the GIF 2bit images that ChartDirector is creating. I can embed the 2bit GIFs into FlashPaper, but not into a PDF. I believe that this is an Adobe ColdFusion bug and I am reporting it to them. In the meantime, I'm trying to determine if there are any options to save GIF images as 8bit. I'm using the makeTmpFile() function and using "1" (GIF) constant, but there there don't appear to be any options beyond that.
Thanks. |
Re: Save GIF using 8bit versus 2bit |
Posted by Peter Kwan on Jun-16-2011 18:29 |
|
Hi James,
The GIF standard allows using 1 to 8 bits per pixel, for an image with 2 to 256 colors. ChartDirector will automatically choose the minimum number of bits per pixel depending on the actual number of colors the image have. The results in the smallest GIF. This behaviour is not configurable.
I think GIF with less than 8 bits per pixel is quite common. Many image editing software (eg. Photoshop) has the same behaviour as ChartDirector, so as to produce the smallest possible GIF. So it is quite surprising that it would not work with ColdFusion PDF.
I am thinking, may be 2-bit GIF is uncommon enough that the ColdFusion PDF has not been tested for it. You may try the following methods:
(a) Try to use PNG instead of GIF, if the PDF supports PNG. In PNG, you can force "True Color Mode" (24/32 bit per pixel), even if your image only has a few colors and can be represented exactly using a few bits per pixel. See "DrawArea.setPaletteMode"
(b) Try to determine the GIF supported by ColdFusion PDF. May be it supports 4-bit per pixel minimum. In this case, you would need to artificially ensure the GIF has at least 16 colors. One method is to put 16 pixels of different colors on the chart. For example, you can put it on the border. If your border is white, may be you can use a very light grey (like 0xfefefe) as the border, and put some pixels like 0xfdfdfd, 0xfffffe, ... near the corners. It is hard or impossible to notice by the user.
(The computer video hardware has 8 bit per color resolution. However, the hardware in many common LCD monitors actually only have 6 bit resolution. So you may not notice any color difference if it is small.)
Hope ths can help.
Regards
Peter Kwan |
Re: Save GIF using 8bit versus 2bit |
Posted by James Moberg on Jun-17-2011 08:27 |
|
I was also surprised when the 2bit GIF image didn't work. (When working with ColdFusion8, sometimes small PNGs with similar file sizes would cloned throughout a PDF. This made it difficult to use small images (even PNGs made using CF8), so I started using GIF.)
I posted it as a bug to Adobe, but I'm not thinking that it will be fixed anytime soon.
I prefer ChartDirector over CFChart and many browser-based jQuery solutions.
Thanks for the quick response. |
Re: Save GIF using 8bit versus 2bit |
Posted by Peter Kwan on Jun-17-2011 17:43 |
|
Hi James,
Have you tried to use PNG with "True Color Mode"?
Like GIF, PNG supports using 2 bits to 8 bits per pixel for palette based (suitable for images with 256 colors or less). But PNG also supports true color images (eg. 24 bit per pixel).
I suppose any good software would output PNG using the minimum number of bits per pixel. So if small PNGs do not work, it is possible that they are using 2 bits per pixel, and may be the PDF generator does not support 2 bits per pixel. If you force the PNG into true color mode, it may work. In ChartDirector, you can do this using:
c.getDrawArea().setPaletteMode(cd.NoPalette);
Note that for the same image, using 24 bits per pixel does not necessarily make the PNG image much larger compared to 2 bits per pixel. If you count the number of bits, you may think it is 12 times larger, but I think practically it would only be 1.2 to 1.5 times as large. It is because in PNG, the bits are compressed using a data compression algorithm. So the inefficiency of 24 bits per pixel will be "compressed away" during data compression.
If the image pixel size is really small, you may consider to use BMP as well.
Hope this can help.
Regards
Peter Kwan |
|