eastcoastguyz wrote:
As I am learning PHP and seeing examples of handling graphics using the
imagecreate functions. The few examples I have run across use PNG as
the graphic file format of choice. Is there a reason for that? I have
used JPG and GIF files, and I have to admit until recently I've not
heard of (didn't have a reason to pay attention to) PNG files before.
I have JPG and GIF images I want to be able to display on a web site
and write some text over them. Should they be converted to PNG files to
do this? Or should they be kept as JPG and GIF files? Thanks!
That depends on what you want. All three formats have their ups and
downs.
GIF:
+) Transparency
+) Lossless compression
+) Very small file sizes
+) Great compatibility with browsers
+) Animations are possible
-) Only up to 8 bit color depth (= 256 colors). That's why it is not
suited very well for true color images. But that's how the files can be
that small even though the compression is lossless.
-) Up to recently was subject to a patented algorithm.
JPEG:
+) Very small file sizes
+) True color -> great for photographs
+) Great compatibility with browsers
-) Lossy compression -> Changing a picture often and saving it again and
again as JPEG will degrade the picture quality quite a bit!
-) No transparency
PNG was developed as alternative to GIF with almost the same
functionality but some improvements:
+) Transparency
+) Lossless compression
+) Patentfree
+) Small file sizes
+) Animations are possible
+) True color
-) Horrible browsersupport, since the format never took of too well.
While most pngs should work in most browsers nowadays you could still
run into serious problems, depending on which software you create your
pngs with or which features (transparency, animation, compression, ...)
you intend to use.
-) File sizes tend to be larger than with the other two formats.
So, my advice is:
If you are looking for graphics that you use on the web go with GIF for
small icon-like graphics with few colors or if you need transparency or
animations and JPEG for true color pictures. You can't go wrong with the
browser support of these formats and if you choose the right filetype
for each particular graphic the formats cons don't matter much.
If you want to store pictures on your harddrive that you might want to
edit again use PNG. True color support with lossless compression is what
you want in this case and browser support doesn't matter as long as you
only use your graphics programs.