PHP: Determine Visually Corrupted Images (yet valid) downloaded via Curl with GD/Imagemagick

前端 未结 4 604
执念已碎
执念已碎 2020-12-10 07:54

I\'m using Curl via Proxies to download images with a scraper I have developed.

Unfortunately, it gets the odd image which looks like these and the last one is compl

4条回答
  •  死守一世寂寞
    2020-12-10 08:18

    found this page when looking for a way to check visually corrupted images like this. Here is a way to solve the problem using bash (anyway, the convert command line can be easily adapted for php or python) :

    convert INPUTFILEPATH -gravity SouthWest -crop 20%x1%   -format %c  -depth 8  histogram:info:- | sed '/^$/d'  | sort -V | head -n 1 | grep fractal | wc -l
    

    It crops a little square in the southwest corner of the picture, then gets the histogram of this picture. If the main color of the histogram has the name "fractal" instead of an rgb color, it means this zone is corrupted and so the output will be 1 and 0 otherwise.

    Hope this helps!

提交回复
热议问题