<?
header ("Content-type: image/png");
// This script outputs pixel.
// Syntax:
// <td background=http://www.server.com/pxl.php?r=50&g=50&b=50> </td>
// or like:
// <td background=http://www.server.com/pxl.php?s=pink> </td>
// Numbers are to be from 0 to 255
// To-do: 1) mode for hex numbers
// 2) mode for safe web palette mode
class pxl {
var $r;
var $g;
var $b;
var $pixel;
var $image;
function pxl () {
$this->set_pixel();
}
function set_pixel () {
$this->image=imagecreate(100,100);
//get colors
$this->get_colors();
//it's our pixel
$this->pixel=imagecolorallocate($this->image, $this->r, $this->g, $this->b);
imagefill ( $this->image, 1, 1, $this->pxl);
// send image to browser
imagepng($this->image);
// After sending - destroy image freeing resources imagedestroy($this->image);
}
function get_colors () {
global $r, $g, $b,$s;
// get colors AS IS
$this->r=$r;
$this->g=$g;
$this->b=$b;
// correct a lil
if (!strlen($r)) $this->r=0;
if (!strlen($g)) $this->g=0;
if (!strlen($b)) $this->b=0;
// antihack - say no to negative numbers
$this->r=(int)(abs($r)%255);
$this->g=(int)(abs($g)%255);
$this->b=(int)(abs($b)%255);
if (strlen($s)>0) {$this->setcolors ($s);}
}
function setcolors ($col) {
switch ($col) {
case 'black':
$this->r=0;
$this->g=0;
$this->b=0;
break;
case 'white':
$this->r=255;
$this->g=255;
$this->b=255;
break;
case 'pink':
$this->r=255;
$this->g=0;
$this->b=255;
break;
case 'red':
$this->r=255;
$this->g=0;
$this->b=0;
break;
case 'blue':
$this->r=0;
$this->g=0;
$this->b=255;
break;
default:
$this->r=255;
$this->g=0;
$this->b=255;
}
}
}
$pixel=new pxl;
?>