大佬教程收集整理的这篇文章主要介绍了PHP实现搜索相似图片,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
count < =5="" 匹配最相似="" count=""> 10 两张不同的图片 var_dump(ImageHash::run(‘./1.png',‘./psb.jpg'));
PHP;"> getHashValue($src1); $hash2 = $self->getHashValue($src2); if(strlen($hash1) !== strlen($hash2)) return false; $count = 0; $len = strlen($hash1); for($i = 0; $i < $len;="" $i++)="" if($hash1[$i]="" !="=" $hash2[$i])="" $count++;="" return="" $count=""><= 10="" true="" :="" false;="" }="" public="" function="" getimage($file)="" {="" $extname="pathinfo($file,PATHINFO_EXTENSION);" if(!in_array($extname,['jpg','jpeg','png','gif']))="" exit(self::file_extname_illegal);="" $img="call_user_func('imagecreatefrom'." (="" $extname="=" 'jpg'="" 'jpeg'="" :="" $extname="" ),$file);="" return="" $img;="" }="" public="" function="" gethashvalue($file)="" {="" $w="8;" $h="8;" $img="imagecreatetruecolor($w,$h);" list($src_w,$src_h)="getimagesize($file);" $src="$this-">getImage($file); imagecopyresampled($img,$src,$w,$h,$src_w,$src_h); imagedestroy($src); $total = 0; $array = array(); for( $y = 0; $y < $h;="" $y++)="" {="" for="" ($x="0;" $x="">< $w;="" $x++)="" {="" $gray="(imagecolorat($img,$x,$y)">> 8) & 0xFF; if(!isset($array[$y])) $array[$y] = array(); $array[$y][$x] = $gray; $total += $gray; } } imagedestroy($img); $average = intval($total / ($w * $h * 2)); $hash = ''; for($y = 0; $y < $h;="" $y++)="" {="" for($x="0;" $x="">< $w;="" $x++)="" {="" $hash="" .="($array[$y][$x]">= $average) ? '1' : '0'; } } var_dump($hash); return $hash; } } var_dump(ImageHash::run('./1.png','./psb.jpg')); =>
以上是大佬教程为你收集整理的PHP实现搜索相似图片全部内容,希望文章能够帮你解决PHP实现搜索相似图片所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。