Live data from Hacker News

Stanford CS248: Implement an SVG Rasterizer

github.com

21–30 of 82 posts

Re: Stanford CS248: Implement an SVG Rasterizer

#22
post #13

What's a good JavaScript-based solution to render SVG into an image? html2canvas doesn't work well with SVG, especially those heavily styled with CSS.

Kinda defeats the whole purpose of SVG. Only photos should be bitmaps. Graphics should be vectors. This is the 21st century, folks...

Re: Stanford CS248: Implement an SVG Rasterizer

#23
post #13

What's a good JavaScript-based solution to render SVG into an image? html2canvas doesn't work well with SVG, especially those heavily styled with CSS.

If you're not in a Node.js context, the Canvas API does a decent job of rasterizing SVGs nowadays. Once rasterized, you can call canvas.toDataURL() to get a download link. Here's a demo: https://codepen.io/hypothete/pen/WNvKLEE

Does the css need to be inlined?

Re: Stanford CS248: Implement an SVG Rasterizer

#25
post #22
post #13

What's a good JavaScript-based solution to render SVG into an image? html2canvas doesn't work well with SVG, especially those heavily styled with CSS.

Kinda defeats the whole purpose of SVG. Only photos should be bitmaps. Graphics should be vectors. This is the 21st century, folks...

One reason is to generate screenshots of HTML by combining this technique with SVG .

Re: Stanford CS248: Implement an SVG Rasterizer

#26
post #23

Earlier quoted context omitted.

If you're not in a Node.js context, the Canvas API does a decent job of rasterizing SVGs nowadays. Once rasterized, you can call canvas.toDataURL() to get a download link. Here's a demo: https://codepen.io/hypothete/pen/WNvKLEE

Does the css need to be inlined?

seems so: https://codepen.io/andyfangdz/pen/abOjPxe

Re: Stanford CS248: Implement an SVG Rasterizer

#27

2d graphics are kinda hard. The problem is that gpus don't support them out of the box so you have to do a Lot yourself.

What do you mean GPUs don't support them? Most opengl tutorials I've read have people building triangles in 2d to learn fragment shaders and vertices before going 3d. Most of them also support parametric curves, so even hardware accelerated bezier curves should be possible.

Re: Stanford CS248: Implement an SVG Rasterizer

#29
post #22
post #13

What's a good JavaScript-based solution to render SVG into an image? html2canvas doesn't work well with SVG, especially those heavily styled with CSS.

Kinda defeats the whole purpose of SVG. Only photos should be bitmaps. Graphics should be vectors. This is the 21st century, folks...

True, but if you have digital display - that is, which have separate, immovable pixels, working with pixels and not with vector-based analog primitives - you'll eventually have to convert "vector" picture into "pixel" picture.

Re: Stanford CS248: Implement an SVG Rasterizer

#30

2d graphics are kinda hard. The problem is that gpus don't support them out of the box so you have to do a Lot yourself.

What do you mean GPUs don't support them? Most opengl tutorials I've read have people building triangles in 2d to learn fragment shaders and vertices before going 3d. Most of them also support parametric curves, so even hardware accelerated bezier curves should be possible.

Wait, why do you say GPUs support parametric curves? GPUs are based on triangles mostly.
Post reply on HN