Intervention / image

PHP Image Processing
https://image.intervention.io
MIT License
13.93k stars 1.5k forks source link

"width or height exceeds limit" when converting SVG files #1225

Closed D10f closed 1 year ago

D10f commented 1 year ago

Hi, I'm running the following code:

$faviconRaw = $manager->make($faviconRaw)->resize(32, 32, function ($constraint) {
    $constraint->aspectRatio();
    $constraint->upsize();
})->encode('png');

But the output of that is not the expected image file, but an empty one. The input SVG that causes this is the Vite favicon found at https://vitejs.dev/logo.svg. Other SVG files seem to work perfectly fine, for example others from similar projects found at https://vuejs.org/logo.svg or https://pinia.vuejs.org/logo.svg. I tried encoding into multiple other formats, different variations of the constraints as provided by the third parameter function, different sizes, no sizes at all, etc... Nothing works.

Trying to convert the same file with ImageMagick directly throws the following error:

$ convert vite.svg -format ico vite.ico
convert-im6.q16: width or height exceeds limit `vite.ico' @ error/icon.c/WriteICONImage/939.

However this only seems to happen when converting to ico, other formats work perfectly. Interestingly when resizing the image at the same time it works fine:

$ convert vite.svg -resize 32x32 -format ico vite.ico

Examining the SVG in question there are width and height attributes, 410x404 respectively at the time of this writing. Shrinking those values manually and then trying to convert them again solves the issue but the image is lost due to the viewport shift. Not that a 400x400 image is too large in any case.

PHP version is 8.2 Intervention/image is 2.7

Please let me know if I should provide any other details. Thank you.

D10f commented 1 year ago

Traced this down to an issue with imagemagick itself while handling certain SVGs with complex instructions. Resorted to install Inkscape as a workaround. See here: https://github.com/ImageMagick/ImageMagick/discussions/6831