XF 2.2 $imageManager GD

Robert9

Well-known member
There is a file (it is there!)

$imageManager = \XF::app()->imageManager();
// icant use imageMagick with XF, because the PECL is not installed normally on this client-server, but imageMagick is here, see later

/** @var \XF\Image\Gd $image */
$image = $imageManager->imageFromFile($tempPathFull);

If this file is a jpg everything is fine; if this is a webp $image is NULL.
 
Last edited:
Seems there is no webp here?
Finally we will have another format till Apple and XF can handle webp?

Code:
<?php

namespace XF\Image;

class Gd extends AbstractDriver
{
    protected $image;

    protected function _imageFromFile($file, $type)
    {
        $this->image = null;

        $image = null;

        // approximately 5 bytes per pixel, times a 1.2 fudge factor, times 2 to support a second copy
        // (such as for rotation via EXIF data)
        $memoryBuffer = ($this->width * $this->height * 5) * 1.2 * 2;
        $availableMemory = \XF::getAvailableMemory();
        if ($availableMemory && $availableMemory < $memoryBuffer)
        {
            \XF::increaseMemoryLimit($memoryBuffer - $availableMemory);
        }

        switch ($type)
        {
            case IMAGETYPE_GIF:
                if (!function_exists('imagecreatefromgif'))
                {
                    return false;
                }
                $image = @imagecreatefromgif($file);
                break;

            case IMAGETYPE_JPEG:
                if (!function_exists('imagecreatefromjpeg'))
                {
                    return false;
                }
                @ini_set('gd.jpeg_ignore_warning', 1); // not default until PHP 7.1
                $image = @imagecreatefromjpeg($file);
                break;

            case IMAGETYPE_PNG:
                if (!function_exists('imagecreatefrompng'))
                {
                    return false;
                }
                $image = @imagecreatefrompng($file);
                break;

            default:
                throw new \InvalidArgumentException("Unknown image type '$type'");
        }
 
I try to add now:

case IMAGETYPE_WEBP:
if (!function_exists('imagecreatefromwebp'))
{
return false;
}
$image = @imagecreatefromwebp($file);
break;
 
I want to kill ...

$function_name = "imagecreatefromwebp";
if ( function_exists($function_name) ) {
echo "$function_name is enabled";
}
else {
echo "$function_name is not enabled";
}

shows that imagecreatefromwebp is available.

But
$image = imagecreatefromwebp($tempPathFull);

doesnt work.
 
Ok. Here we go:

$imageDetails = @getimagesize($tempPathFull);
if ($imageDetails['mime'] == "image/webp") {
$image = imagecreatefromwebp($tempPathFull);
imagejpeg($image, $tempPathFull);
}

I save the webp to jpg, then i can work normal. But funny, funny the picture is now yellow ...
Have read about this somehwere, i use php 7.4. but probably an old GD.
 
Back
Top Bottom