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

Blurhash string must be at least 6 characters #206

Closed
1 of 3 tasks
jwb009 opened this issue Mar 28, 2023 · 4 comments
Closed
1 of 3 tasks

Blurhash string must be at least 6 characters #206

jwb009 opened this issue Mar 28, 2023 · 4 comments

Comments

@jwb009
Copy link

jwb009 commented Mar 28, 2023

I'm submitting a...

  • bug report
  • feature request
  • general question

Steps to reproduce

  1. Using this code, per the docs, results in the error in the title
{% set transform = craft.imagerx.transformImage(asset, { width: 160, height: 90 }) %}
<img src="{{ craft.imagerx.placeholder({ type: 'blurhash', hash: transform.getBlurhash(), width: 25, height: 10 }) }}" width="160" height="90">```


### Description
<!-- Describe both the expected and actual/current behaviour--> 
If I replace the `transform.getBlurhash()` with a random blurhash value, the image loads as "expected". This is obviously not the intended outcome, but I'm not sure where else to troubleshoot.

### Displayed errors, stack trace, relevant logs  
<!-- If it’s long, please paste to https://ghostbin.com/ and insert the link here -->

InvalidArgumentException: Blurhash string must be at least 6 characters in /var/www/html/vendor/kornrunner/blurhash/src/Blurhash.php:88
Stack trace:
#0 /var/www/html/vendor/spacecatninja/imager-x/src/services/PlaceholderService.php(174): kornrunner\Blurhash\Blurhash::decode('', 25, 10)
#1 [internal function]: spacecatninja\imagerx\services\PlaceholderService::spacecatninja\imagerx\services{closure}(Object(craft\cache\FileCache))
#2 /var/www/html/vendor/yiisoft/yii2/caching/Cache.php(607): call_user_func(Object(Closure), Object(craft\cache\FileCache))
#3 /var/www/html/vendor/spacecatninja/imager-x/src/services/PlaceholderService.php(193): yii\caching\Cache->getOrSet('imager-x-blurha...', Object(Closure))
#4 /var/www/html/vendor/spacecatninja/imager-x/src/services/PlaceholderService.php(61): spacecatninja\imagerx\services\PlaceholderService->placeholderBlurhash(Array)
#5 /var/www/html/vendor/spacecatninja/imager-x/src/variables/ImagerVariable.php(62): spacecatninja\imagerx\services\PlaceholderService->placeholder(Array)
#6 /var/www/html/vendor/twig/twig/src/Extension/CoreExtension.php(1607): spacecatninja\imagerx\variables\ImagerVariable->placeholder(Array)
#7 /var/www/html/vendor/craftcms/cms/src/helpers/Template.php(146): twig_get_attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(spacecatninja\imagerx\variables\ImagerVariable), 'placeholder', Array, 'method', false, false)
#8 /var/www/html/storage/runtime/compiled_templates/9e/9ee707d0b77dbbea829b415500d369fdeb6e5abe1e030301f1dbacec78c6a91f.php(69): craft\helpers\Template::attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(spacecatninja\imagerx\variables\ImagerVariable), 'placeholder', Array, 'method')
#9 /var/www/html/vendor/twig/twig/src/Template.php(394): __TwigTemplate_90144b85c1ee61594ca5a2d3927755d8371983e40b084f8223b5aaf523c1a98a->doDisplay(Array, Array)
#10 /var/www/html/vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array)
#11 /var/www/html/vendor/twig/twig/src/Template.php(379): Twig\Template->display(Array)
#12 /var/www/html/vendor/twig/twig/src/TemplateWrapper.php(40): Twig\Template->render(Array, Array)
#13 /var/www/html/vendor/twig/twig/src/Environment.php(277): Twig\TemplateWrapper->render(Array)
#14 /var/www/html/vendor/craftcms/cms/src/web/View.php(456): Twig\Environment->render('sections', Array)
#15 /var/www/html/vendor/craftcms/cms/src/web/View.php(509): craft\web\View->renderTemplate('sections', Array)
#16 /var/www/html/vendor/craftcms/cms/src/web/TemplateResponseFormatter.php(56): craft\web\View->renderPageTemplate('sections', Array, 'site')
#17 /var/www/html/vendor/yiisoft/yii2/web/Response.php(1098): craft\web\TemplateResponseFormatter->format(Object(craft\web\Response))
#18 /var/www/html/vendor/craftcms/cms/src/web/Response.php(286): yii\web\Response->prepare()
#19 /var/www/html/vendor/yiisoft/yii2/web/Response.php(339): craft\web\Response->prepare()
#20 /var/www/html/vendor/yiisoft/yii2/base/Application.php(390): yii\web\Response->send()
#21 /var/www/html/web/index.php(17): yii\base\Application->run()
#22 {main}


### Additional info

- Imager version & edition: Imager X Pro 4.1.12
- Imager transformer: AWS Serverless
- Craft version: 4.4.5
- PHP version: 8.0.26
- Image driver & version: imagick 3.7.0
@aelvan
Copy link
Contributor

aelvan commented Mar 29, 2023

If you're using AWS Serverless for the image that you run getBlurhash() on, that would explain it, since that transformer doesn't support blurhash.

@jwb009
Copy link
Author

jwb009 commented Mar 29, 2023

I see....that would be why! Thanks for the quick response. Is it possible to add it to the AWS transformer? It seems supported on Sharp.js per this article https://css-tricks.com/inline-image-previews-with-sharp-blurhash-and-lambda-functions/ But I have no clue what's involved in implementing it, would just be nice to have.

@aelvan
Copy link
Contributor

aelvan commented Apr 2, 2023

No, the kind of flexibility that the article talks about is not available in the AWS transformer (AFAIK).

But, unless you're using AWS Serverless because you can't use local transforms, there's always the option of using the craft transformer for this one transform, like this:

{% set transform = craft.imagerx.transformImage(asset, { width: 160, height: 90 }, {}, { transformer: 'craft' }) %}
<img src="{{ craft.imagerx.placeholder({ type: 'blurhash', hash: transform.getBlurhash(), width: 25, height: 10 }) }}" width="160" height="90">```

Hope that helps!

@jwb009
Copy link
Author

jwb009 commented Apr 3, 2023

That does help, thank you! I hadn't thought of the workaround to use local transforms, but that should work.

@jwb009 jwb009 closed this as completed Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants