Hudzilla.org - the homepage of Paul Hudson
Contents > Multimedia > Images Wish List | Report Bug | About Me ]

11.2.2     Choosing a format

This is NOT the latest copy of this book; click here for the latest version.

PHP gives you a good selection of options when choosing an output format: PNG, GIF, JPEG, and WBMP to name a few. Normally, though, one is best for a certain type of image.

Generally speaking, for high-quality images with many colours or a lot of detail, the JPEG format should be preferred. JPEG saves in true colour and allows you to set the compression ratio in order to get the best trade-off between size and quality. PNGs, on the other hand, work best as a replacement for GIFs, and as such work well using limited colours. They also offer alpha transparency, and really teensy file sizes.

So, put as simply as possible: for photographs, prefer JPEGs, and for everything else, prefer PNGs. Just as an aside, and at the risk of starting a flame war, the correct pronunciations are: "ping", "jay-peg", and "jif". Note that WBMP is not Windows Bitmap as you might have first thought - it stands for Wireless Bitmap and is designed for use in limited bandwidth situations.





<< 11.2.1 Creating new images: imagecreate(), imagedestroy(), imagecolorallocate()   11.2.3 Getting arty: imagefilledrectangle() >>
Table of Contents
Want to see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.



My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!



Top-right shadow
 
Bottom-left shadow Bottom shadow

Comments from other readers
Be the first to add a comment to this chapter!



Add comment
Please note that by posting a comment here you are committing it to the public domain. This is important so that others can make use of your code themselves, and also so that I can incorporate helpful notes directly into the main text. Comments are limited to 2000 characters in length.

If you are reporting an error in the content, please tell me directly.

Your name/email address:
Your comment:
 
Now, in order to verify that you're a real person, please answer this simple question: what is two plus eight?
The answer is:
(please write in
numbers, eg 19)


Top-right shadow
 
Bottom-left shadow Bottom shadow