SvgDocumentService

Read onlyYes
FinalYes

Stateless operations on {@see SvgDocument} instances: dimension resolution, serialization and crop-scaling.

The document to operate on is always passed in as the first argument, no instance state is kept. Obtain documents via SvgDocumentFactory.

Internal

not part of TYPO3 Core API.

Attributes
#[Autoconfigure]
$public: true

Table of Contents

Methods

cropScale()  : SvgDocument
Wrap the source SVG in an outer `<svg>` that carries the crop viewBox and target dimensions. The passed document is not mutated, a new {@see SvgDocument} is returned.
getDimensions()  : ImageDimension
Resolve pixel dimensions of the SVG.
toInlineMarkup()  : string
Serialize the document as inline HTML5-ready markup.
toXml()  : string
Serialize the document as plain XML markup of its root element, without an `<?xml ?>` prolog.

Methods

getDimensions()

Resolve pixel dimensions of the SVG.

public getDimensions(SvgDocument $document) : ImageDimension

Preference order:

  1. viewBox attribute (width = index 2, height = index 3)
  2. numeric width / height attributes (override viewBox values)
  3. non-numeric width / height (e.g. "100mm", "50%") only when no viewBox-derived value is present, stripped of their unit
  4. 64x64 fallback when nothing usable is found
Parameters
$document : SvgDocument
Return values
ImageDimension

toInlineMarkup()

Serialize the document as inline HTML5-ready markup.

public toInlineMarkup(SvgDocument $document) : string

Emits only the root <svg> element (no <?xml ?> prolog) and applies the clean-ups needed when inlining SVG into an HTML document:

  • drops xmlns="http://www.w3.org/2000/svg" (HTML5 auto-places <svg> in the SVG namespace),
  • drops the legacy version attribute,
  • synthesizes a viewBox from width/height when missing so the SVG scales with CSS instead of rendering at intrinsic pixel size.

Operates on a detached clone; the passed document is not mutated.

Parameters
$document : SvgDocument
Return values
string

toXml()

Serialize the document as plain XML markup of its root element, without an `<?xml ?>` prolog.

public toXml(SvgDocument $document) : string
Parameters
$document : SvgDocument
Return values
string
On this page

Search results