spacecatninja / craft-imager-x

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

Issue transforming external image #184

Open mark-adigital opened 2 years ago

mark-adigital commented 2 years ago

Hi,

I'm submitting a bug report.

  1. Try to transform an image from the Eventbrite API, for example: https://img.evbuc.com/https%3A%2F%2Fcdn.evbuc.com%2Fimages%2F372052839%2F543193880685%2F1%2Foriginal.20221012-143745?auto=format%2Ccompress&q=75&sharp=10&s=337ac9ecddfce644aaa9926c6b4135fe

Expected behaviour would be for the image to be transformed as follows:

{% set imageUrl = event.logo.original.url|default('\/assets\/img\/arnside.jpg') %}
{% set transformedImages = craft.imager.transformImage(imageUrl, [
  { width: 382 },
  { width: 466 },
  { width: 592 },
  { width: 764 },
  { width: 932 },
  { width: 1184 }
], { ratio: 16/10, interlace: true, format: format }) %}
<img src="{{ transformedImages[0] }}" srcset="{{ craft.imager.srcset(transformedImages) }}" width="382" height="239" sizes="(min-width: 1024px) 382px, (min-width: 640px) 50vw, 100vw" alt="{{ event.name.text|default('Arnside') }}" class="block w-full" crossorigin loading="lazy">

However, instead we're seeing intermittent 500 errors due to the image format not being determined. Often these are resolved on refresh (the output is being cached) and the transforms do appear to be working from Eventbrite images, so unsure as to whether this is possibly a false error that is being thrown?

Error log:

