Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rozbehsharahi/svg-convert
Library to convert SVG to other formats
https://github.com/rozbehsharahi/svg-convert
Last synced: 2 days ago
JSON representation
Library to convert SVG to other formats
- Host: GitHub
- URL: https://github.com/rozbehsharahi/svg-convert
- Owner: RozbehSharahi
- License: mit
- Created: 2019-11-02T13:26:23.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-01-18T14:27:03.000Z (almost 5 years ago)
- Last Synced: 2024-06-26T10:48:09.778Z (5 months ago)
- Language: PHP
- Size: 33.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SVG Converter
Library to convert SVG to other formats using ImageMagick.Currently contains two converter implementations:
- ImageMagickConverter (Default)
- GraphicsMagickConverter
- RsvgConverter## Install package
```bash
composer require rozbehsharahi/svg-convert
```## Usage
```php
writeToFile(Configuration::create()->setFile('example.png'));// Write into jpg file
Svg::createFromFile('example.svg')->writeToFile(Configuration::create()->setFile('example.jpg'));// Write into gif file
Svg::createFromFile('example.svg')->writeToFile(Configuration::create()->setFile('example.gif'));// Write into png with given dimension
Svg::createFromFile('example.svg')->writeToFile(
Configuration::create()
->setFile('example_1000x1000.png')
->setDimension(1000, 1000)
);// Returns base64 string ready for tag
Svg::createFromFile('example.svg')->getBase64Url(Configuration::create());// Returns base64 string ready for tag
Svg::createFromFile('example.svg')->getBase64Url(Configuration::create()->setFormat('jpg'));// Returns base64 string ready for tag
Svg::createFromFile('example.svg')->getBase64Url(Configuration::create()->setFormat('gif'));// Returns base64 encoded image
Svg::createFromFile('example.svg')->getBase64(Configuration::create()->setFormat('gif'));// Renders the svg as png
Svg::createFromFile('example.svg')->render(Configuration::create());// Use different converters
Svg::createFromFile('example.svg')->use(new RsvgConverter)->getBase64Url(Configuration::create());
Svg::createFromFile('example.svg')->use(new GraphicsMagickConverter)->getBase64Url(Configuration::create());// Create svg from different sources
Svg::createFromFile('example.svg');
Svg::createFromContent('...');
Svg::createFromBase64('aSBsb3ZlIHByb2dhbW1pbmcK');// Set default converter
Svg::setDefaultConverter(new RsvgConverter());// Set command for converters
ImageMagickConverter::setCommand('/usr/bin/convert');
RsvgConverter::setCommand('/usr/bin/rsvg-convert');
```## Information
- The package does not depend on \Imagick and can be used on server that do not support the php-extension.
- Is based on imagemagick