//test if a Jpeg is greyscale or color
function iscolor($pic_adress){
// A Pixel is Greyscale if the r = B = G
//example: colorpixel R=250, G=140 , B=19 Greyscale
Pixel R=110, G= 110, B=110
//we do a check of 10 Pixels to find out if the Picture
is Greyscale
$tocheck = 10;
$iscolor=false;
$temp= getimagesize($pic_adress);
$x= $temp[0];
$y= $temp[1];
$im= imagecreatefromjpeg($pic_adress);
//now check out the Pixels
for( $i = 0 ; $i< $tocheck && !$iscolor;
$i++){
// Here a Random Pixel is chosen
$color = imagecolorat($im,rand(0,$x),rand(0,$y));
//Problem color is an int
//The Hex view on the number is RRGGBB
// Here we get the blue part of the Pixel
$blue = 0x0000ff & $color;
$green = 0x00ff00 & $color;
//The Green part we have to push 8 bits to the right to
get an Compareable result
$green = $green >> 8;
$red =0xff0000 & $color;
//red part needs to be pushed 16 bit
$red = $red >> 16;
// if one of the Pixels isnt Greyscale it breaks an you
know this is a color picture
if( $red!= $green || $green!= $blue){
$iscolor = true;
break;
}
}
return $iscolor;
}
----
Server IP: 217.13.201.10
Probable Submitter: 134.95.113.8
----
Manual Page -- http://www.php.net/manual/en/function.imagecolorat.php
Edit -- https://master
.php.net/note/edit/71444
Del: integrated -- h
ttps://master.php.net/note/delete/71444/integrated
Del: useless -- http
s://master.php.net/note/delete/71444/useless
Del: bad code -- htt
ps://master.php.net/note/delete/71444/bad+code
Del: spam -- https:/
/master.php.net/note/delete/71444/spam
Del: non-english --
https://master.php.net/note/delete/71444/non-english
Del: in docs -- http
s://master.php.net/note/delete/71444/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/71444
Reject -- https://mast
er.php.net/note/reject/71444
Search -- https://
master.php.net/manage/user-notes.php
--
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php
|