Sam,
File size totally depends on what you're working with. For text and graphics, PNG is significantly smaller than JPEGs that have quality settings anywhere near close to looking similar. For other things, it's tricky.
Certainly, reducing the number of colors is a good way to cut file size. If you're really picky about this, you could use exec() and call the pngcrush binary for your pngs (though this will slow the process down enough to not be a good idea if you're running it in real time). Depending on many factors, pngcrush can often yield a 5-25% reduction in file size with zero quality loss.
Also, I'm not sure what you're actually compressing, but turning off antialiasing will cut the number of colors required by a lot (automatically saving space) and eliminate all the excess edge detail (also saving a bunch). If you're compositing the image in real time (i.e. image + text) try cutting the colors on each one individually (before compositing) and you may be able to use fewer colors (i.e. make the antialiased text be only 3-4 colors but allow the image to retain more quality).
You might also like using imagemagick (in the command line) and working with things there. I haven't yet found enough of a need for it to play with it yet, but I would bet you could do all sorts of things that might help file size (better color reduction, etc) and it doesn't look too tricky.
Good luck!
-Galen
On May 14, 2004, at 7:37 PM, Sam Joseph wrote:
Hi Galen,
Thanks for that - all sorted now. I had looked at imagetruecolortopalette, but had not taken it on board. I'm now using it as follows to get a balance between image quality and file size (for png output):
imagetruecolortopalette ( $myImage, true, 64);
It's just remarkable how much better quality I can get for a given size with jpeg as opposed to png - but then I'm unable to use jpeg for my current application.
Many, many thanks for your help.
CHEERS> SAM
Galen wrote:
Sam,
OK, sorry, I only had a few moments before. Let's see if this points you in the right direction.
Basically, you can have "standard" 8-bit images ("color") and then "true" color images (24 bit). When you "create" the GD image resource, you use a function to do that. One such function is imagecreate() - this generates a palette based image that (IIRC, 8 bit or less) will compress to that smaller PNG 8 file. imagecreatetruecolor() typically makes full-depth ("true color") images that become PNG 24/32 and support transparency and everything. You may find imagetruecolortopalette() also of interest as it transforms a true color image into a palette based image.
So the distinction is this: true color = 32 bit (24 bit + alpha channel), palette based = exact number of colors + no alpha channel
I may be subtly wrong on a few of these smaller points, and please accept my apologies if I am, but the gist is that you need a palette-based image to get 8-bit PNGs!
-Galen
On May 14, 2004, at 4:27 PM, Sam Joseph wrote:
Hi Galen,
Many thanks for your reply. I tried to find things in the php manual relating to bit depth, but I didn't find anything relevant:
http://www.google.co.jp/search?sourceid=navclient&hl=ja&ie=UTF -8&oe=UTF-8&q=site:www%2Ephp%2Enet+bit+depth
I haven't read every single one of the image functions in detail, but I did look through them all, and at the moment I can't see anything that allows me to manipulate the bit depth. The closest thing I can see is the imagecolorstotal function which returns the number of colors in the specified image's palette.
Apologies if I'm missing something obvious, but if anybody knows about a specific function that does this I'd be very interested to hear about it.
Many thanks in advance.
CHEERS> SAM
Galen wrote:
IIRC, the goal of PNG is lossless output and it outputs that exactly with PHP. What you send is what you get out. When you're using GD, I suggest you make an 8 bit GD image resource, then make that into PNG. There are several functions dealing with converting bit depth and such, poke around the GD image reference section in the PHP manual.
Sorry if this is too vague, it's all off the top of my head but I think it will give you enough to go on.
-Galen
On May 14, 2004, at 3:05 PM, Sam Joseph wrote:
Hi all,
I've recently got the GD libraries set up and working with php and I have been resizing and reformating images to my hearts content.
One thing I notice however is that when I output png images they seem by default to come out in the larger size PNG32 format, as opposed to the lightweight PNG8 format that I would prefer.
I've checked the archives and googled and found no direct reference to this issue.
If anybody can tell me how to adjust the png output format php I'd be very grateful. Although I have the feeling that this might well require hacking away at the gd source ....
Thanks in advance.
CHEERS> SAM
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php