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

[BUG] image_rgba in exported svg does not open properly in editors (like inkscape) #11649

Closed
Tushar-N opened this issue Sep 20, 2021 · 5 comments

Comments

@Tushar-N
Copy link

Running this example and then exporting to svg.

N = 20
img = np.empty((N,N), dtype=np.uint32)
view = img.view(dtype=np.uint8).reshape((N, N, 4))
for i in range(N):
    for j in range(N):
        view[i, j, 0] = int(i/N*255)
        view[i, j, 1] = 158
        view[i, j, 2] = int(j/N*255)
        view[i, j, 3] = 255

p = figure(output_backend='svg') # set svg backend
p.x_range.range_padding = p.y_range.range_padding = 0
p.image_rgba(image=[img], x=0, y=0, dw=10, dh=10)

export_svg(p, filename='test.svg') # export to svg

results in an svg that can render properly in browser, but does not open in Inkscape. Fix:

  • xmlns:xlink="http://www.w3.org/1999/xlink" is missing from the namespace
  • all images need the xlink:href attribute (instead of just href)

i.e. if I re-write the .svg file with these replacements, it will open fine

data = open('test.svg', 'r').read()
data = data.replace('xmlns="http://www.w3.org/2000/svg"', 'xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"')
data = data.replace('href=', 'xlink:href=')
with open('test.svg', 'w') as f:
    f.write(data)
@bryevdv
Copy link
Member

bryevdv commented Sep 20, 2021

@Tushar-N according to MDN the usage you propose is deprecated and not recommended:

https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/xlink:href

So I would definitely not regard this as a bug, or at least, not one on our end. It seems like this is known and open issue on Inkscape:

https://gitlab.com/inkscape/inbox/-/issues/620

I guess my going-in position would be that this is something for Inkscape to sort out, and that we should not output deprecated web standards by default. At most, something like that would need to be behind a compatibility flag of some sort.

cc @mattpap

@Tushar-N
Copy link
Author

Thanks for the pointer, I wasn't aware of this.

I guess my going-in position would be that this is something for Inkscape to sort out, and that we should not output deprecated web standards by default.

Makes sense to me. A compatibility flag would be great since Inkscape is popular, or a warning somewhere in the docs for people who try and edit the files. This issue can be closed otherwise.

@mattpap
Copy link
Contributor

mattpap commented Sep 20, 2021

We used to support xlink, but given that all browsers (even IE 11) support plain href, then that support was removed (quite recently actually). Perhaps if I knew Inkscape doesn't support href, I would have postponed this change. Support can be restored, as it's just a few lines of code. What saddens me, is that they had a PR submitted fixing this, and it was rejected as being not good enough.

@bryevdv
Copy link
Member

bryevdv commented Nov 13, 2021

@mattpap how do you want to triage this? If you don't want to restore it, that's ok with me, but then we should close.

@mattpap
Copy link
Contributor

mattpap commented Mar 5, 2023

Support for href was finally merged into Inkscape, though I'm not sure whether this fix was already released or not (they don't assign milestones systematically). I will consider this as an upstream problem.

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

No branches or pull requests

3 participants