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

https://groups.drupal.org/node/535161

  1. [D8] Superfaktura
  2. [D8] iyzipay
  3. [D8] SCSS Compiler
  4. [D8] Smartcat Translation Manager
  5. [D8] REST API Access Token
CommentFileSizeAuthor
image_base64_formatter.jpg47.42 KBvuil

Comments

i.vuchkov created an issue. See original summary.

vuil’s picture

Issue summary: View changes
baikho’s picture

Status: Needs review » Needs work

Hi @i.vuchkov

See the following:

There is a git tag that has the same name as the branch 8.x-1.x. Make sure to remove this tag to avoid confusion.

Can you please remove the 8.x-1.x tag from the 8.x-1.x branch, so that we can run the PAReview report against your branch?

Thanks!

avpaderno’s picture

Title: [D8] Image Base64 Formatter (8.5.x - 8.6.x) » [D8] Image Base64 Formatter
Assigned: vuil » Unassigned
Issue summary: View changes
avpaderno’s picture

Status: Needs work » Closed (won't fix)

I am closing this application due to lack of replies. Please see comment #3 for what needs to be fixed.

vuil’s picture

Status: Closed (won't fix) » Needs review

Hello, sorry for my delay... I removed the 8.x-1.x tag from the 8.x-1.x branch. Thank you.

avpaderno’s picture

Status: Needs review » Needs work
  • What follows is a quick review of the project; it doesn't mean to be complete
  • For every point, I didn't make a complete list of where the code should be fixed, but an example of what is wrong in the code
  • Not all the points are application stoppers; some of them describe changes that would be preferable to make
  1. The code should not use entity_load() or t() when dependency injection is available, for example inside plugin classes
  2. The code doesn't follow the Drupal coding standards in many points
vuil’s picture

Status: Needs work » Needs review

I 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.

klausi’s picture

Status: Needs review » Reviewed & tested by the community

Thanks 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.

vuil’s picture

Done!

* 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.

avpaderno’s picture

Assigned: Unassigned » avpaderno
Status: Reviewed & tested by the community » Fixed

Thank 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.

vuil’s picture

Thanks a lot @kiamlaluno.
I joined the group of reviewers and made some reviews.

vuil’s picture

Issue summary: View changes
vuil’s picture

Issue tags: +PAreview: review bonus
vuil’s picture

Status: Fixed » Needs review
klausi’s picture

Status: Needs review » Fixed
Already Approved
It appears that you have successfully completed the application process with this application, and been granted the security advisory coverage permission:

With 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.

klausi’s picture

Maybe you did not edit your project yet to opt into security advisory coverage?

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.