Cover | Table of Contents | Colophon
|
Name
|
Description
|
Code
|
|---|---|---|
|
Header chunk
|
Global information about the image
|
IHDR
|
|
Palette chunk
|
A palette (optional)
|
PLTE
|
|
Image Data chunk
|
The compressed image data
|
IDAT
|
|
Image End chunk
|
The end-of-file marker
|
http://www.ijg.org).http://www.c-cube.com) and placed in the
public domain. JFIF became the de factostandard
for web JPEGs because of its simplicity. When people talk about a
JPEG web graphic, they are actually referring to a JPEG-encoded data
stream stored in the JFIF file format. In this book we will refer to
JFIFs as JPEGs to reduce confusion, or to further propagate it,
depending on your point of view.http://corp2.unisys.com/LeadStory/lzwfaq.html
ftp://ftp.uu.net/graphics/png/documents/png-1.0-w3c-single.html.gz
ftp://ftp.uu.net:/graphics/png/documents/png-1.0-w3c-single.html.gz#D.Alphachannel-processing
ftp://ds.internic.net/rfc/rfc1951.txt
http://bbs-koi.uniinc.msk.ru/tech1/1994/er_cont/crc.htm
http://www.cdrom.com/pub/mng/
http://www.jpeg.org/
http://www.faqs.org/faqs/jpeg-faq/
http://www.faqs.org/faqs/compression-faq/
http://www.cdrom.com/pub/png/
ALT
attribute, client-side image maps, the USEMAP
attribute, GIF89a animation, image spacing attributes, transparency,
inline PNG/XBM/Progressive JPEG images, the LOWSRC
attribute, borders on image links, alignment tags, and
scaling tags.http://www.apache.org) falls somewhere in
between. Apache takes a modular design approach; it has a very fast,
simple core set of operations that may be extended with other
modules. Whichever web server you are running, its primary function
is the basic capability of handling requests and returning resources.http://www.shemp.net/splashscreen.png would
point at a file in the Portable Network Graphics (PNG) format located
in the web server's root directory. If this URL is requested by
a client (and it exists), the web server determines a MIME type for
the file and sends back an HTTP header to the client. The web server
then reads the data in the file pointed to by the URL and immediately
follows the header with a stream of data from the file.http://www.mozilla.org).<IMG> element or by one of the user
interface options, such as the "Show Images" button on
the navigation bar. This request is made with the GetImage(
) function.<IMG>
tag, because it is very likely that 3.2 will still be the most widely
implemented standard for quite some time. However, we will look at
both the <IMG> and
<OBJECT> forms in this chapter.<IMG> element embeds an image in the
body of a document (it cannot be used in the head
section). The element consists of a start tag without an
end tag, and does not include content as such. It is formed according
to standard HTML syntax, which is to say it should look like this in
its simplest form:<IMG SRC="someimage.png" > # include an inline png
use HTML::Element; # use this module
# Set attributes when creating the element...
my $img = new HTML::Element 'img', src => 'someimage.gif';
# ...or add them later with the attr() method
$img->attr('alt','This is Some Image!');
# Use as_HTML() to print the element as an html tag
print $img->as_HTML;SRC
attribute indicates the
URL of the image. This
can be an absolute or relative address, and it may refer to a file to
be read as data or to a script that is to be run to create the proper
image output. The syntax in either case is the same:<IMG SRC="images/staticfile.gif" > <IMG SRC="cgi-bin/dynamicscript.cgi">
-install
option specified on
the command line to start the browser with the 216 color palette.sub WebSafeColor {
# Returns the closest color in the 216 color web-safe palette.
#
my ($red, $green, $blue) = @_;
my (@returnlist, $max, $hex);
# Find closest value in the 6x6x6 "web-safe" color cube,
# algorithm described below.
#
foreach my $number ($red, $green, $blue) {
LOOP: for ($max = 25; $max < 281; $max += 51) {
if ($number <= $max) {
push @returnlist, ($max - 25);
$hex .= sprintf("%02X", $max - 25);
last LOOP;
}
}
}
return (@returnlist, "#$hex");
}http://www.genome.wi.mit.edu/ftp/pub/software/WWW/
http://www.perl.com/CPAN-local/doc/FAQs/cgi/idiots-guide.html
http://www.perl.apache.org
http://perl.apache.org/tuning
http://horac.ta.jcu.cz/aa/aalib/
http://horac.ta.jcu.cz/aa/aalib/
ALT
< >field of the
<IMG>
< >tag. You can get
the source code for the AA plug-in via the Gimp registry at
http://registry.gimp.org/plugins/AA/
http://sunsite.unc.edu/pub/Linux/libs/graphics
http://www.cpan.org
http://www.cloanto.com/users/mcb/19950127giflzw.html
http://www.opensource.org/osd.html
http://www.gnu.org/copyleft/gpl.html
http://www.opensource.org/bsd-license.html
http://webpages.mr.net/bobz/ttyquake/
use GD will give you access to all of the methods
and constants of the GD::Image, GD::Font, and GD::Polygon classes:use GD will give you access to all of the methods
and constants of the GD::Image, GD::Font, and GD::Polygon classes:# Create a new, empty 50 x 50 pixel image $image = new GD::Image(50, 50) || die "Couldn't create image";
undef on failure.
If the method succeeds, it will return a data structure containing
the decoded GIF data for the image and store it in the given scalar
value. This scalar can only contain one image at a time.of
<SELECT>
< >input fields, which makes
for a slightly clunky interface but simplifies the example for the
purposes of this chapter, as we do not have to check for valid input
from the user. The interface web page is shown in Figure 4.1.
http://www.perl.com. The latest version of
GD.pm should also be available at http://stein.cshl.org/WWW/software/GD/GD.html.
Thomas Boutell's original
C-language version of the libgd library can be found at http://www.boutell.com/gd/gd.html
|
Category
|
Method
|
|---|---|
|
GD Objects
|
GD::Image, GD::Font, GD::Polygon
|
|
GD::Image object creation and saving methods
|
|
Font name
|
Width (pixels)
|
Height (pixels)
|
|---|---|---|
|
gdTinyFont
|
5
|
8
|
|
gdSmallFont
|
6
|
12
|
|
gdMediumBoldFont
|
7
|
13
|
|
gdLargeFont
|
8
|
#!/usr/bin/perl -w
#
# A polygon example that draws simple graphs.
#
use strict;
use GD;
my @polygons; # contains a polygon for each data set
my $max_x = 5; # The number of items in a data set
my $max_y = 100; # The maximum y value
my $x_space = 40; # Pixels between x values
my $width = $max_x * $x_space; # The width of the image in pixels
# An array containing three data sets
#
my @data = ( [ 70, 85, 55, 45, 50 ] ,
[ 25, 33, 22, 5, 40 ],
[ 50, 67, 32, 24, 77 ]);
# Now generate a polygon for each data set by calling the
# createDataSet() function. This funciton will return a
# polygon object and the area of the bounding box of the polygon.
#
my %areas;
my ($poly, $area);
foreach my $dataset (@data) {
($poly, $area) = createDataSet($dataset);
push @polygons, $poly;
$areas{$poly} = $area;
}
# Now create an image and allocate white as the background color
#
my $image = new GD::Image($width-$x_space, $max_y);
my $white = $image->colorAllocate(255, 255, 255);
# Now sort the polygons in order of decreasing area. We will
# plot the graphs with the greatest bounding area first, on the
# assumption that this will minimize the effect of one data set
# being obscured by another, since they will be drawn as filled polygons.
# Note that sorting by the bounding box alone does not guarantee
# that the graphs will be plotted in the right order, but
# it will work for most well-behaved data sets.
#
@polygons = reverse(sort { $areas{$a} <=> $areas{$b}; } @polygons);
# Now draw each polygon. First allocate a random color (note that this
# could be white or the same as another color).
#
my %color; # keep track of the color index of each polygon
foreach my $poly (@polygons) {
$color{$poly} = $image->colorAllocate(rand(255), rand(255), rand(255));
$image->filledPolygon($poly, $color{$poly});
}
# Now go back and stroke each polygon with its color, in case it
# is obscured behind another polygon
#
map {
$image->polygon($_, $color{$_});
} @polygons;
open O, ">graphout.gif"; # open a file
binmode O;
print O $image->gif; # write the image as a GIF
close O;
sub createDataSet {
# Take a reference to an array as an argument and return a
# polygon object and the area of the polygon's bounding box.
#
my $dataset = shift;
my $x = 0;
my $poly = new GD::Polygon;
foreach my $y (@$dataset) {
# translate from origin at upper left corner to
# origin at lower left corner
#
$poly->addPt($x, $max_y - $y);
$x += $x_space;
}
# Close the polygon by adding the following points...
#
$poly->addPt($width, $max_y);
$poly->addPt(0, $max_y);
my ($l, $r, $t, $b) = $poly->bounds;
return ($poly, ($r-$l)*($b-$t));
}use Image::Magick;
$image = Image::Magick->new; # $image is a new image object
undef $image; # destroy an image object
use Image::Magick;
$image = Image::Magick->new; # $image is a new image object
undef $image; # destroy an image object
undef @$image; # delete all images from an object undef $image->[2]; # delete only the third image from a sequence
#/usr/bin/perl -w
use strict;
use Image::Magick;
# $image will be our image object and $status will be the return value
# that we can check for a successful operation
#
my($image, $status);
# Instantiate a new image object
#
$image = Image::Magick->new;
# Read in every image in the image subdirectory whose name starts
# with 'dog' and ends with a .gif extension...
# These will be the frames in an animated sequence, presumably of a dog...
#
$status = $image->Read('images/dog*.gif');
warn "$status" if "$status";
$image->Transparent('#FFFFFF'); # Set white to transparent
$image->Zoom('50%'); # Scale the whole sequence
# Use the 216 web-safe color cube
#
$cube = Image::Magick->new;
$status = $cube->Read('NETSCAPE:');
warn "$status" if "$status";
$image->Map($cube);
# Write the whole sequence out as an animated gif file
#
$status = $image->Set(loop=>0, # loop forever
dispose=>2); # revert to background 'twixt frames
$status = $image->Write("gif:webdog.gif");
warn "$status" if "$status";
# Neatly dispose of our object
#
undef $image;|
Extension
|
Description
|
Multi-Image Files?
|
|---|---|---|
|
GIF, GIF87, GIF89a
|
8-bit color GraphDics Interchange Format
|
|
|
JPEG
|
Joint Photographic Experts Group's compressed 24-bit color JFIF
format
| |
|
MPEG, M2V
|