spacecatninja / craft-imager-x

Image transforms, optimizations and manipulations for your Craft CMS site.
Other
26 stars 16 forks source link

DivisionByZeroError with AVIF image formats (Craft 3) #164

Closed jamesmacwhite closed 2 years ago

jamesmacwhite commented 2 years ago

I'm submitting a...

Steps to reproduce

  1. Upload an AVIF image format
  2. Use the AVIF image on a Craft entry
  3. Transform the image with Imager-X
  4. Observe error when trying to get the width/height of the image.

Description

Imager-X appears to not be able to calculate the width/height of a AVIF image format when uploaded. AVIF image support was added in Craft CMS in 3.7.26 and Imgix does appear to support the image format as a transform, but the Imager-X plugin itself seems to throw a DivisionByZeroError when an AVIF image format is used on the front end. The error indicates it cannot get the width/height numeric values for the calculation on line 93 here: https://github.com/spacecatninja/craft-imager-x/blob/v3/src/models/ImgixTransformedImageModel.php#L93

The situation that led to this was a user happened to right click, save as on a image on the front end that was an AVIF, uploaded this into Craft then attempted to use it on the front end in the AVIF format. Imager-X then threw this error, using a more common format like JPG works fine as expected.

There's a couple of options I guess,

  1. Imager-X handling AVIF or being more defensive on the line that causes a DivisionByZero error
  2. Blocking AVIF image from being uploaded (although Craft CMS itself does support it by the looks of it)

Displayed errors, stack trace, relevant logs

Full stack trace can be viewed here

https://sentry.io/share/issue/f9a6a23b8daa4df0b02cc1e58bb7c266

