-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Resize svg and output png file #729
Comments
Hello, by default the SVG will be rendered at a density of 72DPI, which the metadata for this image suggests will be 16x16. Then You can set the If a density of 72 renders a 16x16 image, then a density of at least 72*100/16 = 450 will be suitable for rendering a 100x100 image. sharp(new Buffer(layersWithSvg[0].icon_svg), { density: 450 })... |
@lovell Thanks a lot, it worked. Another question if I may: What is the fastest way to overlay png with svg (specified as xml text)? This operation is done iteratively like in #405. Right now I try // Resizing overlay
const overlay = await sharp(new Buffer(layer.icon_svg), { density }).toBuffer()
const sharpSprite = sharp(pngBuffer).overlayWith(overlay, { top, left })
// Converting to buffer
const result = await sharpSprite.toBuffer() It takes a lot of time:
All in all it takes around 22 seconds for my program to generate png sprite that consists of 18 svg images loaded from db. Also half of the time is consumed by conversion of Sharp into Buffer. |
The const result = await sharp(pngBuffer)
.overlayWith(new Buffer(layer.icon_svg), { density, top, left })
.toBuffer(); I notice the JSDocs for |
@lovell Thanks again, it halved sprite generation time, you are the best. |
Commit 701b1c4 adds |
Hi @ReFruity Have you solved the performance issue about overlay png with svg? |
@ReFruity @lovell sorry for the noise, I'm trying to resize svg=>png as well and I'm having poor quality too.
Test svg: https://afonsopacifer.github.io/assets/img/tech/node.svg |
@ReFruity At what dimensions does the default density of 72 DPI render? That's your divisor. What dimension do you need? That's your dividend. Multiple the result of this division by 72. There was a worked example in #729 (comment):
|
I am sorry if it is obvious or has been answered before, but this code
for icon_svg with metadata
outputs very poor quality png. Seems like it is scaling rasterized svg. How to scale svg and convert to png correctly?
The text was updated successfully, but these errors were encountered: