scriptz-team

check if image is NOT fully black

Feb 24th, 2015
16,449
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /*
  3. check if image is NOT fully black -- start
  4. */
  5. $source_file = $filename;
  6. $im = ImageCreateFromJpeg($source_file);
  7. $imgw = imagesx($im);
  8. $imgh = imagesy($im);
  9. $r = array();
  10. $g = array();
  11. $b = array();
  12. $c = 0;
  13. for ($i=0; $i<$imgw; $i++)
  14. {
  15.         for ($j=0; $j<$imgh; $j++)
  16.         {
  17.                 // get the rgb value for current pixel
  18.                 $rgb = ImageColorAt($im, $i, $j);
  19.                 // extract each value for r, g, b
  20.                 $r[$i][$j] = ($rgb >> 16) & 0xFF;
  21.                 $g[$i][$j] = ($rgb >> 8) & 0xFF;
  22.                 $b[$i][$j] = $rgb & 0xFF;
  23.                 // count gray pixels (r=g=b)
  24.                 if ($r[$i][$j] == $g[$i][$j] && $r[$i][$j] == $b[$i][$j])
  25.                 {
  26.                         $c++;
  27.                 }
  28.        
  29.         }
  30. }
  31. if ($c == ($imgw*$imgh))
  32. {
  33.         echo "The image is grayscale.";
  34. }
  35. else
  36. {
  37.         echo "The image is NOT grayscale.";
  38. }
  39. /*
  40. check if image is NOT fully black -- end
  41. */
RAW Paste Data