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

Added save_png to drawing #196

Closed
wants to merge 1 commit into from
Closed

Conversation

JosephLing
Copy link

Using the nsvg library which is based off nanosvg to save the export svg string as a png. So that the output for save_svg and save_png are exactly the same.

One small change is that fill-opacity and stroke-opacity are used for the alpha value instead of rgba. This is because despite using the image::ColorType::Rgba8 the alpha channel is not converted properly when saving the image. I suspect this because the actual nsvg library doesn't support rgba() colours as I got exactly the same error when testing the resvg library of a black image. The resvg converts the svg input into a svg just made up of paths allowing you to see the intermediate representation. That showed stroke="none" therefore rgba colour was the issue I think and that changing it fixed it.

@codecov
Copy link

codecov bot commented Aug 31, 2020

Codecov Report

Merging #196 into master will decrease coverage by 0.57%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #196      +/-   ##
==========================================
- Coverage   60.78%   60.21%   -0.58%     
==========================================
  Files          40       40              
  Lines        2637     2662      +25     
==========================================
  Hits         1603     1603              
- Misses       1034     1059      +25     
Impacted Files Coverage Δ
src/async_drawing.rs 55.22% <0.00%> (-1.70%) ⬇️
src/drawing.rs 62.16% <0.00%> (-1.73%) ⬇️
src/ipc_protocol/protocol.rs 53.46% <0.00%> (-1.36%) ⬇️
src/renderer_server/handlers/export_drawings.rs 0.00% <0.00%> (ø)
src/renderer_server/renderer/export.rs 0.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ce7eb4a...e3598ad. Read the comment docs.

@sunjay
Copy link
Owner

sunjay commented Aug 31, 2020

Hey @JosephLing! Thanks for taking the time to implement this feature.

Unfortunately, the save_png method that we eventually want to have will probably look different from what you've implemented here. Creating a string from the SVG and making a PNG from that is fine when we're building automation like in #190, but it's not something we'd want in the main library for users to use.

The implementation we will eventually strive for is probably something closer to what we have for save_svg but writing to a PNG image buffer instead. I'll need to do quite a bit of research before I'm ready to review and mentor the implementation of that. In the meantime, let's finish the last few steps in #190 before we move on to other things. :)

I'm going to close this PR for now because I'm not going to have the bandwidth to get it to the implementation we eventually want. I appreciate your eagerness and the effort it took to put this together! 😄

@sunjay sunjay closed this Aug 31, 2020
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

Successfully merging this pull request may close these issues.

2 participants