PHP code example of mathiasreker / php-svg-optimizer

1. Go to this page and download the library: Download mathiasreker/php-svg-optimizer 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/ */

    

mathiasreker / php-svg-optimizer example snippets




declare(strict_types=1);

r\Services\Providers\FileProvider;
use MathiasReker\PhpSvgOptimizer\Services\SvgOptimizer;

$svgOptimizer = new SvgOptimizer(new FileProvider('path/to/source.svg', 'path/to/output.svg'));

$result = $svgOptimizer
    ->removeTitleAndDesc()
    ->removeComments()
    ->removeUnnecessaryWhitespace()
    ->removeDefaultAttributes()
    ->flattenGroups()
    ->convertColorsToHex()
    ->minifySvgCoordinates()
    ->minifyTransformations()
    ->build();

echo json_encode($result, \JSON_PRETTY_PRINT);

$result = new SvgOptimizer('path/to/source.svg', 'path/to/output.svg');

$svgOptimizer->removeTitleAndDesc();

$svgOptimizer->removeComments();

$svgOptimizer->removeUnnecessaryWhitespace();

$svgOptimizer->removeDefaultAttributes();

$svgOptimizer->flattenGroups();

$svgOptimizer->convertColorsToHex();

$svgOptimizer->minifySvgCoordinates();

$svgOptimizer->minifyTransformations();

$svgOptimizer->build();
bash
composer 
bash
docker exec -it php-svg-optimizer bash