php-imagine / Imagine

PHP Object Oriented image manipulation library
https://imagine.readthedocs.io
Other
4.42k stars 530 forks source link

PHP 8 compatibility. #843

Closed glodov closed 1 year ago

glodov commented 1 year ago

Fix for The error is thrown in the HumHub project:

PHP Deprecated Warning 'yii\base\ErrorException' with message 'Implicit conversion from float-string "42.95454545454545" to int loses precision'

in /www/wwwroot/yta.yaro.info/protected/vendor/imagine/imagine/src/Imagick/Image.php:164

Stack trace:

0 [internal function]: yii\base\ErrorHandler->handleError() #1 /www/wwwroot/yta.yaro.info/protected/vendor/imagine/imagine/src/Imagick/Image.php(164): Imagick->cropImage() #2 /www/wwwroot/yta.yaro.info/protected/humhub/libs/ProfileImage.p...",

ausi commented 1 year ago

How can this error be reproduced? $size and $start should always contain integer values.

glodov commented 1 year ago

How can this error be reproduced? $size and $start should always contain integer values.

I just had it with PHP version 8. It seems some functions send numbers as string values.

ausi commented 1 year ago

I just had it with PHP version 8. It seems some functions send numbers as string values.

I was not able to reproduce that. How does your code in humhub/libs/ProfileImage.p... look like? Maybe the issue has its cause there.

glodov commented 1 year ago

I just had it with PHP version 8. It seems some functions send numbers as string values.

I was not able to reproduce that. How does your code in humhub/libs/ProfileImage.p... look like? Maybe the issue has its cause there.

I found this issue in HumHub project: https://www.humhub.com/. When you try to upload an image to your space and change the size and position it throws an error.

You can also try to pass a string as a number '8.123' or just float the number '8.123'. PHP8 is a strict language by default.

ausi commented 1 year ago

You can also try to pass a string as a number '8.123' or just float the number '8.123'.

I think I see the problem now:

$box = new Box('123.45', '123.45');
$point = new Point('123.45', '123.45');

var_dump($box->getWidth()); // int(123)
var_dump($point->getX()); // string(6) "123.45"

So I think this needs to be fixed in the Point class similar to how it is handled in the Box class: https://github.com/php-imagine/Imagine/blob/c10ea7f80e5b93473e2390515adc3057b85e26a2/src/Image/Box.php#L41-L46

glodov commented 1 year ago

thanks @ausi! @mlocati can you apply the pull request?

mlocati commented 1 year ago

Superseeded by #847