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

Setting Format to Auto with Imgix + Craft 4 Not Returning Auto Format Image #357

Closed
itsmattsoria opened this issue Oct 7, 2022 · 9 comments
Labels

Comments

@itsmattsoria
Copy link

Describe the bug

When using Imgix for transforms with ImageOptimize in Craft 4, and setting format to auto for each of the transforms, the images served from Imgix on the front-end are still in the original file format they were uploaded as (in browsers that support modern formats like avif or webp), and I can see in the request that auto=format isn't present in the query string params. It seems like auto=format might not be getting sent to Imgix.

To reproduce

  1. Install ImageOptimize 4.0.2 on Craft 4.2.5.2
  2. Set Imgix as transform method in ImageOptimize
  3. Add an OptimizedImages field with transforms whose format settings is set to "auto" to a volume
  4. Upload jpg images to an asset field set to that volume
  5. Load up a page displaying an image using that field using the OptimizedImages field srcset in a modern browser, like Chrome Version 106.0.5249.103
  6. Check DevTools and see that the image is still being served as a jpg and check the request in the network tab to see the query string params are missing auto=format

Expected behaviour

As described in the OptimizedImages documentation, when format is set to auto for image transforms, Imgix should send back images with auto=format which should serve up modern file formats for browsers that support them (Imgix docs).

Screenshots

Versions

  • Plugin version: 4.0.2
  • Craft version: 4.2.5.2

I can share a testing URL privately via Discord or something if it's helpful.

@khalwat
Copy link
Contributor

khalwat commented Oct 19, 2022

Here's the relevant code:

            // Handle the Imgix auto setting for compression/format
            $autoParams = [];
            if (empty($params['q'])) {
                $autoParams[] = 'compress';
            }
            if (empty($params['fm'])) {
                $autoParams[] = 'format';
            }
            if (!empty($autoParams)) {
                $params['auto'] = implode(',', $autoParams);
            }

I'm a little confused as to why this isn't working as expected, it definitely used to work.

@itsmattsoria
Copy link
Author

You were able to reproduce this then? Not sure either, I'm really out of my element here and not sure I can help with a solution, but was just aware enough to notice it seemed to not be working as expected.

@MamlukiSn
Copy link

@khalwat .

I can also replicate this issue.
When 'Auto' is selected on the OptimizedImages field, the image being output takes the format of the uploaded image, except for jpg which takes the format pjpg. ie (fm=pjpg)

@khalwat
Copy link
Contributor

khalwat commented Nov 15, 2022

@MamlukiSn I'm assuming you're on Craft 4 as well?

@MamlukiSn
Copy link

Yes I'm on craft 4 as well.

@khalwat
Copy link
Contributor

khalwat commented Nov 15, 2022

So I did some testing locally, and it seems to be working as expected.

Here's what I'm getting for the output:

[
    'domain' => 'nystudio107.imgix.net'
    'w' => 142
    'h' => 190
    'auto' => 'compress,format'
    'fit' => 'crop'
    'fp-x' => 0.5
    'fp-y' => 0.5
    'crop' => 'focalpoint'
]

These are the parameters being sent into Imgix, here's an example URL:

https://nystudio107.imgix.net/assets/site/IMG_1961.HEIC.jpeg?auto=compress%2Cformat&crop=focalpoint&domain=nystudio107.imgix.net&fit=crop&fp-x=0.5&fp-y=0.5&h=190&ixlib=php-3.3.1&w=142

It's not passing in the fmt property, but instead is passing in the auto property, as documented here:

https://docs.imgix.com/apis/rendering/auto/auto?_gl=1*1ad8cmb*_gcl_aw*R0NMLjE2Njg1MzU0NTEuQ2p3S0NBaUFqczJiQmhBQ0Vpd0FMVEJXWllMV1B4NDNGZTJVTTVJVUVCblB3VHNQRDBLdkNRSk5ZcVdUT1AwZTJ5RHYyZnM3eF9vZVpSb0NqWElRQXZEX0J3RQ..

When I dump the incoming transform, I see this:

craft\models\ImageTransform#1
(
    [id] => null
    [name] => null
    [handle] => null
    [width] => 142
    [height] => 190
    [format] => null
    [parameterChangeTime] => null
    [mode] => 'crop'
    [position] => 'center-center'
    [interlace] => 'line'
    [quality] => null
    [uid] => null
    [*:transformer] => 'craft\\imagetransforms\\ImageTransformer'
    [yii\base\Model:_errors] => null
    [yii\base\Model:_validators] => null
    [yii\base\Model:_scenario] => 'default'
    [yii\base\Component:_events] => []
    [yii\base\Component:_eventWildcards] => []
    [yii\base\Component:_behaviors] => []
)

so the format and the quality are both null, which then causes the auto format parameters to be set correctly.

What am I missing here?

khalwat added a commit that referenced this issue Nov 15, 2022
@khalwat
Copy link
Contributor

khalwat commented Nov 15, 2022

Okay so I managed to track this down. It was due to this bug fix: #343 which fixes a regression/bug in Craft that caused it to go into an infinite loop and hang if the format was set to null (which used to be valid in Craft 3).

Addressed in: 7d8d147

You can try it now by setting your semver in your composer.json to look like this:

    "nystudio107/craft-imageoptimize": "dev-develop-v4 as 4.0.3”,

Then do a composer clear-cache && composer update

@khalwat khalwat closed this as completed Nov 15, 2022
@itsmattsoria
Copy link
Author

Rad—thanks for tracking this down and addressing this!

@MamlukiSn
Copy link

Thanks. Works great now.

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

3 participants