Home » Php » PHP – Black image detection and Ignore text. How?

PHP – Black image detection and Ignore text. How?

Posted by: admin October 20, 2018 Leave a comment


My security cam has a failure, sometimes at the movement, the first snaps are black. That’s not a really a problem but I was looking for a way to delete those black images via a PHP script.

This one works great with a fully black images:

function check_if_black($src){

   $img = imagecreatefromjpeg($src);
    list($width_orig, $height_orig)=getimagesize($src);
        $rand_width=rand ( 0 , $width_orig );
        $rand_height=rand ( 0 , $height_orig );
        $rgb = imagecolorat($img, $rand_width, $rand_height);
            return "not black";
    return "black";

My snaps have a white timestamp on it. Always in the same position and always with white text. With the code I posted above it says the image isn’t black. But 80% of it is. Is there a way to detect if the snapshot is black and ignores the white timestamp on it?

A sample of a snapshot:
Sample screenshot