|
|
|
<?
/////////////////////////////////////////////////////////////////////////
//
// counter.php - implements a simple Counter
//
// Author: Claus Radloff
//
// Description:
// The counter in this file can count multiple counters. Therefore
// every counter gets it´s own identifier.
// The Fore- and Backgroundcolor and the number of digits are
// defined, but can be overwritten. Fore- and Backgroundcolor may
// be transparent as well.
// The Parameters are passed in the URL.
// Some Examples:
// simple counter:
// <img src="counter.php?Identifier=Test">
//
// Counter with red background
// <img src="counter.php?Identifier=Test&BGColor=255+0+0">
// or:
// <img src="counter.php?Identifier=Test&BGColor=red">
//
// Counter with red background, green foreground and 4 digits
// <img src="counter.php?Identifier=Test&BGColor=255+0+0&FGColor=0+255+0&Length=4">
// or:
// <img src="counter.php?Identifier=Test&BGColor=red&FGColor=green&Length=4">
//
// Counter with transparent background and red foreground
// <img src="counter.php?Identifier=Test&BGColor=transparent&FGColor=red">
//
Header( "Content-type: image/gif");
require( "colors.php");
// Load the gd-library
// under Windooze use this one
// dl("php3_gd.dll");
// under UNIX use this one
dl( "php3_gd.so");
// some default-values
$Font = 5;
$BGColor = GetColor( "black");
$BGTrans = False;
$FGColor = GetColor( "white");
$FGTrans = False;
$Length = 7;
// get environment
$query_string = getenv( "QUERY_STRING");
// parse environment
// split query-string
$env_array = split( "&", $query_string);
// split in key=value and convert %XX
while (list($key, $val) = each($env_array))
{
// split
list($name, $wert) = split( "=", $val);
// replace %XX by character
$name = urldecode($name);
$wert = urldecode($wert);
// write to $cgivars
$CGIVars[$name] = $wert;
}
// eventually replace the default-values by the given parameters
if ($CGIVars[ "BGColor"])
{
if (ereg( "([0-9]*) ([0-9]*) ([0-9]*)", $CGIVars[ "BGColor"], $tmp))
{
$BGColor[ "red"] = $tmp[1];
$BGColor[ "green"] = $tmp[2];
$BGColor[ "blue"] = $tmp[3];
}
else if (eregi( "transparent", $CGIVars[ "BGColor"]))
{
$BGTrans = True;
}
else
{
$BGColor = GetColor($CGIVars[ "BGColor"]);
}
}
if ($CGIVars[ "FGColor"])
{
if (ereg( "([0-9]*) ([0-9]*) ([0-9]*)", $CGIVars[ "FGColor"], $tmp))
{
$FGColor[ "red"] = $tmp[1];
$FGColor[ "green"] = $tmp[2];
$FGColor[ "blue"] = $tmp[3];
}
else if (eregi( "transparent", $CGIVars[ "FGColor"]))
{
$FGTrans = True;
}
else
{
$FGColor = GetColor($CGIVars[ "FGColor"]);
}
}
if ($CGIVars[ "Length"])
{
$Length = $CGIVars[ "Length"];
}
// calculate size of image
$SizeX = $Length * 13;
$SizeY = 16;
// read counter-file
if (file_exists( "counter.txt"))
{
$fp = fopen( "counter.txt", "rt");
while ($Line = fgets($fp, 999))
{
// split lines into identifier/counter
if (ereg( "([^ ]*) *([0-9]*)", $Line, $tmp))
{
$CArr[ "$tmp[1]"] = $tmp[2];
}
}
// close file
fclose($fp);
// get counter
$Counter = $CArr[$CGIVars[ "Identifier"]];
$Counter += 1;
$CArr[$CGIVars[ "Identifier"]] = $Counter;
}
else
{
// the new counter is initialized with 1
$CArr[$CGIVars[ "Identifier"]] = 1;
$Counter = 1;
}
// write counter file
$fp = fopen( "counter.txt", "wt");
// output array elements
reset($CArr);
while (list($Key, $Value) = each($CArr))
{
$tmp = sprintf( "%s %d\n", $Key, $Value);
fwrite($fp, $tmp);
}
// close file
fclose($fp);
// Counter mit führenden Nullen auffüllen
// fill counter with leading 0´s
$Counter = sprintf( "%0".$Length. "d", $Counter);
// create image
$img = ImageCreate($SizeX + 4, $SizeY + 4);
// use interlace
ImageInterlace($img, 1);
// transparent color for separators
$trans = ImageColorAllocate($img, 1, 1, 1);
ImageColorTransparent($img, $trans);
// fill background
if ($BGTrans)
{
ImageFill($img, 1, 1, $trans);
}
else
{
$col = ImageColorAllocate($img, $BGColor[ "red"], $BGColor[ "green"],
$BGColor[ "blue"]);
ImageFill($img, 1, 1, $col);
}
// output digits
if ($FGTrans)
{
$col = $trans;
}
else
{
$col = ImageColorAllocate($img, $FGColor[ "red"], $FGColor[ "green"],
$FGColor[ "blue"]);
}
$PosX = 0;
for ($i = 1; $i <= strlen($Counter); $i++)
{
ImageString($img, $Font, $PosX + 3, 2 + $i % 2,
substr($Counter, $i - 1, 1), $col);
if ($i != 1)
{
// draw separator
ImageLine($img, $PosX, 0, $PosX, $SizeY + 4, $trans);
}
$PosX += 13;
}
// output image
ImageGif($img);
ImageDestroy($img);
?> |
|
| This is a script that list all image files on a given directory, and displays
the thumbnails nicely formated within an HTML table. It also make use of
JavScript to open pop up windows when the users want to see the full photo. Categories : Graphics, PHP, Complete Programs, Java Script | | | This is a simple photo gallery that reads the image files from multiple directories, and generates a web page styled with CSS1. It opens single auto window to view and print a given image.
Categories : Graphics, Filesystem, PHP, Complete Programs | | | Automatic banner rotation. Randomly selects a banner for display. Categories : Graphics, PHP, Complete Programs | | | Create Thumbnails - resize an image - jpeg, jpg, gif, png to the specifed width and height in proportion without loosing out on pixcel quality. Categories : PHP, GD image library, Graphics | | | phpAds, a complete banner and ad management system with detailled tracking and stats. Categories : MySQL, Complete Programs, Ecommerce, PHP, Databases | | | Point and Click Interface ala MS Access for creating SQL statements. Categories : MySQL, Complete Programs, General SQL, PHP, Databases | | | Accepts a database & hostname from a user and then HTTP username and password. Uses this to connect to a MySQL database. Produces a form based on the tables it finds there to allow the user to do SELECTs, INSERTs, and DELETEs. Categories : Databases, PHP, MySQL, Complete Programs | | | Searches through a local INN server's discussions Categories : Search, Complete Programs, PHP | | | Parses HTTP_USER_AGENT so that you can customize your site to different browsers Categories : HTML, PHP, Complete Programs | | | Random Image Display Categories : PHP, Filesystem, Graphics, HTML and PHP | | | PHP Email image generator - hide your email from bots - using the GD Library Categories : PHP, Graphics, GD image library, Beginner Guides | | | File Explorer, browse, upload, download and edit your web site files with only a browser and a HTTP connection. Categories : Complete Programs, Content Management, Filesystem, PHP | | | PHPCatalog Categories : Ecommerce, PHP, Complete Programs | | | GuestBook Light - a plug and play application for any website. Categories : PHP, Complete Programs, Filesystem, Sessions | | | PHP Round Clock - Must have Gif support to use this. Categories : PHP, Date Time, Graphics | |
| | | | Supreme Creature wrote : 159
I can`t find this "gd-library" from anywhere, can anybody
direct me to it?
| | | | Sjon wrote : 160
And where`s that colors.php script then...
Please provide me with an url or something...
Thanx, Sjon.
| | | | Claus Radloff wrote : 202
The gd-library is part of the binary distributions of PHP (at least
under Windows). It will be built, when compiling the source
distribution, if you have installed the gdlib, which should be
part of the most Linux distributions.
The Colors script is available here in the section graphics and
is titled `Definition of Colornames`
Regards
Claus
| | | | mator wrote :268
where the $%^& workin` example?
| |
|
|
|