diff --git a/example/index.js b/example/index.js index 9a41ba0f..16ec0fc8 100644 --- a/example/index.js +++ b/example/index.js @@ -28,7 +28,10 @@ async function main() { const pngBuffer = pngData.asPng() console.info('Original SVG Size:', `${resvg.width} x ${resvg.height}`) - console.info('Output PNG Size :', `${pngData.width} x ${pngData.height}`) + // console.info('Output PNG Size :', `${pngData.width} x ${pngData.height}`) + // console.info('pixmap :', `${pngData.pixel}`) + + console.info(typeof pngData.pixel) console.info('✨ Done in', performance.now() - t, 'ms') await promises.writeFile(join(__dirname, './text-out.png'), pngBuffer) diff --git a/js-binding.d.ts b/js-binding.d.ts index 1e21cb98..21aac1e5 100644 --- a/js-binding.d.ts +++ b/js-binding.d.ts @@ -43,6 +43,8 @@ export class Resvg { export class RenderedImage { /** Write the image data to Buffer */ asPng(): Buffer + /** Get Pixmap */ + get pixel(): Buffer /** Get the PNG width */ get width(): number /** Get the PNG height */ diff --git a/src/lib.rs b/src/lib.rs index 205b1d6b..8490fe53 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -107,6 +107,20 @@ impl RenderedImage { Ok(buffer.as_slice().into()) } + /// Get pixel data + #[cfg(target_arch = "wasm32")] + pub fn pixel(&self) -> js_sys::Uint8Array { + self.pix.data().into() + } + + /// Get pixel data + #[cfg(not(target_arch = "wasm32"))] + #[napi(getter)] + pub fn pixel(&self) -> Result { + let buffer = self.pix.data(); + Ok(buffer.into()) + } + #[cfg(not(target_arch = "wasm32"))] #[napi(getter)] /// Get the PNG width