Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected DecoderException thrown #1400

Open
ADmad opened this issue Oct 27, 2024 · 1 comment
Open

Unexpected DecoderException thrown #1400

ADmad opened this issue Oct 27, 2024 · 1 comment

Comments

@ADmad
Copy link
Contributor

ADmad commented Oct 27, 2024

Describe the bug

DecoderException is thrown when trying to read a heic image created by lib itself. The error only occurs for heic and not for other image types. Also the exception only occurs on Ubuntu 24.04, it does not happen on 22.04, so it's likely an environment issue and not an issue with the lib, but I needed help to figure how to handle it.

The exact error can be seen here:
https://github.com/thephpleague/glide/actions/runs/11540990914/job/32122452702?pr=400#step:5:29

Code Example

use Intervention\Image\Encoders\MediaTypeEncoder;
use Intervention\Image\ImageManager;

$manager = ImageManager::imagick();
$img = $manager->read($manager->create(100, 100)->encode(new MediaTypeEncoder('image/heic'))->toFilePointer());

Expected behavior

No exception to be thrown.

Environment (please complete the following information):

  • PHP Version: PHP 8.3
  • OS: Ubuntu 24.04
  • Intervention Image Version: 3.9.1
  • GD or Imagick: Imagick
@olivervogel
Copy link
Member

olivervogel commented Oct 27, 2024

Thanks for reporting.

This seems to be an issue with Imagemagick/Imagick installed with Ubuntu 24.04. I have extracted the entire process and recreated it using only “native” Imagick calls. This is what Intervention Image does under the hood.

// create
$background = new ImagickPixel('rgba(255, 255, 255, 0)');
$imagick = new Imagick();
$imagick->newImage(100, 100, $background, 'png');
$imagick->setType(Imagick::IMGTYPE_UNDEFINED);
$imagick->setImageType(Imagick::IMGTYPE_UNDEFINED);
$imagick->setColorspace(Imagick::COLORSPACE_SRGB);
$imagick->setImageResolution(96, 96);
$imagick->setImageBackgroundColor($background);
// encode
$imagick->setFormat('HEIC');
$imagick->setImageFormat('HEIC');
$imagick->setCompressionQuality(75);
$imagick->setImageCompressionQuality(75);
$encoded = $imagick->getImagesBlob();
// re-read
$imagick = new Imagick();
$imagick->readImageBlob($encoded);
$this->assertInstanceOf(Imagick::class, $imagick);

You can see that the result of Imagick::getImagesBlob() is an empty string. This then leads to an exception when reading in again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants