为什么这段 PHP 代码在 php7.1 和 php5.5 中执行不一样
答案:3 悬赏:20 手机版
解决时间 2021-04-29 11:27
- 提问者网友:辞取
- 2021-04-28 10:50
为什么这段 PHP 代码在 php7.1 和 php5.5 中执行不一样
最佳答案
- 五星知识达人网友:鱼忧
- 2021-04-28 11:45
function phash(file)
{
$resource=imagecreatefromstring(file_get_contents($file));
$size=8;
$width = $size + 1;
$heigth = $size;
$resized = imagecreatetruecolor($width, $heigth);
imagecopyresampled($resized, $resource, 0, 0, 0, 0, $width, $heigth, imagesx($resource), imagesy($resource));
$hash = 0;
$one = 1;
for ($y = 0; $y < $heigth; $y++) {
$rgb = imagecolorsforindex($resized, imagecolorat($resized, 0, $y));
$left = floor(($rgb['red'] + $rgb['green'] + $rgb['blue']) / 3);
for ($x = 1; $x < $width; $x++) {
$rgb = imagecolorsforindex($resized, imagecolorat($resized, $x, $y));
$right = floor(($rgb['red'] + $rgb['green'] + $rgb['blue']) / 3);
if ($left > $right) {
$hash |= $one;
}
$left = $right;
$one = $one << 1;
}
}
imagedestroy($resized);
return dechex($hash);
}这样试试呢,希望能帮到你,我刚在后盾网下课,准备吃饭呢,Σ(|||▽||| )
{
$resource=imagecreatefromstring(file_get_contents($file));
$size=8;
$width = $size + 1;
$heigth = $size;
$resized = imagecreatetruecolor($width, $heigth);
imagecopyresampled($resized, $resource, 0, 0, 0, 0, $width, $heigth, imagesx($resource), imagesy($resource));
$hash = 0;
$one = 1;
for ($y = 0; $y < $heigth; $y++) {
$rgb = imagecolorsforindex($resized, imagecolorat($resized, 0, $y));
$left = floor(($rgb['red'] + $rgb['green'] + $rgb['blue']) / 3);
for ($x = 1; $x < $width; $x++) {
$rgb = imagecolorsforindex($resized, imagecolorat($resized, $x, $y));
$right = floor(($rgb['red'] + $rgb['green'] + $rgb['blue']) / 3);
if ($left > $right) {
$hash |= $one;
}
$left = $right;
$one = $one << 1;
}
}
imagedestroy($resized);
return dechex($hash);
}这样试试呢,希望能帮到你,我刚在后盾网下课,准备吃饭呢,Σ(|||▽||| )
全部回答
- 1楼网友:一叶十三刺
- 2021-04-28 12:55
)
- 2楼网友:孤独入客枕
- 2021-04-28 12:03
▽
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