|
Directories, Files and Images
Part:
1
2
3
(Continued from previous part...)
-
imagecolorallocate -- Allocate a color for an image
-
imagecolorat -- Get the index of the color of a pixel
-
imagecolorexact -- Get the index of the specified color
-
imagecolorsforindex -- Get the colors for an index
-
imagecolorstotal -- Find out the number of colors in an image's palette
-
imagecolortransparent -- Define a color as transparent
-
imagecopy -- Copy part of an image
-
imagecopymerge -- Copy and merge part of an image
-
imagecopyresized -- Copy and resize part of an image
-
imagecreatefromgif -- Create a new image from file or URL
-
imagecreatefromjpeg -- Create a new image from file or URL
-
imagecreatefromwbmp -- Create a new image from file or URL
-
imagedestroy -- Destroy an image
-
imagefill -- Flood fill
-
imagefilledarc -- Draw a partial ellipse and fill it
-
imagefilledrectangle -- Draw a filled rectangle
-
imagefilltoborder -- Flood fill to specific color
-
imagefttext -- Write text to the image using fonts using FreeType 2
-
imagegif -- Output image to browser or file
-
imagejpeg -- Output image to browser or file
-
imageline -- Draw a line
-
imageloadfont -- Load a new font
-
imagepolygon -- Draw a polygon
-
imagerectangle -- Draw a rectangle
-
imagesetpixel -- Set a single pixel
-
imagestring -- Draw a string horizontally
-
imagesx -- Get image width
-
imagesy -- Get image height
-
imagettftext -- Write text to the image using TrueType fonts
-
imagewbmp -- Output image to browser or file
-
jpeg2wbmp -- Convert JPEG image file to WBMP image file
-
png2wbmp -- Convert PNG image file to WBMP image file
ShowPhoto.php - Showing Images in a Directory
To show you how to use functions directories, files, and images, I wrote the following sample program:
<?php # PhotoShow.php
# Copyright (c) 2003 by Dr. Herong Yang, http://www.herongyang.com/
#
#- Get the photo file name
$i = intval($_GET['i']);
$c = 0;
$p = "";
if ($d = opendir(".")) {
while (($f = readdir($d)) != false) {
if (preg_match('/.jpg$/',$f)) {
if ($i==$c) {
$p = $f;
}
$c++;
}
}
closedir($d);
}
#- Build the page
$h = fopen("header.html", "r");
$s = fread($h, filesize("header.html"));
fclose($h);
print "$s\n";
if (strlen($p)>0) {
$i1 = ($i+$c-1) % $c;
$i2 = ($i+$c+1) % $c;
list($width, $height, $type, $attr) = getimagesize($p);
if ($width>700) {
$width = $width/2;
$height = $height/2;
}
print "<center><a href=\"ShowPhoto.php?i=$i1\"><=</a> "
."<a href=\"ShowPhoto.php?i=$i2\">=></a></center>\n"
."<center><img src=\"$p\" border=\"1\" width=\"$width\" "
."height=\"$height\"></center><br\>\n"
."<center><a href=\"ShowPhoto.php?i=$i1\"><=</a> "
."<a href=\"ShowPhoto.php?i=$i2\">=></a></center>\n";
} else {
print "<p>Wrong URL. Please go back to the home page.</p>\n";
}
$h = fopen("footer.html", "r");
$s = fread($h, filesize("footer.html"));
fclose($h);
print "$s\n";
?>
Try it out. It's very easy to use. You can easily customize it to meet your requirements.
Part:
1
2
3
|