Skip to content

Converters

AbstractConverter

Laratusk\Larasvg\Converters\AbstractConverter

The abstract base class that provides shared logic for all converters.

Properties

PropertyTypeVisibilityDescription
$inputPathstringpublic readonlyPath to the input SVG file
$binarystringpublic readonlyPath to the converter binary
$timeoutintpublic private(set)Process timeout in seconds
$optionsarraypublic private(set)CLI options as key-value pairs

Abstract Methods

Subclasses must implement:

php
abstract protected function providerName(): string;
abstract protected function applyExportOptions(string $exportPath): void;
abstract public function supportedFormats(): array;
abstract public function version(): string;
abstract public function buildCommand(): string;

Option Name Methods

Subclasses can override these to match their CLI flag names:

MethodDefaultResvgInkscape
widthOption()export-widthwidthexport-width
heightOption()export-heightheightexport-height
dpiOption()export-dpidpiexport-dpi
backgroundOption()export-backgroundbackgroundexport-background
backgroundOpacityOption()export-background-opacitybackground-opacityexport-background-opacity

ResvgConverter

Laratusk\Larasvg\Converters\ResvgConverter

Implements SVG to PNG conversion using the Resvg CLI.

Supported Formats

php
public const array SUPPORTED_FORMATS = ['png'];

Additional Methods

MethodSignatureDescription
setZoom(float $zoom): staticSet zoom factor
setShapeRendering(string $mode): staticShape rendering mode
setTextRendering(string $mode): staticText rendering mode
setImageRendering(string $mode): staticImage rendering mode
setDefaultFontFamily(string $family): staticDefault font family
setDefaultFontSize(int $size): staticDefault font size
useFontFile(string $path): staticUse specific font file
useFontsDir(string $path): staticLoad fonts from directory
skipSystemFonts(): staticSkip system fonts
setResourcesDir(string $path): staticResources directory

InkscapeConverter

Laratusk\Larasvg\Converters\InkscapeConverter

Implements SVG conversion using the Inkscape CLI. Supports multiple output formats.

Supported Formats

php
public const array SUPPORTED_FORMATS = ['svg', 'png', 'ps', 'eps', 'pdf', 'emf', 'wmf'];

Additional Methods

MethodSignatureDescription
setPage(int|string $page): staticSet page(s) to export
firstPage(): staticExport first page only
exportId(string $id, bool $idOnly = false): staticExport specific object
exportAreaPage(): staticExport page area
exportAreaDrawing(): staticExport drawing area
exportArea(float $x0, float $y0, float $x1, float $y1): staticCustom export area
exportAreaSnap(): staticSnap area to pixels
exportTextToPath(): staticConvert text to paths
exportPlainSvg(): staticExport plain SVG
exportOverwrite(): staticOverwrite input file
exportPdfVersion(string $version = '1.4'): staticPDF version
exportPsLevel(int $level = 3): staticPostScript level
exportPngColorMode(string $mode): staticPNG color mode
exportPngCompression(int $level): staticPNG compression (0-9)
exportPngAntialias(int $level): staticPNG antialiasing (0-3)
exportMargin(float|int $margin): staticExport margin
exportLatex(): staticLaTeX companion file
exportIgnoreFilters(): staticIgnore SVG filters
vacuumDefs(): staticRemove unused defs
query(?string $objectId = null): arrayQuery dimensions
actionList(): stringList available actions

Released under the MIT License.