think-image icon indicating copy to clipboard operation
think-image copied to clipboard

大佬, php8出现数据转换的精度问题了, 能修复一下吗?

Open zjkal opened this issue 2 years ago • 8 comments

大佬, php8出现数据转换的精度问题了, 能修复一下吗? Implicit conversion from float 28.083582089552237 to int loses precision #0 [internal function]: think\initializer\Error->appError(8192, 'Implicit conver...', '...', 359) #1 \vendor\topthink\think-image\src\Image.php(359): imagecopyresampled(Object(GdImage), Object(GdImage), 0.0, 28.083582089552, 0, 0, 128.0, 71.832835820896, 670, 376) #2 \app\service\FileUpload.php(91): think\Image->thumb(128, 128, 2)

zjkal avatar Sep 02 '22 04:09 zjkal

同样问题,2023-07-16 还在

lindaoling avatar Jul 15 '23 16:07 lindaoling

同样问题,2023-07-16 还在

其实已经修复了, 是大佬忘记发版本, 你把composer.json里的版本号改成"dev-master"试试

改完记得composer update

zjkal avatar Jul 16 '23 06:07 zjkal

2023-12-27 日复现,回退到8.0 版本正常

XiaoshengSu avatar Dec 27 '23 08:12 XiaoshengSu

php 8.1下丢失精度修复src/Image.php文件修改imagecopyresampled

            do {
                //创建新图像
                $img = imagecreatetruecolor($width, $height);
                // 调整默认颜色
                $color = imagecolorallocate($img, 255, 255, 255);
                imagefill($img, 0, 0, $color);
                //裁剪
                imagecopyresampled($img, $this->im, intval($posx), intval($posy), intval($x), intval($y), intval($neww), intval($newh), intval($w), intval($h));
                imagedestroy($this->im); //销毁原图
                $this->im = $img;
            } while (!empty($this->gif) && $this->gifNext());

gsmdenis avatar Feb 09 '24 00:02 gsmdenis

同样问题,2024-04-29 还在。php版本8.1

TTC1002335644 avatar Apr 29 '24 12:04 TTC1002335644

同样问题,2024-04-29 还在。php版本8.1

你试试把版本号改成dev-master, 然后update一下, 如果还不行就换别的用吧

zjkal avatar May 04 '24 03:05 zjkal

2024-07-17 ps: 问题还在,dev-master也不行 解决办法:374 行改为 return $this->crop($w, $h, $x, $y, (int) $width, (int) $height); 等大佬更新吧~

justin-xean avatar Jul 17 '24 08:07 justin-xean

@justin-xean 可以使用:https://packagist.org/packages/intervention/image进行重构。。

hulang avatar Aug 07 '24 06:08 hulang