apache > cocoon
 

SVG/PNG Serializer

SVG/PNG Serializer

The SVG/PNG serializes an xml svg document to a png image. The serialization uses the Batik's PNGTranscoder internally.

  • Name : svg2png
  • Class: org.apache.cocoon.serialization.SVGSerializer
  • Cacheable: yes

Sitemap Configuration

A minimal sitemap configuration snippet declaring the svg2png serializer:

<map:serializers..
  <map:serializer name="svg2png"
    src="org.apache.cocoon.serialization.SVGSerializer"
    mime-type="image/png"
    logger="sitemap.serializer.svg2png"
  >
  </map:serializer>

A sitemap pipeline snippet using the svg2png serializer:

<map:match pattern="svg/*.png">
  <map:generate src="docs/samples/svg/{1}.svg"/>
  <map:serialize type="svg2png"/>
</map:match>

In the declaration section of the svg2png a number of parameters can be specified. The following snippet set the background color explicitly:

<map:serializers..
  <map:serializer name="svg2png"
    src="org.apache.cocoon.serialization.SVGSerializer"
    mime-type="image/png"
    logger="sitemap.serializer.svg2png"
  >
    <parameter name="background_color" type="color" value="#ff00ff"/>
  </map:serializer>

PNGTranscoder Parameters

General ImageTranscoder parameters are described at the SVG Serializer user documentation.

The following section presents PNGTranscoder specific parameters configurable for the PNGTranscoder.

Parameter

Type

Comment

force_transparent_white

boolean

It controls whether the encoder should force the image's fully transparent pixels to be fully transparent white instead of fully transparent black. This is usefull when the encoded PNG is displayed in a browser which does not support PNG transparency and lets the image display with a white background instead of a black background.
However, note that the modified image will display differently over a white background in a viewer that supports transparency.

gamma

float

Controls the gamma correction of the png image; by default its value is approx 2.22.

Further Reading

Further details about PNGTranscoder, ImageTranscoder is available at Batik.