DivisionByZeroError: Division by zero
#44 /vendor/spacecatninja/imager-x/src/models/ImgixTransformedImageModel.php(93): spacecatninja\imagerx\models\ImgixTransformedImageModel::__construct
#43 /vendor/spacecatninja/imager-x/src/transformers/ImgixTransformer.php(116): spacecatninja\imagerx\transformers\ImgixTransformer::getTransformedImage
#42 /vendor/spacecatninja/imager-x/src/transformers/ImgixTransformer.php(67): spacecatninja\imagerx\transformers\ImgixTransformer::transform
#41 /vendor/spacecatninja/imager-x/src/services/ImagerService.php(472): spacecatninja\imagerx\services\ImagerService::transformImage
#40 /vendor/spacecatninja/imager-x/src/variables/ImagerVariable.php(38): spacecatninja\imagerx\variables\ImagerVariable::transformImage
#39 /vendor/twig/twig/src/Extension/CoreExtension.php(1566): twig_get_attribute
#38 /vendor/craftcms/cms/src/helpers/Template.php(106): craft\helpers\Template::attribute
#37 /storage/runtime/compiled_templates/f2/f2483a9a9c9c1802cd3ab236ba449166b17bfef7edfba3e5beb347402358e420.php(76): __TwigTemplate_fce8e8425529e699d90e21fcb1cb3f38e621ec4fadd9dd93f17aff0d3d2c2ef5::macro_imageTransformAny
#36 /vendor/twig/twig/src/Extension/CoreExtension.php(1169): twig_call_macro
#35 /storage/runtime/compiled_templates/f2/f2483a9a9c9c1802cd3ab236ba449166b17bfef7edfba3e5beb347402358e420.php(123): __TwigTemplate_fce8e8425529e699d90e21fcb1cb3f38e621ec4fadd9dd93f17aff0d3d2c2ef5::macro_sized
#34 /vendor/twig/twig/src/Extension/CoreExtension.php(1169): twig_call_macro
#33 /storage/runtime/compiled_templates/a8/a8985cbb3be3d6b92cff87da898702b055b74f85a5d98cf4444e5a9e6e308df1.php(151): __TwigTemplate_9b76c1cf2ea42ffae0783620fa4383303a50a951e3c8d295620c358e7465aeb9::block_content
#32 /vendor/twig/twig/src/Template.php(182): Twig\Template::displayBlock
#31 /storage/runtime/compiled_templates/b0/b0ce4732d8b36b55505c00a46084f9fe7842e292f5891eecc7d8a7d190a8db63.php(569): __TwigTemplate_7cd103494f1a87296fdec4eb34e69d1a19986803e1496e6e7b07d1511f89b209::block_fullPage
#30 /vendor/twig/twig/src/Template.php(182): Twig\Template::displayBlock
#29 /storage/runtime/compiled_templates/b0/b0ce4732d8b36b55505c00a46084f9fe7842e292f5891eecc7d8a7d190a8db63.php(416): __TwigTemplate_7cd103494f1a87296fdec4eb34e69d1a19986803e1496e6e7b07d1511f89b209::doDisplay
#28 /vendor/twig/twig/src/Template.php(405): Twig\Template::displayWithErrorHandling
#27 /vendor/twig/twig/src/Template.php(378): Twig\Template::display
#26 /storage/runtime/compiled_templates/a8/a8985cbb3be3d6b92cff87da898702b055b74f85a5d98cf4444e5a9e6e308df1.php(96): __TwigTemplate_9b76c1cf2ea42ffae0783620fa4383303a50a951e3c8d295620c358e7465aeb9::doDisplay
#25 /vendor/twig/twig/src/Template.php(405): Twig\Template::displayWithErrorHandling
#24 /vendor/twig/twig/src/Template.php(378): Twig\Template::display
#23 /vendor/twig/twig/src/Template.php(390): Twig\Template::render
#22 /vendor/twig/twig/src/TemplateWrapper.php(45): Twig\TemplateWrapper::render
#21 /vendor/twig/twig/src/Environment.php(318): Twig\Environment::render
#20 /vendor/craftcms/cms/src/web/View.php(408): craft\web\View::renderTemplate
#19 /vendor/craftcms/cms/src/web/View.php(461): craft\web\View::renderPageTemplate
#18 /vendor/craftcms/cms/src/web/Controller.php(201): craft\web\Controller::renderTemplate
#17 /vendor/craftcms/cms/src/controllers/TemplatesController.php(102): craft\controllers\TemplatesController::actionRender
#16 [internal](0): call_user_func_array
#15 /vendor/yiisoft/yii2/base/InlineAction.php(57): yii\base\InlineAction::runWithParams
#14 /vendor/yiisoft/yii2/base/Controller.php(178): yii\base\Controller::runAction
#13 /vendor/yiisoft/yii2/base/Module.php(552): yii\base\Module::runAction
#12 /vendor/craftcms/cms/src/web/Application.php(293): craft\web\Application::runAction
#11 /vendor/yiisoft/yii2/web/Application.php(103): yii\web\Application::handleRequest
#10 /vendor/craftcms/cms/src/web/Application.php(278): craft\web\Application::handleRequest
#9 /vendor/craftcms/cms/src/controllers/PreviewController.php(174): craft\controllers\PreviewController::actionPreview
#8 [internal](0): call_user_func_array
#7 /vendor/yiisoft/yii2/base/InlineAction.php(57): yii\base\InlineAction::runWithParams
#6 /vendor/yiisoft/yii2/base/Controller.php(178): yii\base\Controller::runAction
#5 /vendor/yiisoft/yii2/base/Module.php(552): yii\base\Module::runAction
#4 /vendor/craftcms/cms/src/web/Application.php(293): craft\web\Application::runAction
#3 /vendor/yiisoft/yii2/web/Application.php(103): yii\web\Application::handleRequest
#2 /vendor/craftcms/cms/src/web/Application.php(278): craft\web\Application::handleRequest
#1 /vendor/yiisoft/yii2/base/Application.php(384): yii\base\Application::run
#0 /index.php(12): null

Additional info

aelvan commented 2 years ago

Thanks for reporting!

This is caused by the same underlying issue that caused #157 (and for reference it's due to https://externals.io/message/116543). PHP's utility method for extracting information about images doesn't work, the image will probably have to be loaded with the image driver (GD or Imagick), for the size to be determined. There's a straight forward fix, but I'll do some additional testing because I suspect it'll impact performance somewhat. Maybe better to use the information stored on the asset, if the source image is an asset, and then use the loading route only for external images.

jamesmacwhite commented 2 years ago

Thanks for your prompt reply!

The easy workaround at the moment is don't use AVIF as the source image, although Craft CMS allows it and as far as I can tell you can't easily remove/restrict extensions, only add additional ones or custom kinds which you'd then need to update any asset field, I did consider just blocking AVIF uploads for assets for now, but I don't think that is easily doable through the Craft CMS config from what I can tell.

Although if there's a workable and performant fix in Imager-X that would be even better!

aelvan commented 2 years ago

I will fix it one way or another for Imager, just need to test a little bit on what the best approach is.

