Comments (8)
@llgcode
I agree with your suggestions.
I hadn't really had an optimization for large files in my mind when I was implementing it.
A simple improvement would be to check whether the group attrs changed and reuse the last group if possible, instead of creating a new one every time.
The default values sounds good as well. We could apply values from first calls of SetStrokeColor
, SetFillColor
, SetLineWidth
, SetLineCap
etc. to SVG element itself. And later only create a group only if current values differ from those of the SVG tag. - If that is what you meant by the default values.
The css classes would be nice too, but a bit harder to implement.
I looked into the code and I have no idea where the LineTo comes from either.
@SteepAtticStairs
It looks like you are rendering a lot of transparent pieces (with stroke="rgba(0,0,0,0)"
) - you could detect those and not render them.
The images are very complex. I'm on the edge about whether svg format is more suitable for them compared to png.
Even if we implement some optimization, the result will probably still be larger than the gzipped version.
from draw2d.
I have pushed a commit to my project:
that prevents transparent colors (e.g. rgba()
values that end in 0 which are transparent) from rendering, and I saw a drastic size differential, around 95 MB
got reduced to around 60 MB
.
I am also gzipping the resulting svg, because this does also reduce the size by an incredible amount.
It looks like you are rendering a lot of transparent pieces (with stroke="rgba(0,0,0,0)") - you could detect those and not render them.
@drahoslove FYI.
from draw2d.
Hi SteepAtticStairs,
I guess you need to reinitialize the path every time you have drawn something, so that the path don't grow on each loop.
Try to do a SVGgc.BeginPath()
and PNGgc.BeginPath()
at the start of the loop.
You could also implement a render function that take draw2d.GraphicContext
as parameter so that you can pass a SVGgc or PNGgc and factorize some code.
Can you please attach your SVG to better understand the issue ?
regards
from draw2d.
radar.svg.gz
Here is the radar.svg
file. I gzipped it because the original file was 95.8 MB
, but the gzip reduced it to 14.3 MB
. This seems like it would be a solution, to just gzip the svg, but then the user would have to unzip it and couldn't render the resulting large svg file.
I tried to do SVGgc.BeginPath()
on the line right after I declared SVGgc
, but didn't decrease the size. The svg file I have attached resulted from code without SVGgc.BeginPath()
.
I have also modified the code in my original comment to remove PNGgc
, because that works fine. I am able to greatly control the size of a png file by setting the size of the canvas. Examples of this are down below.
None of these above images have been compressed or processed at all, they are the raw output from draw2dimg.SaveToPngFile(out, PNGcanvas)
. To see the difference between the images, I would download them and zoom in.
from draw2d.
Thanks,
I've open the svg file. I see a lot of redundant information that could be factorize. For now, the svg generator do not factorize by itself.
I guess one way to factorize is to stroke only when color and lineWidth change. Be careful to not reinitialize the path, I was wrong about the BeginPath in earlier answer, the path is renitialized everytime you draw.
So you can factorize the stroke attribute written into a group. May be you can regroup "draw" that have the same stroke properties.
In our side we could factorize things by using css classes, default values or not using group everytime we draw.
What do you think @drahoslove ?
I see in the SVG path MoveTo and LineTo on the same point, and I couldn't figure out where does this LineTo comes from. It seems that the LineTo is not relevant here. What do you think?
from draw2d.
Thanks.
Do you want me to implement the optimisation?
Or you want to do it ?
from draw2d.
I found the redundant LineTo
Line 129 in 80aa0a2
from draw2d.
Thanks. Do you want me to implement the optimisation? Or you want to do it ?
Please, feel free to implement it yourself.
I can review your code, once you are done, if you want me to.
I found the redundant LineTo
Good job!
from draw2d.
Related Issues (20)
- Add width and height attribute to SVG output HOT 2
- SetLineCap does not work
- Is that possible for cutting a rectangle pic as rounded ? HOT 1
- How can I draw a shape with an inner hole ? HOT 4
- GraphicContext within GraphicContext HOT 1
- support reading of svg format HOT 2
- always get empty png HOT 3
- Draw line using a gradient color HOT 2
- Does it support different blend for image? HOT 1
- Scale/Rotate transformations with graphics context for pdf files HOT 1
- Is it possible to fill path with transparent color on a non-transparent background? HOT 2
- GetStringBounds Wrapping Support HOT 2
- Text Stroke LineCap and LineJoin HOT 6
- how to use your own font / custom font? HOT 1
- i know how to scale image but how do i resize canvas? HOT 1
- nice work, how do i get the color code of a particular pixel? HOT 1
- how to save as []byte so to get md5 hash value without saving to disk first? HOT 1
- i know how to draw a line. but how do you draw a pixel? just 1 pixel. HOT 1
- Support EPS (encapsulated postscript) output HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from draw2d.