deeplook / svglib

Read SVG files and convert them to other formats.
GNU Lesser General Public License v3.0
307 stars 79 forks source link

Problems with embedded image sizes #395

Open Technickfreak opened 6 months ago

Technickfreak commented 6 months ago

The tool I am using to convert SVG files to JPG is encountering issues with embedded images. In the provided SVG code, the image is correctly positioned, but its size does not match the specified dimensions.

<?xml version="1.0" encoding="utf-8"?>
<svg viewBox="-120 -120 240 240" xmlns="http://www.w3.org/2000/svg">
  <circle cx="0" cy="0" r="120"/>

  <circle cx="-50" cy="-60" r="30" fill="#ff00ff"/>
  <circle cx="-50" cy= "60" r="30" fill="#00ffff"/>

  <circle cx="60" cy= "50" r="30" fill="#ffff00"/>
  <circle cx="60" cy="-50" r="30" fill="#ff0000"/>

  <g fill="none" stroke="black">
    <path stroke-width="7" stroke-linecap="round" d="M50 -50  70 -50" />
    <path stroke-width="7" stroke-linecap="round" d="M60 -40  60 -60" />

    <path stroke-width="7" stroke-linecap="round" d="M50  50  70  50" />
  </g>

  <rect x="-100" y="-25" rx="25" ry="25" width="130" height="50" style="fill:#ffffff" />

  <image x="-70" y="40" width="40" height="40" href="save-44.svg" />
  <image x="-70" y="-80" href="home-360.svg" width="40px" height="40px"/>

</svg>

Parameter

drawing = svg2rlg("Bilder\\Parameter.svg")
renderPM.drawToFile(drawing, "Bilder\\temp.png", fmt="PNG")

temp

home-360.svg: home-360

save-44.svg: save-44

github-actions[bot] commented 6 months ago

Thank you for raising your first issue! Your help to improve svglib is much appreciated!

Technickfreak commented 6 months ago

on github the embeddOn Github, the embedded image is not displayed at all. when the svg is opened in the browser, they are displayed correctly.ed image is not displayed at all

deeplook commented 6 months ago

You don't seem to provide the files "save-44.svg" and "home-360.svg" above in this ticket, do you? At least I don't see their SVG code anywhere...

Technickfreak commented 6 months ago

save-44.svg:

<svg class="svg-icon" style="width: 1em; height: 1em;vertical-align: middle;fill: currentColor;overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M730.584615 78.769231v267.815384c0 19.692308-15.753846 37.415385-37.415384 37.415385H273.723077c-19.692308 0-37.415385-15.753846-37.415385-37.415385V78.769231H157.538462C114.215385 78.769231 78.769231 114.215385 78.769231 157.538462v708.923076c0 43.323077 35.446154 78.769231 78.769231 78.769231h708.923076c43.323077 0 78.769231-35.446154 78.769231-78.769231V220.553846L803.446154 78.769231h-72.861539z m137.846154 750.276923c0 19.692308-15.753846 37.415385-37.415384 37.415384H194.953846c-19.692308 0-37.415385-15.753846-37.415384-37.415384V500.184615c0-19.692308 15.753846-37.415385 37.415384-37.415384h636.061539c19.692308 0 37.415385 15.753846 37.415384 37.415384v328.861539zM488.369231 267.815385c0 19.692308 15.753846 37.415385 37.415384 37.415384h90.584616c19.692308 0 37.415385-15.753846 37.415384-37.415384V78.769231h-163.446153l-1.969231 189.046154z"  /></svg>

home-360.svg:

<svg class="svg-icon" style="width: 1em; height: 1em;vertical-align: middle;fill: currentColor;overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M947.712 508.48 555.008 140.224C547.968 132.672 538.176 128.384 527.872 128.384S507.776 132.672 500.672 140.224L73.92 510.912C63.872 521.728 61.184 537.472 67.072 550.976s19.264 22.336 33.984 22.336l92.288 0 0 280.32C193.344 888.768 220.864 896 256 896l63.36 0 21.184 0 7.04 0L339.456 896c23.424 0 42.368-19.008 42.368-42.368l0-171.264C381.824 659.008 400.832 640 424.32 640l173.888 0c23.488 0 42.432 19.008 42.432 42.368l0 171.264c0 23.36 19.008 42.368 42.432 42.368l84.224 0C802.496 896 832 888.768 832 853.632l0-280.32 90.688 0c0.128 0 0.128 0 0.256 0 20.48 0 37.056-16.64 37.056-37.12C960 525.248 955.2 515.392 947.712 508.48z"  /></svg>