2022-10-30 12:56:06 [-][-][-][error][Imagine\Exception\InvalidArgumentException] Imagine\Exception\InvalidArgumentException: Saving image in "20221012-143745" format is not supported, please use one of the following extensions: "bmp", "gif", "jpeg", "png", "wbmp", "webp", "xbm" in /srv/users/morecambebay/apps/mbp-live/vendor/pixelandtonic/imagine/src/Gd/Image.php:602
Stack trace:
#0 /srv/users/morecambebay/apps/mbp-live/vendor/pixelandtonic/imagine/src/Gd/Image.php(265): Imagine\Gd\Image->saveOrOutput('20221012-143745', Array, '/srv/users/more...')
#1 /srv/users/morecambebay/apps/mbp-live/vendor/spacecatninja/imager-x/src/transformers/CraftTransformer.php(297): Imagine\Gd\Image->save('/srv/users/more...', Array)
#2 /srv/users/morecambebay/apps/mbp-live/vendor/spacecatninja/imager-x/src/transformers/CraftTransformer.php(96): spacecatninja\imagerx\transformers\CraftTransformer->getTransformedImage(Object(spacecatninja\imagerx\models\LocalSourceImageModel), Array)
#3 /srv/users/morecambebay/apps/mbp-live/vendor/spacecatninja/imager-x/src/services/ImagerService.php(472): spacecatninja\imagerx\transformers\CraftTransformer->transform('https://img.evb...', Array)
#4 /srv/users/morecambebay/apps/mbp-live/vendor/spacecatninja/imager-x/src/variables/ImagerVariable.php(38): spacecatninja\imagerx\services\ImagerService->transformImage('https://img.evb...', Array, Array, NULL)
#5 /srv/users/morecambebay/apps/mbp-live/vendor/twig/twig/src/Extension/CoreExtension.php(1566): spacecatninja\imagerx\variables\ImagerVariable->transformImage('https://img.evb...', Array, Array)
#6 /srv/users/morecambebay/apps/mbp-live/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)
#7 /srv/users/morecambebay/apps/mbp-live/storage/runtime/compiled_templates/1d/1dd842817b8cea5156cee73a9fc6a63d1f59be001d5bc294ac534323584434a0.php(217): craft\helpers\Template::attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(spacecatninja\imagerx\variables\ImagerVariable), 'transformImage', Array, 'method')
#8 /srv/users/morecambebay/apps/mbp-live/vendor/twig/twig/src/Template.php(182): __TwigTemplate_aef5251ad2dabae682481012d3f7e970c4ce6741f4d65520419b66aa5be20ff7->block_maincontent(Array, Array)
#9 /srv/users/morecambebay/apps/mbp-live/storage/runtime/compiled_templates/1c/1cf1f9149b50e31d27a0235c1303d0079700eb51d5d3c1558e0544ef47af3cdb.php(304): Twig\Template->displayBlock('maincontent', Array, Array)
#10 /srv/users/morecambebay/apps/mbp-live/vendor/twig/twig/src/Template.php(405): __TwigTemplate_2e765a7b949dcb64bde8d414f17c42ff9870a60e8691ed1879dd96f517cdfa6d->doDisplay(Array, Array)
#11 /srv/users/morecambebay/apps/mbp-live/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling(Array, Array)
#12 /srv/users/morecambebay/apps/mbp-live/storage/runtime/compiled_templates/1d/1dd842817b8cea5156cee73a9fc6a63d1f59be001d5bc294ac534323584434a0.php(44): Twig\Template->display(Array, Array)
#13 /srv/users/morecambebay/apps/mbp-live/vendor/twig/twig/src/Template.php(405): __TwigTemplate_aef5251ad2dabae682481012d3f7e970c4ce6741f4d65520419b66aa5be20ff7->doDisplay(Array, Array)
#14 /srv/users/morecambebay/apps/mbp-live/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling(Array, Array)
#15 /srv/users/morecambebay/apps/mbp-live/vendor/twig/twig/src/Template.php(390): Twig\Template->display(Array)
#16 /srv/users/morecambebay/apps/mbp-live/vendor/twig/twig/src/TemplateWrapper.php(45): Twig\Template->render(Array, Array)
#17 /srv/users/morecambebay/apps/mbp-live/vendor/twig/twig/src/Environment.php(318): Twig\TemplateWrapper->render(Array)
#18 /srv/users/morecambebay/apps/mbp-live/vendor/craftcms/cms/src/web/View.php(408): Twig\Environment->render('_home/index', Array)
#19 /srv/users/morecambebay/apps/mbp-live/vendor/craftcms/cms/src/web/View.php(461): craft\web\View->renderTemplate('_home/index', Array)
#20 /srv/users/morecambebay/apps/mbp-live/vendor/craftcms/cms/src/web/Controller.php(205): craft\web\View->renderPageTemplate('_home/index', Array, 'site')
#21 /srv/users/morecambebay/apps/mbp-live/vendor/craftcms/cms/src/controllers/TemplatesController.php(102): craft\web\Controller->renderTemplate('_home/index', Array)
#22 [internal function]: craft\controllers\TemplatesController->actionRender('_home/index', Array)
#23 /srv/users/morecambebay/apps/mbp-live/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#24 /srv/users/morecambebay/apps/mbp-live/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#25 /srv/users/morecambebay/apps/mbp-live/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('render', Array)
#26 /srv/users/morecambebay/apps/mbp-live/vendor/craftcms/cms/src/web/Application.php(293): yii\base\Module->runAction('templates/rende...', Array)
#27 /srv/users/morecambebay/apps/mbp-live/vendor/yiisoft/yii2/web/Application.php(103): craft\web\Application->runAction('templates/rende...', Array)
#28 /srv/users/morecambebay/apps/mbp-live/vendor/craftcms/cms/src/web/Application.php(278): yii\web\Application->handleRequest(Object(craft\web\Request))
#29 /srv/users/morecambebay/apps/mbp-live/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#30 /srv/users/morecambebay/apps/mbp-live/public/index.php(26): yii\base\Application->run()
#31 {main}

Aware this might not be a bug as such, but we would at least appreciate some help to understand the best way to try and fix the issue. Thanks!

aelvan commented 2 years ago

Hi,

Thanks for submitting. I'm not able to reproduce, but could you elaborate on this:

However, instead we're seeing intermittent 500 errors due to the image format not being determined. Often these are resolved on refresh (the output is being cached) and the transforms do appear to be working from Eventbrite images, so unsure as to whether this is possibly a false error that is being thrown?

So, when an image fails, that same image shows correctly on the next refresh?

aelvan commented 2 years ago

Could you also share your imager-x config file (make sure to redact any sensitive data).

mark-adigital commented 2 years ago

Yes - it certainly seems that way. We've mostly detected the downtime through a Pingdom alert, so by the time we visit the site it's often come back up, but logs indicate that the same image which throws the error will subsequently be transformed successfully.

We're actually just using the default Imager config on this site.

Whenever we're outputting content from EventBrite, we're typically wrapping it in Craft {% cache %} tags to reduce the number of calls to the API and improve performance, and the downtime alerts correspond to when that cache expires - but obviously that might not mean the caching is the cause of the problem, just that it might be happening a lot more often without caching.