The only native thing that would help in this regard is the extraFileKinds general config setting, ie:

        'extraFileKinds' => [
            'websafeimage' => [
                'label' => 'Web Safe Image',
                'extensions' => ['gif', 'jpg', 'jpeg', 'png'],
            ],
        ],

Which will only allow these extensions to be added to a field. But as you say, you'd have to go through and edit all your fields, and the client would still be able to upload avifs to assets, so not perfect.

We created a plugin for adding restrictions to asset uploads that we use internally at my agency, so it's definately possible to make. But it'd rather belong in core.

jamesmacwhite commented 2 years ago

Thank you for acknowledging and committing to a fix. I will just inform users for now to avoid anything AVIF to be honest, I agree anything around restricting file types should be in core, I could also likely do a similar thing like you've done with adding some custom handling in a module.

Main thing has been to understand and report the issue, as we've seen it a few times now in Sentry, so good to flag it and start the process on working on a fix.

aelvan commented 2 years ago

Various steps to amend this issue was added to 4.1.3 and 3.6.3. If the size of a transformed image can't be calculated (the image is of a format that getimagesize can't read, and the transform itself is not enough to calculate the size), the following three steps will be tried on the source image:

1) Use getimagesize on the source image. 2) If that fails, use the width and height of the source asset, if an asset was passed. 3) If that fails, the source image is loaded with Imagine and the image driver tries to get the size (which will succeed if the driver has support for the format). The result is cached in the data cache to ease the pain of the performance hit.

At this stage, the probablility that we don't have a size to work with, is really slim.

jamesmacwhite commented 2 years ago

Amazing work! Thank you for your efforts!

jamesmacwhite commented 2 years ago

FYI. I tested Imager-X 3.6.3.1 with an AVIF image and it still errors with the DivisionByZero error, here' the full stack trace if it helps where our website is failing at each part of the plugin.

