Open yjutard opened 6 months ago
I haven't used ImageData, so resvg-js is mostly missing ImageData.colorSpace
and the Uint8ClampedArray needed for ImageData.data
?
Note: This structure is available in the node-related canvas library. https://github.com/Brooooooklyn/canvas/blob/a6b5cc4a45e2b58d7576ee413eff156f394511ff/index.d.ts#L169-L186
resvg currently always uses the sRGB color space. See: https://github.com/RazrFalcon/resvg/issues/629
Please see that having #304 is the solution to your needs?
ping @yjutard
Thanks @yisibl I was able to convert resvg's output to ImageData without effort:
const renderedImage = resvg.render();
const imageData = { // https://developer.mozilla.org/en-US/docs/Web/API/ImageData
width: renderedImage.width,
height: renderedImage.height,
colorSpace: 'srgb', // let's try...
data: renderedImage.pixels,
};
let { top, right, bottom, left } = getTrimEdges(imageData); // it works! (npm lib trim-image-data)
So it seems the current "pixels" format is OK ✅
My comment was about the data shape. Instead of inventing a new one, suggestion to use a "standard" one.
All good, not critical since the conversion is trivial. This issue can serve as doc. Feel free to close it!
Hi, thanks for this lib that looks great! (I'm still evaluating)
I'm trying to pass the output to another lib, which requires an ImageData input:
Looking at the output of resvg-js, it looks extremely similar:
My suggestion is to switch the output of resvg-js to the standard API ImageData or provide a conversion function, ex.
toImageData()