count count > 10 两张不同的图片
var_dump(imagehash::run(‘./1.png', ‘./psb.jpg'));
gethashvalue($src1); $hash2 = $self->gethashvalue($src2); if(strlen($hash1) !== strlen($hash2)) return false; $count = 0; $len = strlen($hash1); for($i = 0; $i run($otherimghash); } if (strlen($imghash) !== strlen($otherimghash)) return false; $count = 0; $len = strlen($imghash); for($i=0;$irate; $img = imagecreatetruecolor($width, $height); list($w, $h) = getimagesize($file); $source = $this->createimg($file); imagecopyresampled($img, $source, 0, 0, 0, 0, $width, $height, $w, $h); $value = $this->gethashvalue($img); imagedestroy($img); return $value; } public function gethashvalue($img){ $width = imagesx($img); $height = imagesy($img); $total = 0; $array = array(); for ($y=0;$y 8 ) & 0xff; if (!is_array($array[$y])){ $array[$y] = array(); } $array[$y][$x] = $gray; $total += $gray; } } $average = intval($total / (64 * $this->rate * $this->rate)); $result = ''; for ($y=0;$ygetfileext($file); if ($ext === 'jpeg') $ext = 'jpg'; $img = null; switch ($ext){ case 'png' : $img = imagecreatefrompng($file);break; case 'jpg' : $img = imagecreatefromjpeg($file);break; case 'gif' : $img = imagecreatefromgif($file); } return $img; } public function getfileext($file){ $infos = explode('.', $file); $ext = strtolower($infos[count($infos) - 1]); return $ext; }}
调用方式如下:
require_once imghash.class.php;$instance = imghash::getinstance();$result = $instance->checkissimilarimg('chenyin/img_3214.png', 'chenyin/img_3212.jpg');
如果$result值为true, 则表明2个图片相似,否则不相似。
http://www.bkjia.com/phpjc/1057474.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/1057474.htmltecharticlephp实现搜索相似图片, 感知哈希算法 count =5 匹配最相似 count 10 两张不同的图片 var_dump(imagehash::run(‘./1.png', ‘./psb.jpg')); phpclass imagehash {...