DivisionByZeroError: Division by zero in /srv/app/nttmcoll-staging/htdocs/vendor/spacecatninja/imager-x/src/models/ImgixTransformedImageModel.php:94
Stack trace:
#0 /srv/app/nttmcoll-staging/htdocs/vendor/spacecatninja/imager-x/src/transformers/ImgixTransformer.php(116): spacecatninja\imagerx\models\ImgixTransformedImageModel->__construct('https://notting...', Object(craft\elements\Asset), Array, Object(spacecatninja\imagerx\models\ImgixSettings))
#1 /srv/app/nttmcoll-staging/htdocs/vendor/spacecatninja/imager-x/src/transformers/ImgixTransformer.php(67): spacecatninja\imagerx\transformers\ImgixTransformer->getTransformedImage(Object(craft\elements\Asset), Array)
#2 /srv/app/nttmcoll-staging/htdocs/vendor/spacecatninja/imager-x/src/services/ImagerService.php(472): spacecatninja\imagerx\transformers\ImgixTransformer->transform(Object(craft\elements\Asset), Array)
#3 /srv/app/nttmcoll-staging/htdocs/vendor/spacecatninja/imager-x/src/variables/ImagerVariable.php(38): spacecatninja\imagerx\services\ImagerService->transformImage(Object(craft\elements\Asset), Array, NULL, NULL)
#4 /srv/app/nttmcoll-staging/htdocs/vendor/twig/twig/src/Extension/CoreExtension.php(1566): spacecatninja\imagerx\variables\ImagerVariable->transformImage(Object(craft\elements\Asset), Array)
#5 /srv/app/nttmcoll-staging/htdocs/vendor/craftcms/cms/src/helpers/Template.php(106): twig_get_attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(spacecatninja\imagerx\variables\ImagerVariable), 'transformImage', Array, 'method', false, false)
#6 /srv/app/nttmcoll-staging/htdocs/storage/runtime/compiled_templates/ba/bac01bbefd36ba85303cda5c1a3f701f3c0b7f84ab71369c965c280352badece.php(76): craft\helpers\Template::attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(spacecatninja\imagerx\variables\ImagerVariable), 'transformImage', Array, 'method')
#7 /srv/app/nttmcoll-staging/htdocs/vendor/twig/twig/src/Extension/CoreExtension.php(1169): __TwigTemplate_bde5669c3c26113909821dbf0dcc52426cf0286171c6c0d3b3e51c07b086b722->macro_imageTransformAny(Object(craft\elements\Asset), Array, 'Charlie and Deb...', NULL)
#8 /srv/app/nttmcoll-staging/htdocs/storage/runtime/compiled_templates/ba/bac01bbefd36ba85303cda5c1a3f701f3c0b7f84ab71369c965c280352badece.php(123): twig_call_macro(Object(__TwigTemplate_bde5669c3c26113909821dbf0dcc52426cf0286171c6c0d3b3e51c07b086b722), 'macro_imageTran...', Array, 21, Array, Object(Twig\Source))
#9 /srv/app/nttmcoll-staging/htdocs/vendor/twig/twig/src/Extension/CoreExtension.php(1169): __TwigTemplate_bde5669c3c26113909821dbf0dcc52426cf0286171c6c0d3b3e51c07b086b722->macro_sized(Object(craft\elements\Asset), 300, 800, 'Charlie and Deb...', NULL, 'fit')
#10 /srv/app/nttmcoll-staging/htdocs/storage/runtime/compiled_templates/32/3206c3a82fc10acaeb973885fab9a232f25d3940b1ec2ba146f432b3b9edd096.php(103): twig_call_macro(Object(__TwigTemplate_bde5669c3c26113909821dbf0dcc52426cf0286171c6c0d3b3e51c07b086b722), 'macro_sized', Array, 23, Array, Object(Twig\Source))
#11 /srv/app/nttmcoll-staging/htdocs/vendor/twig/twig/src/Template.php(405): __TwigTemplate_566c3a3650c20ae673ea7b4042c36ba999a9afffb5147f481c962f69b4dc112e->doDisplay(Array, Array)
#12 /srv/app/nttmcoll-staging/htdocs/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling(Array, Array)
#13 /srv/app/nttmcoll-staging/htdocs/storage/runtime/compiled_templates/ba/ba19465ceeaef756eb130ccf3dd795fe78404b97e37887aa5241fcfd9c94b134.php(120): Twig\Template->display(Array)
#14 /srv/app/nttmcoll-staging/htdocs/vendor/twig/twig/src/Template.php(405): __TwigTemplate_7bfaf7fa67651f1b3b6f373bd653ac3cdc9f4f33544e2e921129f9bd176da145->doDisplay(Array, Array)
#15 /srv/app/nttmcoll-staging/htdocs/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling(Array, Array)
#16 /srv/app/nttmcoll-staging/htdocs/storage/runtime/compiled_templates/b6/b69cb55b6a4e888965d30edf101a6cb47b0a32005364cc0723fabfa7bbe39ab0.php(140): Twig\Template->display(Array)
#17 /srv/app/nttmcoll-staging/htdocs/vendor/twig/twig/src/Template.php(182): __TwigTemplate_34a5dcd031fe6ba6e83c824da30ed81fdcde7d2c93d716c213fb0b880d319c9e->block_body(Array, Array)
#18 /srv/app/nttmcoll-staging/htdocs/storage/runtime/compiled_templates/b6/b69cb55b6a4e888965d30edf101a6cb47b0a32005364cc0723fabfa7bbe39ab0.php(108): Twig\Template->displayBlock('body', Array, Array)
#19 /srv/app/nttmcoll-staging/htdocs/vendor/twig/twig/src/Template.php(182): __TwigTemplate_34a5dcd031fe6ba6e83c824da30ed81fdcde7d2c93d716c213fb0b880d319c9e->block_content(Array, Array)
#20 /srv/app/nttmcoll-staging/htdocs/storage/runtime/compiled_templates/a1/a1dcd9d8126e591269366c011ebd0eed57245df6a785d14f2da92bdf8548fcab.php(569): Twig\Template->displayBlock('content', Array, Array)
#21 /srv/app/nttmcoll-staging/htdocs/vendor/twig/twig/src/Template.php(182): __TwigTemplate_940441b0a9a9a4a86ff8ee9a9705b8ffa5ce3c28f7e9d7a7c7844946b156ab5b->block_fullPage(Array, Array)
#22 /srv/app/nttmcoll-staging/htdocs/storage/runtime/compiled_templates/a1/a1dcd9d8126e591269366c011ebd0eed57245df6a785d14f2da92bdf8548fcab.php(416): Twig\Template->displayBlock('fullPage', Array, Array)
#23 /srv/app/nttmcoll-staging/htdocs/vendor/twig/twig/src/Template.php(405): __TwigTemplate_940441b0a9a9a4a86ff8ee9a9705b8ffa5ce3c28f7e9d7a7c7844946b156ab5b->doDisplay(Array, Array)
#24 /srv/app/nttmcoll-staging/htdocs/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling(Array, Array)
#25 /srv/app/nttmcoll-staging/htdocs/storage/runtime/compiled_templates/b6/b69cb55b6a4e888965d30edf101a6cb47b0a32005364cc0723fabfa7bbe39ab0.php(49): Twig\Template->display(Array, Array)
#26 /srv/app/nttmcoll-staging/htdocs/vendor/twig/twig/src/Template.php(405): __TwigTemplate_34a5dcd031fe6ba6e83c824da30ed81fdcde7d2c93d716c213fb0b880d319c9e->doDisplay(Array, Array)
#27 /srv/app/nttmcoll-staging/htdocs/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling(Array, Array)
#28 /srv/app/nttmcoll-staging/htdocs/storage/runtime/compiled_templates/0c/0cd84fcfbfd9105c49fd3b71a667132eea7fd7489e72c27411a9b51b9cc75878.php(152): Twig\Template->display(Array, Array)
#29 /srv/app/nttmcoll-staging/htdocs/vendor/twig/twig/src/Template.php(405): __TwigTemplate_405d614b56dfd502476ed37b7a11d99c24114741ec88d22c9ff7650f6a8b302f->doDisplay(Array, Array)
#30 /srv/app/nttmcoll-staging/htdocs/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling(Array, Array)
#31 /srv/app/nttmcoll-staging/htdocs/vendor/twig/twig/src/Template.php(390): Twig\Template->display(Array)
#32 /srv/app/nttmcoll-staging/htdocs/vendor/twig/twig/src/TemplateWrapper.php(45): Twig\Template->render(Array, Array)
#33 /srv/app/nttmcoll-staging/htdocs/vendor/twig/twig/src/Environment.php(318): Twig\TemplateWrapper->render(Array)
#34 /srv/app/nttmcoll-staging/htdocs/vendor/craftcms/cms/src/web/View.php(408): Twig\Environment->render('_dispatcher', Array)
#35 /srv/app/nttmcoll-staging/htdocs/vendor/craftcms/cms/src/web/View.php(461): craft\web\View->renderTemplate('_dispatcher', Array)
#36 /srv/app/nttmcoll-staging/htdocs/vendor/craftcms/cms/src/web/Controller.php(205): craft\web\View->renderPageTemplate('_dispatcher', Array, 'site')
#37 /srv/app/nttmcoll-staging/htdocs/vendor/craftcms/cms/src/controllers/TemplatesController.php(102): craft\web\Controller->renderTemplate('_dispatcher', Array)
#38 [internal function]: craft\controllers\TemplatesController->actionRender('_dispatcher', Array)
#39 /srv/app/nttmcoll-staging/htdocs/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#40 /srv/app/nttmcoll-staging/htdocs/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#41 /srv/app/nttmcoll-staging/htdocs/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('render', Array)
#42 /srv/app/nttmcoll-staging/htdocs/vendor/craftcms/cms/src/web/Application.php(293): yii\base\Module->runAction('templates/rende...', Array)
#43 /srv/app/nttmcoll-staging/htdocs/vendor/yiisoft/yii2/web/Application.php(103): craft\web\Application->runAction('templates/rende...', Array)
#44 /srv/app/nttmcoll-staging/htdocs/vendor/craftcms/cms/src/web/Application.php(278): yii\web\Application->handleRequest(Object(craft\web\Request))
#45 /srv/app/nttmcoll-staging/htdocs/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#46 /srv/app/nttmcoll-staging/htdocs/web/index.php(12): yii\base\Application->run()
#47 {main}
aelvan commented 2 years ago

