Image

class svgwrite.image.Image(href, insert=None, size=None, **extra)

The image element indicates that the contents of a complete file are to be rendered into a given rectangle within the current user coordinate system. The image element can refer to raster image files such as PNG or JPEG or to files with MIME type of “image/svg+xml”.

Methods

Image.__init__(href, insert=None, size=None, **extra)
Parameters:
  • href (string) – hyperlink to the image resource
  • insert (2-tuple) – insert point (x, y)
  • size (2-tuple) – (width, height)
  • attribs (dict) – additional SVG attributes
  • extra – additional SVG attributs as keyword-arguments
Image.stretch()

Stretch viewBox in x and y direction to fill viewport, does not preserve aspect ratio.

Image.fit(horiz='center', vert='middle', scale='meet')

Set the preserveAspectRatio attribute.

Parameters:
  • horiz (string) – horizontal alignment 'left'|'center'|'right'
  • vert (string) – vertical alignment 'top'|'middle'|'bottom'
  • scale (string) – scale method 'meet'|'slice'
Scale methods Description
meet preserve aspect ration and zoom to limits of viewBox
slice preserve aspect ration and viewBox touch viewport on all bounds, viewBox will extend beyond the bounds of the viewport

SVG Attributes

  • classstring

    assigns one or more css-class-names to an element

  • stylestring

    allows per-element css-style rules to be specified directly on a given element

  • externalResourcesRequiredbool

    False: if document rendering can proceed even if external resources are unavailable else: True

  • transform – use svgwrite.mixins.Transform interface

  • x<coordinate>insert parameter

    The x-axis coordinate of one corner of the rectangular region into which the referenced document is placed.

    Default is '0'.

  • y<coordinate>insert parameter

    The y-axis coordinate of one corner of the rectangular region into which the referenced document is placed.

    Default is '0'.

  • width<length>size parameter

    The width of the rectangular region into which the referenced document is placed. A negative value is an error. A value of zero disables rendering of the element.

  • height<length>size parameter

    The height of the rectangular region into which the referenced document is placed. A negative value is an error. A value of zero disables rendering of the element.

  • xlink:hrefstringhref parameter

    A IRI reference to the image resource.

  • preserveAspectRatio'[defer] <align> [<meetOrSlice>]'