Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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