PHP code example of choowx / rasterize-svg

1. Go to this page and download the library: Download choowx/rasterize-svg library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

choowx / rasterize-svg example snippets


use Choowx\RasterizeSvg\Svg;

$svgString = '<svg width="100" height="100" viewBox="0 0 100 100"...';

$jpegBinaryString = Svg::make($svgString)->toJpeg();
$jpegBinaryString = Svg::make($svgString)->toJpg(); // Alias of toJpeg()
$pngBinaryString = Svg::make($svgString)->toPng();
$webpBinaryString = Svg::make($svgString)->toWebp();

use Choowx\RasterizeSvg\Svg;

$svgString = '<svg width="100" height="100" viewBox="0 0 100 100"...';

Svg::make($svgString)->saveAsJpeg('path/to/rasterized.jpeg');
Svg::make($svgString)->saveAsJpg('path/to/rasterized.jpg'); // Alias of saveAsJpeg()
Svg::make($svgString)->saveAsPng('path/to/rasterized.png');
Svg::make($svgString)->saveAsWebp('path/to/rasterized.webp');