Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- check if image is NOT fully black -- start
- */
- $source_file = $filename;
- $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++)
- {
- // get the rgb value for current pixel
- $rgb = ImageColorAt($im, $i, $j);
- // extract each value for r, g, b
- $r[$i][$j] = ($rgb >> 16) & 0xFF;
- $g[$i][$j] = ($rgb >> 8) & 0xFF;
- $b[$i][$j] = $rgb & 0xFF;
- // count gray pixels (r=g=b)
- 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.";
- }
- /*
- check if image is NOT fully black -- end
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement