Skip to content

Resize image error Deprecated Functionality: Implicit conversion from float 114.90625 to int loses precision Magento246

I am getting the following error in PHP version 8.2 on running Deprecated Functionality: Implicit conversion from float 114.90625 to int loses precision in /var/www/html/magento2/vendor/magento/framework/Image/Adapter/Gd2.php on line 422

$newImage = imagecreatetruecolor($dims['frame']['width'], $dims['frame']['height']);

Here’s a modification to ensure that the width and height parameters are cast to integers before being passed to the resize method:

but not working

/**
     * Handle resize image
     * @param $absoluteImageUrl
     * @param $width
     * @param $height
     * @throws Exception
     */
    protected function resizeImage($absoluteImageUrl, $width = 250, $height = null)
    {
        $width = (int) $width; // Cast to integer
        $height = $height !== null ? (int) $height : null; // Cast to integer if not null

        $imageResize = $this->adapterFactory->create();
        try {
            $imageResize->open($absoluteImageUrl);
            $imageResize->constrainOnly(false);
            $imageResize->keepTransparency(true);
            $imageResize->keepFrame(false);
            $imageResize->keepAspectRatio(true);
            $imageResize->resize($width, $height);
            $imageResize->save($absoluteImageUrl);
        } catch (Exception $e) {
            $this->logger->critical($e);
        }
    }

Also, refer to this link but this link is not working.

Resize image error Deprecated Functionality: Implicit conversion from float 114.90625 to int loses precision Magento246