Skip to content

Wrong dimensions when using SVG units such as "mm" #4628

@urish

Description

@urish

Bug report

Describe the bug

The following SVG uses the "mm" units, and renders incorrectly:

<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100">
  <rect x="0" y="0" width="13.22mm" height="13.22mm" fill="red" />
  <rect x="50" y="50" width="13.22mm" height="13.22mm" fill="blue" />
</svg>

This is what it looks like with pyvips (3.0.0):

Image

This is what it looks like when converted with rsvg-convert (v2.58.0) and in both Chrome / Firefox:

Image

From what I can tell, it seems like the units are scaled down by a factor of 1.33.

I also tried playing around with the dpi and scale parameters of the svgload function, but they only scale the resulting image, without affecting the content within.

To Reproduce

Save the provided svg to "test-units.svg", and then run the following python script:

import pyvips
image = pyvips.Image.svgload('test-units.svg')
image.write_to_file('test-units-py.png')

Environment
(please complete the following information)

  • OS: Windows 11
  • pyvips: 3.0.0
  • pyvips-binary: 8.17.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions