imageBufferToPngDataUrl Function
Produces a data url in "image/png" format from the contents of an ImageBuffer.
imageBufferToPngDataUrl(buffer: ImageBuffer, preserveAlpha: booleantrue): string | undefined
@returns  a data url as a string suitable for setting as the src property of an HTMLImageElement, or undefined if the url could not be created.
| Parameter | Type | Description | 
|---|---|---|
| buffer | ImageBuffer | The ImageBuffer, of any format. | 
| preserveAlpha | boolean | If false, the alpha channel will be set to 255 (fully opaque). This is recommended when converting an already-blended image (e.g., one obtained from readImageBuffer). | 
Returns - string | undefined
a data url as a string suitable for setting as the src property of an HTMLImageElement, or undefined if the url could not be created.
Defined in
Last Updated: 24 June, 2025
Found something wrong, missing, or unclear on this page? Raise an issue in our repo.