SVG does not render embedded image with a dimension greater than 10000 pixels
"After upgrading from version 0.33.4 to 0.33.5 of the sharp library, the memory leak issue has been resolved, but there are rendering failures with high-resolution images."
sharp(imgBuffer, { unlimited: true }) .toFormat(type) .withMetadata({ density: dpi, icc: colourspace } as any) .toBuffer((err, data) => {
})
the memory leak issue has been resolved,
I don't know what this refers to, please can you provide more details.
there are rendering failures with high-resolution images.
Please can you provide complete information that allows someone else to reproduce. This will include complete, standalone code and a sample image.
When a certain Base64 is too large, the image generated by sharp will be missing this layer.
code like: `const svgString = ''; const imgBuffer = Buffer.from(svgString) sharp(imgBuffer, { unlimited: true }) .toFormat(type) .withMetadata({ density: dpi, icc: colourspace } as any) .toBuffer((err, data) => {
})`
When size of an image in an SVG is too large, version 0.33.5 of Sharp will fail (version 0.33.4 is OK) to render that image during the conversion process. @lovell
demo code(the path should change to your local path) ` const sharp = require('sharp') const fs = require('fs')
// Example function to convert SVG buffer to PNG async function convertSvgToImage(svgBuffer, outputFormat = 'png', outputPath) { try { const imageBuffer = await sharp(svgBuffer).toFormat(outputFormat).toBuffer()
// Write the output image buffer to a file
fs.writeFileSync(outputPath, imageBuffer)
console.log(`Image successfully written to ${outputPath}`)
} catch (err) { console.error('Error converting SVG to image:', err) } }
// Example usage ;(async () => { try { // Read SVG file into a buffer const svgBuffer = fs.readFileSync('./method-draw-image.svg')
// Convert SVG buffer to PNG and save it as a file
await convertSvgToImage(Buffer.from(svgBuffer), 'png', 'output-image.png')
} catch (err) { console.error('Error:', err) } })()`
This is probably related to the upstream librsvg issue at https://gitlab.gnome.org/GNOME/librsvg/-/issues/1093
The latest release of librsvg was 9 years ago. How can this issue be fixed using Sharp? Are there any specific solutions? @lovell
The latest release of librsvg was 9 years ago.
There's a new release of librsvg every month or so, please see https://gitlab.gnome.org/GNOME/librsvg/-/tags
The prebuilt binaries provided by sharp always use the most recent version of librsvg available at that point in time. You can view the version you are using via sharp.versions.rsvg.
Please subscribe to the upstream issue at https://gitlab.gnome.org/GNOME/librsvg/-/issues/1093 for updates about this specific problem.