Here's a neat piece of PHP code that'll convert an image into its negative..

Download the zip (with the donkey kong pic
)

CODE:
function img2neg($pic) {
header("Content-type: image/jpeg");
$source=imagecreatefromjpeg($pic); // Source
$width=imagesx($source); $height=imagesy($source);
$im = imagecreatetruecolor($width, $height); // Our negative img in the making
for($y=0; $y < $height; $y++) {
for($x=0; $x < $width; $x++) {
$colors=imagecolorsforindex($source, imagecolorat($source, $x,$y)); // Extract the pixel color
// this is what makes the colors negative
$r=255-$colors['red'];
$g=255-$colors['green'];
$b=255-$colors['blue'];
$test=imagecolorallocate($im, $r,$g,$b);
imagesetpixel($im,$x, $y, $test);
}
}
imagejpeg($im);
imagedestroy($im);
}
function img2neg($pic) {
header("Content-type: image/jpeg");
$source=imagecreatefromjpeg($pic); // Source
$width=imagesx($source); $height=imagesy($source);
$im = imagecreatetruecolor($width, $height); // Our negative img in the making
for($y=0; $y < $height; $y++) {
for($x=0; $x < $width; $x++) {
$colors=imagecolorsforindex($source, imagecolorat($source, $x,$y)); // Extract the pixel color
// this is what makes the colors negative
$r=255-$colors['red'];
$g=255-$colors['green'];
$b=255-$colors['blue'];
$test=imagecolorallocate($im, $r,$g,$b);
imagesetpixel($im,$x, $y, $test);
}
}
imagejpeg($im);
imagedestroy($im);
}
Download the zip (with the donkey kong pic

on April 30, 2006, 5:25 pm
btw, its a good utility we were looking for.
( Reply to this comment )