PHP code example of sportsgearswag / artwork-vectorizer

1. Go to this page and download the library: Download sportsgearswag/artwork-vectorizer 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/ */

    

sportsgearswag / artwork-vectorizer example snippets


// config/bundles.php
Sgs\Vectorizer\ArtworkVectorizerBundle::class => ['all' => true],

public function __construct(private readonly VectorizerService $vectorizer) {}

$result = $this->vectorizer->convert($file, TraceOptions::fromPreset('logo'));
// $result['svg'], $result['layers'], ...

foreach ($vectorizer->engines() as $name => $engine) {
    printf("%-8s %s\n", $name, $engine['available'] ? 'ready' : 'not installed');
}

// config/bundles.php
return [
    // ...
    Sgs\Vectorizer\ArtworkVectorizerBundle::class => ['all' => true],
];

use Sgs\Vectorizer\TraceOptions;
use Sgs\Vectorizer\VectorizerService;

public function __construct(private readonly VectorizerService $vectorizer) {}

public function convert(string $uploadedFile): array
{
    $detection = $this->vectorizer->inspect($uploadedFile);
    $options   = TraceOptions::fromPreset($detection['preset']);

    return $this->vectorizer->convert($uploadedFile, $options);
}

// config/bundles.php
Sgs\Vectorizer\ArtworkVectorizerBundle::class => ['all' => true],

[
    'svg'              => '<svg ...>',   // the finished markup
    'layers'           => [              // one entry per ink, largest area first
        ['hex' => '#C8102E', 'share' => 12.7, 'pms' => 'PMS 186 C', 'pmsDelta' => 0.0, 'subpaths' => 2],
    ],
    'palette'          => [['hex' => '#C8102E', 'share' => 12.7]],
    'detectedInks'     => 4,      // found before the max-colour cap was applied
    'paletteTruncated' => false,  // true when detectedInks exceeded the cap
    'width'            => 900,
    'height'           => 400,
    'bytes'            => 3930,
    'subpaths'         => 15,
    'engine'           => 'potrace',  // which one actually ran, after fallback
    'compliance'       => [],         // non-empty means the SVG broke a format rule
    'seconds'          => 1.55,
]

$deviation = $vectorizer->measureDeviation($file, $result['svg'], true);   // % off the original
$coverage  = $vectorizer->measureCoverage($file, $result['svg']);          // % of ink area drawn

$verdict = ConversionAssessment::assess($deviation, $coverage, $preset, count($result['layers']));
// ['verdict' => 'good', 'headline' => 'Good — 1.61% off the original across 4 layers', 'detail' => '...']