LonghornPHP 2026

Voting

: min(six, five)?
(Example: nine)

The Note You're Voting On

mail at kailashnadh dot name
21 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