add a base64 encoding filter #54

Open
lsmith77 opened this Issue Apr 26, 2012 · 11 comments

Projects

None yet

8 participants

this can be convenient for inlining images. the filter should accept a variable containing a binary string, a stream resource and maybe also just a filename.

Contributor

Probably a binding to this lib is a good way ? https://github.com/alchemy-fr/PHP-dataURI

@nlegoff This is for you

snc commented Apr 29, 2012

for mime-type detection you can check this Symfony2 classes/code:

you are right. i tested this:
http://pastebin.com/Hi07BaEE

some drawbacks:

  • class "MimeTypeGuesser" is a Singleton
  • my webhoster disabled Fileinfo ext
  • my webhoster disabled "passthru" method
  • method "mime_content_type" is deprecated
  • there is no posibility to catch the exception (\LogicException SPL?) cleanly (no code)
  • in class File\File there is an protected "mime-type => extension" array ($defaultExtensions). with array_flip i might map this...
    BUT:
    in rfc2397 mime-type ([]) is optional. so it works entirely without mime-type or with text/plain... it doesnt matter :)
Contributor

Be carefull, your implementation does not check the string length to comply with RFC 2397 section 2 https://www.ietf.org/rfc/rfc2397.txt

Contributor

Here's my implementation, based on PHP-dataURI

https://github.com/romainneutron/TwigExtension-DataUri

RFC 1866 Hypertext Markup Language - 2.0 November 1995
The `NAMELEN' parameter in the SGML declaration (9.5, "SGML Declaration for HTML") limits the length of an attribute value to 1024 characters.

BC can be overdone :)
and except for mixing datatypes, i like your solution...

👍 for this feature in the core!

JHGitty commented Apr 19, 2016

👍

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment