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

Colors not showing... ideas? #7

Open
danielnjoo opened this issue Nov 14, 2017 · 5 comments
Open

Colors not showing... ideas? #7

danielnjoo opened this issue Nov 14, 2017 · 5 comments

Comments

@danielnjoo
Copy link

danielnjoo commented Nov 14, 2017

Desired image
Output image

The SVG string renders in codepen as desired, however, when I render it with svg2img I get the output as above. Any ideas where this might be going wrong?

My pipeline involves posting the rendered JPEG to s3, and then sending it via Facebook Messenger, and it hasn't gone wrong until now.

If you need any more info let me know, thanks for any help :)!

@fuzhenn
Copy link
Owner

fuzhenn commented Nov 14, 2017

Hi!

svg2img‘s work flow is as below:

img => svg2img(prepare options) => canvg(parse SVG and draw on canvas) => node-canvas

The problem looks like a parsing problem of canvg. If it's OK, you can post your SVG here, I will take a quick check if there is anything unnormal.

@danielnjoo
Copy link
Author

Here's the svgstring, amazing response time 👍

@fuzhenn
Copy link
Owner

fuzhenn commented Nov 17, 2017

Sorry for the late response.

It may be related with external css.

        .axis {
          stroke: #555;
          stroke-width: .2;
        }
        .scale {
          fill: #e7e7e7;
          stroke: #999999;
          stroke-width: .2;
        }
        .shape {
          fill-opacity: .7;
          stroke-width: .5;
        }
        .shape:hover {
          fill-opacity: .6;
        }
        
    .shape.something1 { fill: #edc951; }
    .shape.something2  { fill: #cc333f; }
    .shape.something3 { fill: #00a0b0; }

canvg doesn't support style defines in external CSS, as canvg/canvg#323. You can try to inline the styles, it may resolve your problem.

@danielnjoo
Copy link
Author

OK thanks for the idea, but if external CSS doesn't work, but do the preceding styles get applied?

@fuzhenn
Copy link
Owner

fuzhenn commented Nov 18, 2017

canvg seems to only have limited support of preceding styles, as mentioned in canvg/canvg#414.

I think the problem may come from the selector .shape.something1 { fill: #edc951; }. canvg may be unable to parse the css selector like .shape.something1.

You may replace .shape.something1 to sth like .shape-something1 and see if it can resolve the issue.

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