Skip to content

[5.x]: Error cropping an SVG that has the preserveAspectRatio attribute #16709

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

Closed
alexroper opened this issue Feb 14, 2025 · 2 comments
Closed
Labels

Comments

@alexroper
Copy link

What happened?

Description

Using Craft's image transform to crop an SVG with the preserveAspectRatio attribute causes an error.

Steps to reproduce

Example SVG that triggers the error:

<svg height="218" preserveAspectRatio="xMidYMid" viewBox="0 0 256 218" width="256"
  xmlns="http://www.w3.org/2000/svg">
  <g fill="#0061ff">
    <path d="m63.9945638 0-63.9945638 40.7712563 63.9945638 40.7712562 64.0054362-40.7712562z"/>
    <path d="m192.000442 0-64.000442 40.7750015 64.000442 40.7750016 64.000443-40.7750016z"/>
    <path d="m0 122.321259 63.9945638 40.771257 64.0054362-40.771257-64.0054362-40.7712559z"/>
    <path d="m192 81.5500031-64 40.7747199 64 40.774719 64-40.774719z"/>
    <path d="m64 176.771256 64.005436 40.771257 63.994564-40.771257-63.994564-40.771256z"/>
  </g>
</svg>

Here is a reduced test case where I'm transforming the SVG asset above:

{% set asset = craft.assets.id(1162).one() %}

{% set thumb = {
  mode: 'crop',
  width: 100,
  height: 100,
} %}

<img src="{{ asset.getUrl(thumb) }}">

Expected behavior

SVG image cropped to 100 x 100 pixels.

Actual behavior

Error message:

This page contains the following errors:

error on line 2 at column 159: Attribute preserveAspectRatio redefined

Below is a rendering of the page up to the first error.

Craft CMS version

Craft Pro 5.6.1

PHP version

8.2.26

Operating system and version

Linux 6.10.14-linuxkit

Database type and version

MySQL 8.0.36

Image driver and version

Imagick 3.7.0 (ImageMagick 6.9.11-60)

Installed plugins and versions

@brandonkelly
Copy link
Member

Thanks for reporting that! Fixed for the next Craft 4 and 5 releases.

@brandonkelly
Copy link
Member

Craft 4.14.6 and 5.6.7 are out with that fix. Thanks again!

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

No branches or pull requests

2 participants