fanfavorite Posted May 10, 2008 Share Posted May 10, 2008 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 More sharing options...
rarebit Posted May 10, 2008 Share Posted May 10, 2008 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... Link to comment https://forums.phpfreaks.com/topic/105031-solved-find-all-black-images/#findComment-537622 Share on other sites More sharing options...
AndyB Posted May 10, 2008 Share Posted May 10, 2008 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. Link to comment https://forums.phpfreaks.com/topic/105031-solved-find-all-black-images/#findComment-537706 Share on other sites More sharing options...
fanfavorite Posted May 10, 2008 Author Share Posted May 10, 2008 Thank you both! I had a little trouble getting it to work correctly with your method rarebit, however I understand how it would work. The filesize method works great Andy, thanks! I completely forgot about that. Link to comment https://forums.phpfreaks.com/topic/105031-solved-find-all-black-images/#findComment-537750 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.