Home Tutorial Php Phpgd PHP GD image grayscale

 
 

Share on Google+Share on Google+
PHP GD image grayscale
Posted on: November 7, 2009 at 12:00 AM
Advertisement
This example shows how to display that the particular image is grayscale or not in php gd.

<?php

$source_file = "images.jpg";

$im = ImageCreateFromJpeg($source_file);

$imgw = imagesx($im);

$imgh = imagesy($im);

$r = array();

$g = array();

$b = array();

$c = 0;

for ($i=0; $i<$imgw; $i++)

{

for ($j=0; $j<$imgh; $j++)

{

$rgb = ImageColorAt($im, $i, $j);

$r[$i][$j] = ($rgb >> 16) & 0xFF;

$g[$i][$j] = ($rgb >> 8) & 0xFF;

$b[$i][$j] = $rgb & 0xFF;

if ($r[$i][$j] == $g[$i][$j] && $r[$i][$j] == $b[$i][$j])

{

$c++;

}

}

}

if ($c == ($imgw*$imgh))

{

echo "The image is grayscale.";

}

else

{

echo "The image is NOT grayscale.";

}

?>

After running the program you will get the following output

OUTPUT:The image is NOT grayscale
Advertisement

Related Tags for PHP GD image grayscale:


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 7, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com