PHP 8.5.0 Alpha 4 available for testing

Voting

: two plus two?
(Example: nine)

The Note You're Voting On

mail at kailashnadh dot name
20 years ago
This nifty function will produce the negative of a given image!

<?php

/********************************

Code by Kailash Nadh
http://kailashnadh.name

usage:
img2neg("my_pic.jpg");

*********************************/

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));

// 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);
}

?>

<< Back to user notes page

To Top