Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVGs render to an empty PNG #399

Open
texzone opened this issue Aug 23, 2023 · 12 comments
Open

SVGs render to an empty PNG #399

texzone opened this issue Aug 23, 2023 · 12 comments

Comments

@texzone
Copy link

texzone commented Aug 23, 2023

I have a couple of SVG files that I wish to convert to PNG or JPEG - doesn't matter really. Unfortunately, whenever I try to render them to JPG or PNG using CairoSVG, the pictures are empty (contain nothing). I am not sure where the issue is, but actually, when I try to do it online using any other SVG -> PNG tools, the same thing happens. Would love some guidance as to why this is happening.

I have included three SVG files here as an example that you can see in SVG-Viewer.

N-Sqaured
Additions
3x3

So, yeah - what could be the reason for this issue?

@liZe
Copy link
Member

liZe commented Aug 23, 2023

Hi!

Your files work well for me:
ex
ex2

I’ve tried CairoSVG 2.6.0 and 2.7.1, they both work. Do you use an older version?

@texzone
Copy link
Author

texzone commented Aug 23, 2023

Hi!

Your files work well for me: ex ex2

I’ve tried CairoSVG 2.6.0 and 2.7.1, they both work. Do you use an older version?

Huh, interesting! I am using CairoSVG version 2.7.1 on Windows. I did experience a lot of trouble getting it installed though, and ultimately had to install the libcairo-2.dll from some other source and use that DLL. Could that be the issue, that this particular DLL is outdated?

Edit:

Pretty sure this is what I followed: https://stackoverflow.com/questions/46265677/get-cairosvg-working-in-windows

I installed uiconverter, got the DLLs and added them to my SystemPath. I also installled GTK3-runtime and added that to the path as well. There may be other things I have done, to be honest.... im not entirely sure. All I know is, I had to really finagle

@texzone
Copy link
Author

texzone commented Aug 23, 2023

Okay, I am not sure what to do. According to this issue, GTK3 should be good? I have uninstalled everything, reinstalled CairoSVG with GTK3, and still.... nothing.

@liZe
Copy link
Member

liZe commented Aug 23, 2023

I feel like all I need it the .dll file.

Yes, you need the DLL files, and the GTK3 installer is probably the easiest way to get them.

and still.... nothing.

Do you mean that the error is gone but that the image is empty?

@texzone
Copy link
Author

texzone commented Aug 23, 2023

Yes, the errors are gone (which is why i deleted the message - my bad, I should have edited or something). I installed GTK3 and included it in my SystemPath on Windows. However, I get the same issue where the image is still basically empty or just a block of black/white.

> python
Python 3.11.4 (tags/v3.11.4:d2340ef, Jun  7 2023, 05:45:37) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cairosvg
>>> cairosvg.__version__
'2.7.1'

This is the code im running:

def svg_to_png_jpeg(input_svg_path):
    cairosvg.svg2png(
        url=input_svg_path,
        write_to=output_png_path,
        background_color="white",
        scale=2
    )

These are the images I get:
With background=white
With no background

... issues with AMD?

@liZe
Copy link
Member

liZe commented Aug 23, 2023

... issues with AMD?

CairoSVG does not use the graphic card.

Do you have the same problem by launching python -m cairosvg --background=white --scale=2 input.svg -o output.png?

@texzone
Copy link
Author

texzone commented Aug 23, 2023

Yes, unfortunately, I do... seems like exactly the same output. So you dont think the issue is with a... weird .dll file im getting for GTK3?

@liZe
Copy link
Member

liZe commented Aug 23, 2023

So you dont think the issue is with a... weird .dll file im getting for GTK3?

I don’t think so. I really don’t know where it could come from.

Could you please share the result of python -m cairosvg --background=white --scale=2 input.svg -o output.svg?

@texzone
Copy link
Author

texzone commented Aug 23, 2023

Yes, absolutely. Here are the files

output.png
input.svg

@texzone
Copy link
Author

texzone commented Aug 23, 2023

Shoot, my bad, I just reread your comment. The output needs to be SVG, not PNG. My bad.
output.svg

There is the svg file. My bad

<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="351.828pt" height="34.116pt" viewBox="0 0 351.828 34.116" version="1.1">
  <defs>
    <clipPath id="clip1">
      <path d="M 178 0 L 239 0 L 239 34.117188 L 178 34.117188 Z M 178 0 "/>
    </clipPath>
    <clipPath id="clip2">
      <path d="M 170 0 L 247 0 L 247 34.117188 L 170 34.117188 Z M 170 0 "/>
    </clipPath>
  </defs>
  <g id="surface1">
    <rect x="0" y="0" width="351.828" height="34.116" style="fill:rgb(100%,100%,100%);fill-opacity:1;stroke:none;"/>
    <g clip-path="url(#clip1)" clip-rule="nonzero">
      <path style=" stroke:none;fill-rule:nonzero;fill:rgb(0%,0%,0%);fill-opacity:1;" d="M 208.5 373.5 L 205.5 373.5 C 193.5 373.5 184.5 366.5 178.5 352.5 L 178.5 -376.5 L 180 -1105.5 C 190 -1118.5 199.5 -1125 208.5 -1125 C 221.5 -1125 231.5 -1117.5 238.5 -1102.5 L 238.5 352.5 C 230.5 366.5 221.5 373.5 211.5 373.5 Z M 208.5 373.5 "/>
    </g>
    <g clip-path="url(#clip2)" clip-rule="nonzero">
      <path style="fill:none;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:4;" d="M 139 -249 L 137 -249 C 129 -249 123 -244.333333 119 -235 L 119 251 L 120 737 C 126.666667 745.666667 133 750 139 750 C 147.666667 750 154.333333 745 159 735 L 159 -235 C 153.666667 -244.333333 147.666667 -249 141 -249 Z M 139 -249 " transform="matrix(1.5,0,0,-1.5,0,0)"/>
    </g>
  </g>
</svg>

@liZe
Copy link
Member

liZe commented Aug 23, 2023

I really don’t know where your problem comes from. I’ve tried two different versions of Cairo on two different computers, and it works well for me.

I am not sure where the issue is, but actually, when I try to do it online using any other SVG -> PNG tools, the same thing happens.

That’s really, really strange, because your file is pretty easy SVG and should give correct results with many converters. Are you sure that the input SVG are exactly the ones you provided in this issue? Is the original SVG correctly displayed in a browser on your computer for example?

The only "strange" thing in this files is the "ex" unit used in the svg tag for width and height. Do you get the same result when you use px instead of ex?

@texzone
Copy link
Author

texzone commented Aug 23, 2023

I truly have no idea... I am certain that the SVG files are the same. Well, I'm going to go bang my head against the wall for a bit and see if any divine intervention occurs. Thank you so much for your time man!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants