Home Tutorial Php Phpgd PHP GD image negative Color

 
 

Share on Google+Share on Google+
PHP GD image negative Color
Posted on: November 12, 2009 at 12:00 AM
Advertisement
This example shows how to set the negative color of an image in php gd.

<?php

function negate($image)

{

if(function_exists('imagefilter'))

{

return imagefilter($image, IMG_FILTER_NEGATE);

}

for($x = 0; $x < imagesx($image); ++$x)

{

for($y = 0; $y < imagesy($image); ++$y)

{

$index = imagecolorat($image, $x, $y);

$rgb = imagecolorsforindex($index);

$color = imagecolorallocate($image, 255 - $rgb['red'], 255 - $rgb['green'], 255 - $rgb['blue']);

imagesetpixel($im, $x, $y, $color);

}

}

return(true);

}

$image = imagecreatefromjpeg('image1.jpg');

if($image && negate($image))

{

echo 'Image successfully converted to negative colors.';

imagejpeg($image, 'image1.jpg', 100);

imagedestroy($image);

}

else

{

echo 'Negative color conversion failed.';

}

?>

After running the program you will get the following output

Advertisement

Related Tags for PHP GD image negative Color:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 12, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com