https://github.com/basster/twig-base64-extension
Convert images to base64 in twig
https://github.com/basster/twig-base64-extension
Last synced: about 1 month ago
JSON representation
Convert images to base64 in twig
- Host: GitHub
- URL: https://github.com/basster/twig-base64-extension
- Owner: Basster
- License: mit
- Created: 2019-06-26T08:21:12.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-31T19:28:36.000Z (over 2 years ago)
- Last Synced: 2025-06-02T02:27:18.703Z (about 1 month ago)
- Language: PHP
- Size: 12.7 KB
- Stars: 4
- Watchers: 2
- Forks: 5
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
basster/twig-base64-extension
=============================[](https://insight.symfony.com/projects/b44a3032-735a-4659-9077-d32393efa623) [](https://scrutinizer-ci.com/g/Basster/twig-base64-extension/build-status/master) [](https://scrutinizer-ci.com/g/Basster/twig-base64-extension/?branch=master) [](https://scrutinizer-ci.com/g/Basster/twig-base64-extension/?branch=master)
Install
-------```bash
composer req basster/twig-base64-extension
```Use in Symfony
--------------If you are using [Symfony Flex](https://flex.symfony.com/) you're done.
If you are not using Flex, add the following to your `services.yaml`:
```yaml
services:
_defaults:
public: false
autowire: true
autoconfigure: trueBasster\TwigBase64\Converter\ImageToBase64Converter: ~
Basster\TwigBase64\Twig\Base64ImageExtension: ~
Basster\TwigBase64\Converter\FileConverterInterface: '@Basster\TwigBase64\Converter\ImageToBase64Converter'
```If you are using Twig standalone, do something like this:
```php
$converter = new \Basster\TwigBase64\Converter\ImageToBase64Converter(new \Symfony\Component\Serializer\Normalizer\DataUriNormalizer());
$extension = new \Basster\TwigBase64\Twig\Base64ImageExtension($converter);$twig = new \Twig\Environment($loader);
$twig->addExtension($extension);
```Usage
------```twig
![]()
```Supported Mime-Types?
---------------------
It utilizes Symfonys `MimeTypeGuesser`, nuff said.