craft-imageoptimize icon indicating copy to clipboard operation
craft-imageoptimize copied to clipboard

Craft 4 & automatically SVG transforms in the CP

Open Romanavr opened this issue 3 years ago • 6 comments

Describe the bug

I noticed a bug that every time when entering any entry in the CP where the SVG image is used, CraftCMS tries to transform it and thus causes an error. StrackTrace errors in this case leads to the plugin (see logs). At the moment, I don't have any transforms for assets. FieldType for images -> just AssetField, not OptimizeField. The image is stored on S3, Sharp is selected as a transformer. Tested on 2 sites with the same version of Craft & plugin - in both cases, SVG images triggers an error

To reproduce

In any entry, add an asset field and upload an image in SVG format Refresh page Check the logs

Expected behaviour

There must be no transformation

Screenshots

Check logs

Versions

  • Plugin version: 4.0.2
  • Craft version: Craft 4.2.3

trace.log <- HERE

Romanavr avatar Sep 19 '22 20:09 Romanavr

You should be able to disable the transformation of SVG images via the OptimizedImages field settings. Does that not work for you?

khalwat avatar Oct 19 '22 19:10 khalwat

@khalwat Thanks for the reply Forgot to add, the error is caused by converting images in the CP panel like miniatures/thumbnails in the entry for the example: https://i.imgur.com/8vIV1dC.png. That's happens only for the SVG images.

Romanavr avatar Oct 19 '22 20:10 Romanavr

Thumbnail transformation is intercepted by EVENT_TRANSFORM_IMAGE and I don't see a way to turn it off for the auto-transforms in the CP

Romanavr avatar Oct 19 '22 20:10 Romanavr

That's a good idea for a feature flag: the ability to disable transforms for CP requests

khalwat avatar Oct 20 '22 01:10 khalwat

@Romanavr shouldn't thumbnails be intercepted by Assets::EVENT_DEFINE_THUMB_URL -> https://github.com/nystudio107/craft-imageoptimize/blob/develop-v4/src/ImageOptimize.php#L314

khalwat avatar Nov 15 '22 21:11 khalwat

@Romanavr shouldn't thumbnails be intercepted by Assets::EVENT_DEFINE_THUMB_URL -> https://github.com/nystudio107/craft-imageoptimize/blob/develop-v4/src/ImageOptimize.php#L314

There is a problem with regular SVG images as well (not thumbnails) According to the strack trace, I see that it looks exactly at this event, not the Assets::EVENT_DEFINE_THUMB_URL

Romanavr avatar Nov 23 '22 12:11 Romanavr