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

Strange colors when trying to convert svg icons to png #15

Open
probonopd opened this issue Oct 22, 2019 · 11 comments
Open

Strange colors when trying to convert svg icons to png #15

probonopd opened this issue Oct 22, 2019 · 11 comments

Comments

@probonopd
Copy link

I am getting strange colors when trying to convert svg icons to png.

The test files and code are attached.

files.zip

Am I missing something obvious?

@srwiley
Copy link
Owner

srwiley commented Oct 23, 2019

Does this happen with all svg files or just this one?

@probonopd
Copy link
Author

probonopd commented Oct 23, 2019

Also with other svg icons on my Xubuntu system from /usr/share/icons/hicolor/scalable.

@srwiley
Copy link
Owner

srwiley commented Nov 12, 2019

I get the same result as you. There are quite a few unsupported elements in this particular svg, most of which are in the metadata section. You will see them if you turn error reporting on. In this case, after the meta data section is removed I get two elements that are not supported:

2019/11/11 19:32:17 Cannot process svg element namedview
2019/11/11 19:32:17 Cannot process svg element grid

Although I am not certain this is the problem, until oksvg supports those two things I think it will not draw correctly. If you can slim it down to a file without those elements and it still does not draw correctly, I will take another look.

@probonopd
Copy link
Author

probonopd commented Nov 12, 2019

Attached are two versions of the icon: in tagsremoved.svg I have removed all offending tags until oksvg does not complain anymore. The conversion still has the wrong colors.

For slimmed.png I have sent the PNG through an optimizer; this one results in a crash.

https://github.com/srwiley/oksvg/files/3837681/icons.zip

@srwiley
Copy link
Owner

srwiley commented Jan 16, 2020

probonopd, sorry for taking so long to get back to you. The tagsremoved.svg file does not appear as a link on my end. Please provided a link like you did for files.zip.
thanks, srwiley

@probonopd
Copy link
Author

@srwiley
Copy link
Owner

srwiley commented Jan 20, 2020

I think I have this mostly fixed; see the "gradfix" branch oksvg and update rasterx.

The problem lies with gradients in a couple of ways. The magenta you are seeing is because that is the default color I used for a gradient with no stops as a debugging tool. The default is now black.

Also, there are some gradients with no colors specified in their stops. This is apparently OK as per the SVG2.0 specifications as you are supposed to then use the current fill or line color. So, now a gradient defined in the defs might change depending on the path in which it is used, which took a little more work to implement.

Finally, in your example file there are radial gradients that have an xlink:href to a linear gradient. xlink:href is deprecated, but even if you substitute in the preferred use(url) syntax, it makes no sense except perhaps to copy the list of stops into the radial gradient. However, the default SVG renderer in linux just ignores that type of linking and so does oksvg for now.

Since there are some substantive changes I am putting the fixes in the "gradfix" branch of oksvg for a couple of weeks. If I don't hear back from any interested parties, I will merge it into the main. Also reload rasterx before testing the fix, since the default color for no stop gradients is there.

@probonopd
Copy link
Author

probonopd commented Jan 22, 2020

Thank you very much @srwiley. I no longer see the pink/magenta color, but now some icons are rendered in black/grey colors that should be colorful. I'd still consider it an improvement, but apparently the issue is not entirely solved yet.

I will post examples as I encounter them.

@srwiley
Copy link
Owner

srwiley commented Jan 22, 2020

I agree, there is still some stuff going on. What exactly did you do to generate the "tagsremoved" version of the hard drive icon? Because on my system that appears to render correctly, while the original does not.

@probonopd
Copy link
Author

Just a text editor :-)

@probonopd
Copy link
Author

Attached are some examples.

examples.zip

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