Dang. Need some more information:

1) I see that you're passing in an asset right? If you go to the asset detail view in Craft, or activate dimensions in the element index, does it show the dimensions of the image there? 2) Can you post your imgix config (make sure to strip out any sensitive credentials). 3) What type of source is the Imgix source? 4) What's the transform you're doing on the asset when this fails?

jamesmacwhite commented 2 years ago

Sure.

  1. No dimensions are shown on the AVIF image in the asset view.
  2. My imager-x config:
<?php

/**
 * Imager by André Elvan
 *
 * @author      André Elvan <http://vaersaagod.no>
 * @package     Imager
 * @copyright   Copyright (c) 2016, André Elvan
 * @license     http://opensource.org/licenses/mit-license.php MIT License
 * @link        https://github.com/aelvan/Imager-Craft
 */

/**
 * Configuration file for Imager
 *
 * Override this by placing a file named 'imager-x.php' inside your config folder and override variables as needed.
 * Multi-environment settings work in this file the same way as in general.php or db.php
 */

use craft\helpers\App;

return [
    '*' => [
        'transformer' => App::env('IMGIX_ENABLED') ? 'imgix' : 'craft',
        'imagerSystemPath' => 'resized/',
        'imagerUrl' =>  rtrim(App::env('UPLOAD_ASSET_BASE_URL'), '/') . '/resized/' . strtolower(CRAFT_ENVIRONMENT) . '/',
        'interlace' => true,
        'allowUpscale' => true,
        'removeMetadata' => true,
        'filenamePattern' => 'postfix',
        'hashRemoteUrl' => false,
        'instanceReuseEnabled' => false,
        'useForCpThumbs' => App::parseBooleanEnv('$IMGIX_ENABLED') ?? false,
        'imgixApiKey' => App::env('IMGIX_API_KEY'),
        'imgixConfig' => [
            'default' => [
                'domain' => App::env('IMGIX_HOSTNAME'),
                'useHttps' => true,
                'signKey' => App::env('IMGIX_SIGN_TOKEN'),
                'sourceIsWebProxy' => false,
                'useCloudSourcePath' => true,
                'getExternalImageDimensions' => true,
                'defaultParams' => [
                    'auto' => 'compress,format',
                    'q'=> 80
                ],
            ],
        ],
        'curlOptions' => [
            CURLOPT_PROXY => App::env('HTTP_PROXY') ?: null,
        ]
    ],
    'dev' => [
        // Dev can fallback to local images if required
        'imagerSystemPath' => $_SERVER['DOCUMENT_ROOT'] . '/resized/',
        'imagerUrl' => '/resized/'
    ]
];
  1. Amazon S3 Imgix source
  2. This it the transform macro being used
{% macro imageTransformAny(asset, transform, alt, htmlAttrs) %}
    <!-- Original asset source: {{ asset.getUrl() }} -->
    <img src="{{ craft.imager.transformImage(asset, transform).url }}" alt="{{ alt }}" {{ htmlAttrs }}>
{% endmacro %}
aelvan commented 2 years ago
  1. No dimensions are shown on the AVIF image in the asset view.

