php-imagine / Imagine

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

GMagick No encode delegate for this image format #732

Closed ausi closed 4 years ago

ausi commented 4 years ago

Issue description

On my system it is not possible to save a GMagick image to a file without a file extension. The Exception No encode delegate for this image format (jpeg) gets thrown.

What's the PHP version you are using?

7.3.13-1+ubuntu16.04.1+deb.sury.org+1

What's the imaging library you are using [gd/imagick/gmagick/any]?

GMagick

What's the imaging library configuration

gmagick version => 2.0.5RC1
GraphicsMagick version => GraphicsMagick 1.4 snapshot-20180922 Q16 http://www.GraphicsMagick.org/

Minimal PHP code to reproduce the error:

$gmagick = new \Gmagick();
$gmagick->newimage(100, 100, (new \GmagickPixel('#ffffff'))->getcolor(false));
$gmagick->setimageformat('jpeg');
$gmagick->writeimage(__DIR__.'/testimage');

How to fix

The GraphicsMagick documentation shows the image format in uppercase ("GIF") and if I replace the 'jpeg' with 'JPEG' in the test code above this fixes the issue for me.

I think we should replace https://github.com/avalanche123/Imagine/blob/3db069bd870f45b5305e7d6bd4e08d45ebb22cef/src/Gmagick/Image.php#L433 with:

$this->gmagick->setimageformat(strtoupper($options['format']));
ausi commented 4 years ago

@mlocati should I provide a pull request for the fix?

mlocati commented 4 years ago

@ausi that'd be great

ausi commented 4 years ago

Pull request: #733