Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: How to detect if a jpeg is completely black (no image)?

Tags:

php

gd

I built a community website where the users upload their photo and they can crop the thumbnail, ala Facebook to be clear.

But for some reason some of them generate a blank (actually black jpeg thumbnail).

I tried different solutions but it sounds like this is happening with big images or maybe in computers where JS is not enabled? I don't know...

Bottom line, since the number of users with this is very tiny, I was thinking of creating a patch: detect when the user generates a blank jpeg.Then I would be able to warn them.

Do you know how to do it?

like image 643
Francesco Avatar asked Jan 31 '11 15:01

Francesco


1 Answers

Resize it to a 1x1 PX image. Then check if the one pixel is black. Not perfect, but if there is a significant amount of non black in the original, that 1px will not be black. The benefit is that it will be fast.

like image 52
profitphp Avatar answered Sep 23 '22 02:09

profitphp