且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP,检测水印图像?

更新时间:2023-02-26 13:35:44

如果根据您的问题,您只想检测带水印的图像,您可以使用以下算法:

If according to your question, you just want to detect the images that are watermarked, you can use the following algorithm:


  • 提取水印图像样本扫描水印图像

  • 逐个像素地存储数组中的第一个像素。逐个像素地扫描每个

  • 图像并存储在一个数组中。每当来自被扫描图像的行矩阵

  • 包含

  • 相同顺序的数组元素时,它很可能是匹配。

  • Extract a sample of the watermarking image Scan the watermark image
  • pixel by pixel and store the first pixels in an array. Scan each
  • image pixel by pixel and store in an array. Whenever a row matrix
  • from the image being scanned contains elements of the array in the
  • same order, it's most likely a match.

代码可能是这样的:

$no_of_pixels = what_you_got;
$matched = 0;
$thumbpixels = array();
$wmark = imagecreatefrompng("watermark.png");
list($width, $height) =  getimagesize("watermark.png");
$tesimage = imagecreatefrompng("test.png");
for($h = 0; $h < $height; $h++){    
    for($w = 0; $w < $width; $w++){
        if(imagecolorsforindex($testimage, imagecolorat($testimage, $w, $h)) == $thumbpixels[0]){
            while($thumbpixels[$i++] === imagecolorsforindex($tesimage, imagecolorat($wmark, $w, $h)) && $no_of_pixels != $matched){
                $matched++;
            }
            if($matched == $no_of_pixels) echo "Voila, we found it!";
        }
    }
}






编辑



只看到你的缩略图示例。如果您只想检测文字,可以尝试 tesseract-ocr PhpOCR

您也可以考虑 PHPSane