Chapter 6. Image Formats

2 views
Skip to first unread message

Pterodactyl

unread,
May 5, 2007, 6:15:27 AM5/5/07
to Dive Into PHP 5: The Graphics
Chapter 6. Image Formats

Table of Contents

Overview
JPEG
GIF
PNG
SWF
Other formats

This chapter introduces supported image formats.

Overview

Image file formats provide a standardized method of organizing and
storing image data. [1][http://pterodactyl.l2p.net/book/php5image/page/
bi01.html#wikipedia]

There are dozens of formats, however, only few of them are supported
by PHP. More formats are available for getting image information, less
formats are available for manipulations. Major graphic file formats
are JPEG, PNG, GIF, etc. Some formats are discussed in the following
sections.

Most image file formats are compessed. Image compression is a method
of using algorithms to decrease file size. There are two types of
image file compression algorithms: lossy and lossless. Lossless
compression algorithms reduce file size with no loss in image quality,
although compression ratios are generally weak. Lossy compression
algorithms take advantage of the inherent limitations of the human eye
and discard information that cannot be seen. Most lossy compression
algorithms allow for variable levels of quality (compression) and as
these levels are decreased, file size is also reduced. [1][http://
pterodactyl.l2p.net/book/php5image/page/bi01.html#wikipedia]

Generating image, it is important to send to the browser a special
header with the proper MIME type, e.g. image/png for PNG images, image/
gif for GIF images, and so on.

header('Content-Type: image/png');

JPEG

The JPEG[2] (Joint Photographic Experts Group) image files are a lossy
format. The JPEG format supports 8-bit per color - red, green, and
blue, for 24-bit total - and produces relatively small file sizes.
Fortunately, the compression in most cases does not detract noticeably
from the image. [1][http://pterodactyl.l2p.net/book/php5image/page/
bi01.html#wikipedia
]
[Warning][http://pterodactyl.l2p.net/images/docbook/warning.png]
Warning

JPEG files do suffer generational degradation when repeatedly edited
and saved. [1][http://pterodactyl.l2p.net/book/php5image/page/
bi01.html#wikipedia]

JPEG are usually used to store photographic or other images with many
colors or gradations of color. This format is not suitable for line
drawings, text, or solid blocks of color. [10][http://
pterodactyl.l2p.net/book/php5image/page/
bi01.html#php.mysql.web.development]

The common filename extension is .jpg. MIME type is image/jpeg.

GIF

GIF[3] (Graphic Interchange Format) is limited to an 8-bit palette, or
256 colors. This makes the GIF format suitable for storing graphics
with relatively few colors such as simple diagrams, shapes and cartoon
style images. The GIF format supports animation and is still widely
used to provide image animation effects. It also uses a lossless
compression that is more effective when large areas have a single
color, and ineffective for detailed images or dithered images. [1]
[http://pterodactyl.l2p.net/book/php5image/page/bi01.html#wikipedia]
[Note] Note

The LZW compression algorithm used by GIF was subject to a patent
owned by UNISYS (expired in 2003 in USA and in 2004 in Europe and
Asia), so GIF was limited supported by PHP for several years before
2005. [8][http://pterodactyl.l2p.net/book/php5image/page/
bi01.html#beginning.php4][10][http://pterodactyl.l2p.net/book/
php5image/page/bi01.html#php.mysql.web.development]

The filename extension is .gif. MIME type is image/gif.

PNG

The PNG[4] (Portable Network Graphics) file format is regarded and was
made as the free and open-source successor to the GIF file format (see
the section called "GIF" for details). The lossless PNG file format
supports true color (16 million colors) whereas the GIF file format
only allows 256 colors. [1][http://pterodactyl.l2p.net/book/php5image/
page/bi01.html#wikipedia]

PNG excels when the image has large areas of uniform color, i.e it
works best with images that contain text, lines, and large blocks of
color (such as headings, website buttons, cartoons, illustrations,
etc.). The PNG format is best suited for editing pictures, and the
lossy formats like JPEG (see the section called "JPEG") are best for
final distribution of photographic-type images because of smaller file
size. [1][http://pterodactyl.l2p.net/book/php5image/page/
bi01.html#wikipedia][8][http://pterodactyl.l2p.net/book/php5image/page/
bi01.html#beginning.php4][10][http://pterodactyl.l2p.net/book/
php5image/page/bi01.html#php.mysql.web.development]

PNG supports such features as transparency, gamma correction, and two-
dimensional interlacing, but animanion. [10][http://
pterodactyl.l2p.net/book/php5image/page/
bi01.html#php.mysql.web.development]

The filename extension is .png. MIME type is image/png.

SWF

SWF[5] (Small Web Format as well as Shockwave Flash) is a proprietary
vector graphics file format produced by the Flash software from Adobe
(formerly Macromedia). Intended to be small enough for publication on
the web, SWF files can contain animations or applets of varying
degrees of interactivity and function. [1][http://pterodactyl.l2p.net/
book/php5image/page/bi01.html#wikipedia]

Originally limited to presenting vector based objects and images in a
simple sequential manner, the newer versions of the format allow
audio, video and many different possible forms of interaction with the
end user. [1][http://pterodactyl.l2p.net/book/php5image/page/
bi01.html#wikipedia]

Although a full specification of SWF is available, it is not an open
format, as implementing software that plays the format is disallowed
by the license. Implementing software which creates SWF files,
however, is permitted, on the condition that the resulting files
render [error free in the latest publicly available version of Adobe
Flash Player]. [1][http://pterodactyl.l2p.net/book/php5image/page/
bi01.html#wikipedia]

The filename extension is .swf. MIME type is application/x-shockwave-
flash.

Other formats

Other supported formats are not in wide use.

WBMP (Wireless Bitmap). Monochrome graphics file format optimized for
mobile computing devices. [1][http://pterodactyl.l2p.net/book/
php5image/page/bi01.html#wikipedia]

XBM (X BitMap). ASCII monochrome image format, is used by X Window
System for storing cursor and icon bitmaps. [1][http://
pterodactyl.l2p.net/book/php5image/page/bi01.html#wikipedia]

PSD (Photoshop Document). Stores an image as a set of layers,
including text, masks, opacity, blend modes, color channels, alpha
channels, clipping paths, and duotone settings. [1][http://
pterodactyl.l2p.net/book/php5image/page/bi01.html#wikipedia]

BMP (bitmap). Bitmapped graphics format used internally by the
Microsoft Windows graphics subsystem, and used commonly as a simple
graphics file format on that platform. [1][http://pterodactyl.l2p.net/
book/php5image/page/bi01.html#wikipedia]

TIFF (Tagged Image File Format). File format for mainly storing
images, including photographs and line art. TIFF is used extensively
for traditional print graphics. Lossy and lossless compression
available, but many programs only support a subset of available
options. [1][http://pterodactyl.l2p.net/book/php5image/page/
bi01.html#wikipedia]

JP2/JPC/JPX. Stand for JPEG 2000 which is an advanced JPEG format. [1]
[http://pterodactyl.l2p.net/book/php5image/page/bi01.html#wikipedia]

JB2 (JBIG2). Format for bi-level (black/white) image compression that
offers significant advantages over other compression formats. [11]
[http://pterodactyl.l2p.net/book/php5image/page/
bi01.html#jbig2.development]

IFF (Interchange File Format). Generic file format in order to ease
transfer of data between software products produced by different
companies. IFF files do not have any common extension. Most files
with .iff extension are in fact ILBM files, wrongly named so because
they are most common IFF files. [1][http://pterodactyl.l2p.net/book/
php5image/page/bi01.html#wikipedia]

SWC. Format used by Macromedia Flash 8 for compiled components
protects source code by putting a layer of obfuscation between
component developers and component consumers. [12][http://
pterodactyl.l2p.net/book/php5image/page/bi01.html#exploring.flash8]

[2] pronounced "jay-peg" [1][http://pterodactyl.l2p.net/book/php5image/
page/bi01.html#wikipedia]

[3] pronounced like the peanut butter brand, "Jif", with a soft "g" [1]
[http://pterodactyl.l2p.net/book/php5image/page/bi01.html#wikipedia]

[4] pronounced "ping", but can be spoken "P-N-G" to avoid confusion
with network tool ping [1][http://pterodactyl.l2p.net/book/php5image/
page/bi01.html#wikipedia]

[5] pronounced "S-W-F" (with each letter being pronounced
individually), but some people prefer to pronounce it as "swiff" [1]
[http://pterodactyl.l2p.net/book/php5image/page/bi01.html#wikipedia]

Reply all
Reply to author
Forward
0 new messages