Skip to content

Quality and other params are ignored with AutoWebP Parameter turned ON #11

Description

@Romanavr

Describe the bug

Before we start: we have a regular CloudFormation stack with Sharp on AWS. It's important that in our case AutoWebPParameter is always enabled(=ON).

So, while doing another image optimization, we noticed that changing the quality does not affect the image file size.
It turns out that this is because the quality does not change at all.

Although we noticed that this works if we call,srcsetWebp for example, but not in the case of srcset.
To add, in our case the extension of the original image is usually JPG or PNG.

Having debugged the converted URL (base64-encoded), we saw that there are "edits" object with "jpeg" edits as a key, where quality and other stuff are defined.
However, my guess is that because it AutoWebPParameter is enabled, we always have WebP in the output, even if we call srcset rather than srcsetWebp.
And it looks like the JPG is just ignored in that case, which makes sense.

{% do asset.setTransform({'quality': 10 }) %}
Example decoded output without WebP:

{
  "bucket": "mybucket",
  "key": "myimage.png",
  "edits": {
    "png": {
      "quality": 10,
      "progressive": false
    },
    "resize": {
      "fit": "cover"
    },
    "sharpen": true
  }
}

{% do asset.setTransform({'quality': 10, 'format': 'webp'}) %}
Example Decoded output with WebP:

{
  "bucket": "mybucket",
  "key": "myimage.png",
  "edits": {
    "webp": {
      "quality": 10
    },
    "resize": {
      "fit": "cover"
    },
    "sharpen": true
  }
}

Perhaps a flag or something like that could be added so that instead of "jpeg", the base64-encoded JWT always has “WebP” for case when expected output is always in WebP?

To reproduce

  1. In your AWS CF stuck turn on AutoWebPParameter parameter.
  2. Call the regular image transform with the changed quality, e.g. 10.
{% set asset = craft.assets.id(123).one() %}
{% do asset.setTransform({'quality': 10 ) %}
...
  1. Do the same, but add format: webP
{% set asset = craft.assets.id(123).one() %}
{% do asset.setTransform({'quality': 10, 'format': 'webp' ) %}
...
  1. See that the first image transform quality is still 100%. The second image transform quality is 10%.

Expected behaviour

In both cases image transform should respect quality param.

Screenshots

Not sure that it would be possible to see difference on the Screenshot
Image

Versions

  • Plugin version: 5.0.7
  • Craft version: 5.7.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions