Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

How to save a layer to a image file #68

Open
velara3 opened this issue Nov 22, 2022 · 2 comments
Open

How to save a layer to a image file #68

velara3 opened this issue Nov 22, 2022 · 2 comments

Comments

@velara3
Copy link

velara3 commented Nov 22, 2022

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();
@pastelmind
Copy link
Collaborator

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.

@gcmartijn
Copy link

  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'))

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants