Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

add a base64 encoding filter #54

Closed
lsmith77 opened this issue Apr 26, 2012 · 14 comments · Fixed by twigphp/Twig#3102
Closed

add a base64 encoding filter #54

lsmith77 opened this issue Apr 26, 2012 · 14 comments · Fixed by twigphp/Twig#3102
Labels

Comments

@lsmith77
Copy link

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.

@romainneutron
Copy link
Contributor

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

@nlegoff This is for you

@snc
Copy link

snc commented Apr 29, 2012

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

@cryptocompress
Copy link

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 :)

@romainneutron
Copy link
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

@romainneutron
Copy link
Contributor

Here's my implementation, based on PHP-dataURI

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

@cryptocompress
Copy link

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

@damienalexandre
Copy link

👍 for this feature in the core!

@ghost
Copy link

ghost commented Apr 19, 2016

👍

4 similar comments
@webdevilopers
Copy link

👍

@Maelstromeous
Copy link

👍

@nateclonch
Copy link

👍

@obax
Copy link

obax commented Mar 12, 2018

👍

@fabpot
Copy link
Contributor

fabpot commented Aug 7, 2019

implemented in Twig core (see twigphp/Twig#3102)

@fabpot fabpot closed this as completed Aug 7, 2019
fabpot added a commit to twigphp/Twig that referenced this issue Aug 7, 2019
This PR was merged into the 2.x branch.

Discussion
----------

Add the data_uri filter

Implemented as a popular request here: closes twigphp/Twig-extensions#54

Commits
-------

220e750 added the data_uri filter
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

10 participants