Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/basster/twig-base64-extension
Convert images to base64 in twig
https://github.com/basster/twig-base64-extension
Last synced: about 4 hours 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 (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-31T19:28:36.000Z (almost 2 years ago)
- Last Synced: 2024-11-15T16:28:34.313Z (2 days ago)
- Language: PHP
- Size: 12.7 KB
- Stars: 4
- Watchers: 3
- Forks: 5
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
basster/twig-base64-extension
=============================[![SymfonyInsight](https://insight.symfony.com/projects/b44a3032-735a-4659-9077-d32393efa623/mini.svg)](https://insight.symfony.com/projects/b44a3032-735a-4659-9077-d32393efa623) [![Build Status](https://scrutinizer-ci.com/g/Basster/twig-base64-extension/badges/build.png?b=master)](https://scrutinizer-ci.com/g/Basster/twig-base64-extension/build-status/master) [![Code Coverage](https://scrutinizer-ci.com/g/Basster/twig-base64-extension/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/Basster/twig-base64-extension/?branch=master) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Basster/twig-base64-extension/badges/quality-score.png?b=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.