Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

How can I save mask data as png? #278

Open
Jamu2800 opened this issue Jan 3, 2023 · 0 comments
Open

How can I save mask data as png? #278

Jamu2800 opened this issue Jan 3, 2023 · 0 comments

Comments

@Jamu2800
Copy link

Jamu2800 commented Jan 3, 2023

I have created a PSD file like the one pictured below.
image

What we want to save this time is this mask data.
image

To save it, I created the following source code.

import { fromFile } from "psd"
import sharp from "sharp"

const psdData = fromFile("src/resource/test_psd.psd")
psdData.parse()
const treePSD = psdData.tree()
const mask = treePSD.children()[2].get("mask")
const imageData = treePSD.children()[2].get("image").maskData

sharp(imageData, {
  raw: {
    width: mask.width,
    height: mask.height,
    channels: 4
  }
}).png()
  .toFile("src/resource/test.png")

However, test.png was inverted to black and white.
test

I would like to know how to save without inverting black and white.
Thank you in advance.

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

No branches or pull requests

1 participant