PHP code example of vestaware / svg-sprite-generator

1. Go to this page and download the library: Download vestaware/svg-sprite-generator 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/ */

    

vestaware / svg-sprite-generator example snippets


use Vestaware\SvgSpriteGenerator\SvgSpriteGenerator;

// Define the input directory containing SVG files
$inputDir = __DIR__ . '/svgs';

// Define the output directory for the SVG sprite
$outputDir = __DIR__ . '/output';

// Define the base file name for the sprite
$baseFileName = 'sprite';

// Define the path for the manifest file
$manifestPath = $outputDir . '/sprite-manifest.json';

// Create an instance of the generator
$generator = new SvgSpriteGenerator($inputDir, $outputDir, $baseFileName, $manifestPath, removeFill: true);

// Generate the SVG sprite
$generator->generateSprite();

// Load the manifest to retrieve the generated file name
$manifest = json_decode(file_get_contents($manifestPath), true);
$generatedFileName = $manifest[$baseFileName];

echo "SVG sprite generated at: $outputDir/$generatedFileName";