Resize svg and output png file
See original GitHub issueI am sorry if it is obvious or has been answered before, but this code
await sharp(new Buffer(layersWithSvg[0].icon_svg))
.resize(100, 100)
.png()
.toFile('./assets/icon.png')
for icon_svg with metadata
{ format: 'svg',
width: 16,
height: 16,
space: 'srgb',
channels: 4,
density: 72,
hasProfile: false,
hasAlpha: true }
outputs very poor quality png. Seems like it is scaling rasterized svg. How to scale svg and convert to png correctly?
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Resize SVG Online - Free SVG Resizer Tool - Pixelied
Resize SVG files online without editing their HTML code. With Pixelied, you can adjust the dimensions of SVG images in under a minute,...
Read more >Free Online Resize SVG Images with High output Quality
Just upload your SVG image, choose a size and resampling type to get the resized image in desired format for free from any...
Read more >Resize & Convert SVG to PNG (Online) with myScale - Hongkiat
Upload your .svg file. · Input the width in pixels (maintains the aspect ratio automatically). · Click “Generate” to preview the output, then ......
Read more >How to resize a SVG image - Medium
Open the SVG file with your text editor. It should show lines of code as below. ... As you can see, width and...
Read more >Resize many SVG vector images online for free - iLoveIMG
Resize SVG images for free. Change SVG dimensions in batch to optimize them for your website. Resizing SVG vectors maintaining the quality!
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hello, by default the SVG will be rendered at a density of 72DPI, which the metadata for this image suggests will be 16x16. Then
resize(100, 100)
will resize the 16x16 to 100x100, hence the problem you’ve encountered.You can set the
density
parameter on the constructor to increase the size of the initial rendering.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.
@lovell Thanks again, it halved sprite generation time, you are the best.