Jump to content

Recommended Posts

I was wondering if there is a function to be able to locate images that are all black.  I have almost 6000 images in a directory and don't want to have to go through each and every one to delete the ones that are all black.

 

Any ideas would be appreciated. 

 

Thanks,

 

-JC 

Link to comment
https://forums.phpfreaks.com/topic/105031-solved-find-all-black-images/
Share on other sites

theres a few ways to do it conceptually (all using GD):

a) open image, read each pixel, if one is diff to first (or not black) then it isn't all same (or black)

b) if it's not a true colour image then find the size of the palette using imagecolorstotal and if greater than 1 (and not black), then hey presto

c) if a true colour image, read into memory, convert to palette image with imagetruecolortopalette, then as (b).

*) there's probably others but there's enough to get on with...

 

 

Update: First link now works...

I would have thought that any image that was all one colour would be a very small file compared to images with multiple colours.

 

I'd suggest using the glob() function to generate the array and looking at filesizes less than a few kb ought to quickly show the 'black' images.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.