psd icon indicating copy to clipboard operation
psd copied to clipboard

How to save a layer to a image file

Open velara3 opened this issue 3 years ago • 2 comments

In the documentation it says you can export a layer to pixel data. How would you save that to a PNG? I'm using node js.

// Extract the pixel data of a layer, with all layer and layer group effects applied
var layerPixelData = await layer.composite();

velara3 avatar Nov 22 '22 14:11 velara3

After calling layer.composite() to extract the pixel data, you can either use the Canvas API (if you're in a web browser) or a library like pngjs to convert that to a PNG file.

pastelmind avatar Nov 23 '22 00:11 pastelmind

  let layerPixelData = await layer.composite()

    let png = new PNG({ width: layer.width, height: layer.height })
    png.data = Buffer.from(layerPixelData);
    png.pack().pipe(fs.createWriteStream('out.png'))

gcmartijn avatar Dec 06 '22 19:12 gcmartijn