Huh.. Do you see the image in the control panel? What image driver are you using (GD or Imagick)? And if you check the PHP info section for your driver, does it have AVIF support?

jamesmacwhite commented 2 years ago

I see the image in the assets list with no dimensions when adding that column on the element index view.

Our hosting environment provides the following PHP setup: https://phpinfo-81.frb.io/

We are on 8.0, but the 8.0 link is currently throwing a 403, however I don't think it would be too different in terms of image drivers for analysis purposes, the versions will differ of course.

Based on this info it would appear imagick module does not support AVIF as it is not listed in the ImageMagick supported formats, so that's likely the problem here. I might need to contact our web hosting provider about this. It looks like PHP 8.1 may be the version it is supported in, although our provider currently isn't using a ImageMagick library version that does by the looks of it but apparently GD does in 8.1, based on:

image image

Technically this isn't an issue if we just don't use AVIF but the fact Craft CMS doesn't let you just block certain file types easily as mentioned before, it does potentially create for a scenario where AVIF images can be used without restrictions as assets, which aren't then going to work on the front end currently with the issue with obtaining width and height values on these formats, despite your best efforts in defending against it.

aelvan commented 2 years ago

Ok, I kinda got blinded by the fact that one sometimes wouldn't get the size from an avif file, even if the image driver had support for it. :) In this case where there's no support for avif, Imager will not be able to get the necessary information from it.

So I think the only resolution here would be to limit the file formats for fields, or create a custom plugin/module to keep avif files from being uploaded at all, and maybe add a conditional in twig (inside that macro for instance) to check the extension to make sure that you don't pass any avif files to Imager.

jamesmacwhite commented 2 years ago

@aelvan

Thanks! You mentioned you implemented a custom module to prevent AVIF files being uploaded, any chance you can share the way you've done it, as I think we might have to block AVIF files as you say to prevent this.

aelvan commented 2 years ago

Sure, it's here: https://github.com/vaersaagod/assetmate

It has a few shortcomings due to limitations in Craft itself, but overall it works well.

jamesmacwhite commented 2 years ago

Thank you! I'll have a look at the way it's done and see if we can implement it.