This module adds a FieldFormatter for an Image field, which let's you implement base64 of the image directly.
While most of the code comes from the core module image's ImageFormatter.php, some rewriting with templating has been done. Should be stable.
After installation of this module you'll get a new format type "Image Base64" you can assign to any Image Field in a Content Type. Just go to the Type's "Manage Display" and choose "Image Base64" instead of "Image" from the Format Combo-Box. (see the attachment screenshot)
Now the image's base64 encoded in the chosen form will be returned as 'img src="data:image/jpeg;base64,..."' instead of the 'img src="path/filename.xxx"' tag.
Also working well as Restful API (json/xml) service, return the entire image base64 encoded, and you can directly use outside of your decoupled drupal application.
Project link
https://www.drupal.org/project/image_base64_formatter
Git instructions
git clone --branch 8.x-1.x https://git.drupal.org/project/image_base64_formatter.git
PAReview checklist
https://pareview.sh/pareview/https-git.drupal.org-project-image_base64_f...
Manual reviews of other projects
| Comment | File | Size | Author |
|---|---|---|---|
| image_base64_formatter.jpg | 47.42 KB | vuil |
Comments
Comment #2
vuilComment #3
baikho commentedHi @i.vuchkov
See the following:
Can you please remove the
8.x-1.xtag from the8.x-1.xbranch, so that we can run the PAReview report against your branch?Thanks!
Comment #4
avpadernoComment #5
avpadernoI am closing this application due to lack of replies. Please see comment #3 for what needs to be fixed.
Comment #6
vuilHello, sorry for my delay... I removed the 8.x-1.x tag from the 8.x-1.x branch. Thank you.
Comment #7
avpadernoentity_load()ort()when dependency injection is available, for example inside plugin classesComment #8
vuilI applied all requirements mentioned in PAReview checklist:
https://pareview.sh/pareview/https-git.drupal.org-project-image_base64_f...
Please, review the code... Thank you.
Comment #9
klausiThanks for your contribution!
* Remove "datestamp" from the info file, it will be added by drupal.org packaging automatically
* Move all code files to the root folder of the project. No need to create a nested image_base64_formatter folder again.
* template_preprocess_image_base64_formatter(): empty function, should be removed.
* ImageBase64Formatter::viewElements(): do not build markup here, return a render array and use a twig template instead that other people can easily override.
Otherwise looks good to me, did not see any security issues.
Comment #10
vuilDone!
* Remove "datestamp" from the info file.
* Move all code files to the root folder of the project.
* Remove template_preprocess_image_base64_formatter(): empty function.
Comment #11
avpadernoThank you for your contribution! I am going to update your account.
These are some recommended readings to help with excellent maintainership:
You can find more contributors chatting on the IRC #drupal-contribute channel. So, come hang out and stay involved.
Thank you, also, for your patience with the review process.
Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.
I thank all the dedicated reviewers as well.
Comment #12
vuilThanks a lot @kiamlaluno.
I joined the group of reviewers and made some reviews.
Comment #13
vuilComment #14
vuilComment #15
vuilComment #16
klausiWith this in mind, I have marked your application as 'fixed'. If this is incorrect, and you do not yet have the ability to opt into security advisory coverage, then please feel free to re-open this application.
Comment #17
klausiMaybe you did not edit your project yet to opt into security advisory coverage?