Converters
AbstractConverter
Laratusk\Larasvg\Converters\AbstractConverter
The abstract base class that provides shared logic for all converters.
Properties
| Property | Type | Visibility | Description |
|---|---|---|---|
$inputPath | string | public readonly | Path to the input SVG file |
$binary | string | public readonly | Path to the converter binary |
$timeout | int | public private(set) | Process timeout in seconds |
$options | array | public private(set) | CLI options as key-value pairs |
Abstract Methods
Subclasses must implement:
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:
| Method | Default | Resvg | Inkscape | rsvg-convert |
|---|---|---|---|---|
widthOption() | export-width | width | export-width | width |
heightOption() | export-height | height | export-height | height |
dpiOption() | export-dpi | dpi | export-dpi | — (overridden) |
backgroundOption() | export-background | background | export-background | background-color |
backgroundOpacityOption() | export-background-opacity | background-opacity | export-background-opacity | — (combined into color) |
ResvgConverter
Laratusk\Larasvg\Converters\ResvgConverter
Implements SVG to PNG conversion using the Resvg CLI.
Supported Formats
public const array SUPPORTED_FORMATS = ['png'];Additional Methods
| Method | Signature | Description |
|---|---|---|
setZoom | (float $zoom): static | Set zoom factor |
setShapeRendering | (string $mode): static | Shape rendering mode |
setTextRendering | (string $mode): static | Text rendering mode |
setImageRendering | (string $mode): static | Image rendering mode |
setDefaultFontFamily | (string $family): static | Default font family |
setDefaultFontSize | (int $size): static | Default font size |
useFontFile | (string $path): static | Use specific font file |
useFontsDir | (string $path): static | Load fonts from directory |
skipSystemFonts | (): static | Skip system fonts |
setResourcesDir | (string $path): static | Resources directory |
InkscapeConverter
Laratusk\Larasvg\Converters\InkscapeConverter
Implements SVG conversion using the Inkscape CLI. Supports multiple output formats.
Supported Formats
public const array SUPPORTED_FORMATS = ['svg', 'png', 'ps', 'eps', 'pdf', 'emf', 'wmf'];Additional Methods
| Method | Signature | Description |
|---|---|---|
setPage | (int|string $page): static | Set page(s) to export |
firstPage | (): static | Export first page only |
exportId | (string $id, bool $idOnly = false): static | Export specific object |
exportAreaPage | (): static | Export page area |
exportAreaDrawing | (): static | Export drawing area |
exportArea | (float $x0, float $y0, float $x1, float $y1): static | Custom export area |
exportAreaSnap | (): static | Snap area to pixels |
exportTextToPath | (): static | Convert text to paths |
exportPlainSvg | (): static | Export plain SVG |
exportOverwrite | (): static | Overwrite input file |
exportPdfVersion | (string $version = '1.4'): static | PDF version |
exportPsLevel | (int $level = 3): static | PostScript level |
exportPngColorMode | (string $mode): static | PNG color mode |
exportPngCompression | (int $level): static | PNG compression (0-9) |
exportPngAntialias | (int $level): static | PNG antialiasing (0-3) |
exportMargin | (float|int $margin): static | Export margin |
exportLatex | (): static | LaTeX companion file |
exportIgnoreFilters | (): static | Ignore SVG filters |
vacuumDefs | (): static | Remove unused defs |
query | (?string $objectId = null): array | Query dimensions |
actionList | (): string | List available actions |
RsvgConvertConverter
Laratusk\Larasvg\Converters\RsvgConvertConverter
Implements SVG conversion using the rsvg-convert CLI (from librsvg). Supports PNG, PDF, PS, EPS, and SVG output.
Supported Formats
public const array SUPPORTED_FORMATS = ['png', 'pdf', 'ps', 'eps', 'svg'];Additional Methods
| Method | Signature | Description |
|---|---|---|
setZoom | (float $zoom): static | Set zoom factor |
setXZoom | (float $zoom): static | Horizontal zoom factor |
setYZoom | (float $zoom): static | Vertical zoom factor |
keepAspectRatio | (bool $keep = true): static | Preserve aspect ratio |
setStylesheet | (string $path): static | External CSS stylesheet |
unlimited | (bool $unlimited = true): static | Disable parser guards |
setPageWidth | (string $width): static | Page width for PDF/PS (e.g. '210mm') |
setPageHeight | (string $height): static | Page height for PDF/PS (e.g. '297mm') |
setTopMargin | (string $margin): static | Top margin/offset |
setLeftMargin | (string $margin): static | Left margin/offset |
keepImageData | (bool $keep = true): static | Control image compression in PDF/PS |
setBaseUri | (string $uri): static | Base URI for relative references |
DPI behaviour
setDpi() sets both --dpi-x and --dpi-y simultaneously, since rsvg-convert uses separate flags for each axis.
Background opacity
rsvg-convert has no --background-opacity flag. Calling setBackgroundOpacity() combines the value with the background color into a single rgba() string.