473,387 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Why does PHP seem to favor PNG over JPG and GIF files?

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!

Jul 17 '05 #1
14 1831
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!


PNG is preferred because it's an open standard. It far better than GIF
(true color - without colormaps, alpha channel, different compression
schemes available, extensible format). Alas, the animated version of PNG
(called MNG) hasn't become so famous.

PNG and JPG serve different purposes. PNG stores images withous loss of
quality, but JPG strips down the quality in order to take less room on
your harddrive and less time on your wires.

My recommendation: use JPG and PNG. Only use GIF when you desperately
need animation effects (and you shouldn't).

Jul 17 '05 #2
Dani CS wrote:
eastcoastguyz wrote:

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!


PNG is preferred because it's an open standard. It far better than GIF
(true color - without colormaps, alpha channel, different compression
schemes available, extensible format). Alas, the animated version of PNG
(called MNG) hasn't become so famous.


IIRC, until recently, GIF format was subject to a patent which restricted
its application (unless the developer paid for it).

PNG is a more effective format but browser support is not as good,
particularly with transparency (MSIE is the worst, Firefox is better, but
only Konqueror/Safari seems to get it right all the time).

HTH

C.
Jul 17 '05 #3
Dani CS <co*****************@yahoo.es.quita-la-merluza> wrote:
eastcoastguyz wrote:

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!


PNG and JPG serve different purposes. PNG stores images withous
loss of quality, but JPG strips down the quality in order to
take less room on your harddrive and less time on your wires.


Indeed. This makes JPEG the perfect format for photographs, it does
a far better job than PNG in that area, and was specifically
designed for that purpose.

However, for line drawings (hard edges, ...), the JPEG compression
results in artefacts in the drawing that can really spoil the image.
In that case, use lossless PNG.

Regards,
Wald
Jul 17 '05 #4
.oO(Colin McKinnon)
PNG is a more effective format but browser support is not as good,
particularly with transparency (MSIE is the worst, Firefox is better, but
only Konqueror/Safari seems to get it right all the time).


Recent browsers support it quite well.

Only problem is old IE which lacks support for alpha transparency. But
there are ways to deliver a different image for IE if necessary, while
all other browsers will get the PNG.

Micha
Jul 17 '05 #5
On 2005-01-25, Michael Fesser <ne*****@gmx.net> wrote:
Only problem is old IE which lacks support for alpha transparency.


Which gif doesn't support at all afaik.

--
Cheers,
- Jacob Atzen
Jul 17 '05 #6
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.
Jul 17 '05 #7
On 2005-01-25, Anonymous <an*******@nowhere.invalid> wrote:
PNG was developed as alternative to GIF with almost the same
functionality but some improvements:
[snip] -) File sizes tend to be larger than with the other two formats.


In my experience PNG files will be smaller than GIF files, as long as
you remember to make the PNG 8bit color (like GIF's) instead of
truecolor.

--
Cheers,
- Jacob Atzen
Jul 17 '05 #8

"Colin McKinnon" <co**************@andthis.mms3.com> wrote in message
news:ct*******************@news.demon.co.uk...
Dani CS wrote:
eastcoastguyz wrote:

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!


PNG is preferred because it's an open standard. It far better than GIF
(true color - without colormaps, alpha channel, different compression
schemes available, extensible format). Alas, the animated version of PNG
(called MNG) hasn't become so famous.


IIRC, until recently, GIF format was subject to a patent which restricted
its application (unless the developer paid for it).

PNG is a more effective format but browser support is not as good,
particularly with transparency (MSIE is the worst, Firefox is better, but
only Konqueror/Safari seems to get it right all the time).


Hard to believe that PNG has been around for over ten years now. It's a good
case study for how a superior technology fails to supplant an existing one.
I attribute it to the lame choice of name. GIF just sounds better. PNG
sounds like some chemical that they put into spam to keep it from rotting.

It's similiar what's happening to the OGG format. "Downloading an ogg"
sounds gross, somehow.
Jul 17 '05 #9
Jacob Atzen wrote:

On 2005-01-25, Anonymous <an*******@nowhere.invalid> wrote:
PNG was developed as alternative to GIF with almost the same
functionality but some improvements:


[snip]
-) File sizes tend to be larger than with the other two formats.


In my experience PNG files will be smaller than GIF files, as long as
you remember to make the PNG 8bit color (like GIF's) instead of
truecolor.


I know, but since PNG does support true color nobody will really do so.
That's the difference between theory and practice...
Jul 17 '05 #10
Anonymous wrote:
-) 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.
Almost... it's an 8-bit indexed palette. So you have 256 colors to
pick from, but they can be any 256 colors. You can also decrease the
palette size to save space. Eg. if you have a technical drawing, a
1-bit palette may well suffice.

