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 to export a psd to png or jpg ? #177

Open
826327700 opened this issue May 27, 2024 · 3 comments
Open

How to export a psd to png or jpg ? #177

826327700 opened this issue May 27, 2024 · 3 comments
Assignees

Comments

@826327700
Copy link

I didn't get clear instructions in the documentation how to export psd to image, hope someone can tell me。

@Agamnentzar
Copy link
Owner

You can save psd.canvas, in browser it's regular HTMLCanvasElement ( https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement ) and in node it's node-canvas canvas object ( https://github.com/Automattic/node-canvas?tab=readme-ov-file#non-standard-apis )

The PSD document is not guaranteed to have composite image saved in it, most documents have it though.

@Agamnentzar Agamnentzar self-assigned this May 27, 2024
@826327700
Copy link
Author

您可以保存psd.canvas,在浏览器中它是一个常规的 HTMLCanvasElement(https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement),在节点中它是一个 node-canvas 画布对象(https://github.com/Automattic/node-canvas?tab=readme-ov-file#non-standard-apis)

PSD文档不保证其中保存有复合图像,但其它文档都有。

I have tried using the following code but the psd.canvas is empty

import { readPsd } from 'ag-psd';
import 'ag-psd/initialize-canvas'; 

let buf=fs.readFileSync('xxxx.psd');
const psd = readPsd(buf.buffer,{ skipLayerImageData: true, skipCompositeImageData: true, skipThumbnail: true });
console.log("======",psd.canvas);//-->undefined

@Agamnentzar
Copy link
Owner

skipCompositeImageData: true option skips reading psd.canvas fields, you need to remove it.

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

2 participants