[JPEG] -) Lossy compression -> Changing a picture often and saving it again and
again as JPEG will degrade the picture quality quite a bit!


This will depend largely on what you actually do with the image.
AFIAK, JPEG basically does frequency analysis and run-length encoding on
8x8 pixel blocks of graphics (that's why its good for photographs and
not for straight lines).

There is a JPEG FAQ on the web which goes into more detail.

/m
Jul 17 '05 #11
Chung Leong wrote:

Hard to believe that PNG has been around for over ten years now. It's
a good case study for how a superior technology fails to supplant an
existing one.


After having read the first few posts in this thread I played around with
Photoshop a little to compare PNG and GIF. PNG always made bigger file sizes
(factor 3+).

What is the recommended way to generate PNGs with reasonable file sizes?

--
Markus
Jul 17 '05 #12
Markus Ernst wrote:
Chung Leong wrote:

Hard to believe that PNG has been around for over ten years now. It's a good case study for how a superior technology fails to supplant an existing one.
After having read the first few posts in this thread I played around

with Photoshop a little to compare PNG and GIF. PNG always made bigger file sizes (factor 3+).

What is the recommended way to generate PNGs with reasonable file

sizes?

Probably GIMP <http://www.gimp.org/>

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Jul 17 '05 #13

"Markus Ernst" <derernst@NO#SP#AMgmx.ch> wrote in message
news:41********@news.cybercity.ch...
Chung Leong wrote:

Hard to believe that PNG has been around for over ten years now. It's
a good case study for how a superior technology fails to supplant an
existing one.
After having read the first few posts in this thread I played around with
Photoshop a little to compare PNG and GIF. PNG always made bigger file

sizes (factor 3+).
A factor of 3 indicates that you're saving the file in 24-bit instead of
8-bit mode. When you do a save for web, change the number of colors to 256.
What is the recommended way to generate PNGs with reasonable file sizes?

--
Markus

Jul 17 '05 #14
Markus Ernst wrote:
Chung Leong wrote:
Hard to believe that PNG has been around for over ten years now. It's
a good case study for how a superior technology fails to supplant an
existing one.

After having read the first few posts in this thread I played around with
Photoshop a little to compare PNG and GIF. PNG always made bigger file sizes
(factor 3+).


Photoshop is known to produce less-than-optimal file sizes for PNG. And
then take into account what Chung says about true color.

What is the recommended way to generate PNGs with reasonable file sizes?


I always filter my PNG files through pngcrush [1] before putting them
online.

[1] http://pmt.sourceforge.net/pngcrush/
Jul 17 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Randy Yates | last post by:
Why is this necessary? The identifiers provide by the programmer are unique, and that is what is important - why map what the user has specified to something else? -- Randy Yates Sony Ericsson...
126
by: ramyach | last post by:
Hi friends, I need to write a parallel code in 'C' on the server that is running SGI Irix 6.5. This server supports MIPS Pro C compiler. I don't have any idea of parallel C languages. I looked...
6
by: Wayne | last post by:
MS IE 6 is not honoring padding-left for images? For example, with img style="padding-left: 20px;" align="right" width="216" height="75" src="g1/filename.gif" I dont see what I am doing...
12
by: Nalaka | last post by:
Hi, I suddenly started getting a lot of errors from html validation (some CSS) so I followed the following instructions to disable it. If you'd rather not have these types of HTML validation...
14
by: Anoop | last post by:
Hi, I am new to this newsgroup and need help in the following questions. 1. I am workin' on a GUI application. Does C# provides Layout Managers the way Java does to design GUI? I know that it...
89
by: Cuthbert | last post by:
After compiling the source code with gcc v.4.1.1, I got a warning message: "/tmp/ccixzSIL.o: In function 'main';ex.c: (.text+0x9a): warning: the 'gets' function is dangerous and should not be...
8
by: =?Utf-8?B?UGF1bCBSZWVk?= | last post by:
Hello, I have an app that was xcopy deployed from an ASP.NET 1.1 W2KServer to a box running ASP.NET 2.0 W2003Server. The app runs fine with the exception of where I use the above method. It...
0
by: dprjessie | last post by:
Hello, I am a Web programmer and I'm working on my first desktop application as a favor for a friend. I'm sure I have a stupid error here, but there is no error being thrown so I can't figure out...
21
by: Peter Duniho | last post by:
On Fri, 18 Jul 2008 07:03:37 -0700, Ben Voigt <rbv@nospam.nospamwrote: I agree whole-heartedly about being closer to Java. But the OP didn't ask about Java. :) I disagree on the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.