Agamnentzar / ag-psd

Javascript library for reading and writing PSD files
Other
496 stars 66 forks source link

program error on opening modified psd file #149

Closed krishankanhaya closed 6 months ago

krishankanhaya commented 1 year ago

import fs from 'fs'; import { readPsd, writePsd } from "ag-psd"; import { writePsdBuffer } from "ag-psd"; // for writing into psd files

// test 1 const inputBuffer = fs.readFileSync("card.psd");

const psd = readPsd(inputBuffer, { skipLayerImageData: true, skipCompositeImageData: true, skipThumbnail: true }); psd.children[1].children[3].children[0].children[2].text.text = 'new text'; // ere i change my layers text console.log(psd.children[1].children[3].children[0].children[2].text.text); // new text const buffer = writePsdBuffer(psd); fs.writeFileSync("my-file.psd", buffer); // saved file is could not open due to program error : why?

Agamnentzar commented 1 year ago

If you use skipLayerImageData: true, skipCompositeImageData: true, skipThumbnail: true options then the data will be missing for writing and entire document will have no image data. The document would be empty when you open it in Photoshop. Although it's still an error in ag-psd that you can't open it, I'll have to check that.

Agamnentzar commented 1 year ago

Also be aware of the limitations of this library specified here: https://github.com/Agamnentzar/ag-psd#modifying-documents

And specifically regarding to text layers: https://github.com/Agamnentzar/ag-psd#updating-text-layers

Agamnentzar commented 1 year ago

I tried similar modification on my test file and couldn't reproduce your error, would it be possible for you to share the PSD that you had issue with?

krishankanhaya commented 1 year ago

sorry for late reply, here is the download link https://drive.google.com/file/d/1ME29MXw1AEcyagKEsFDJzXunuymoa1_C/view?usp=sharing

pos : i want to update the text and save as copy and also want to update image inside it. is this possible with ag-psd?

Agamnentzar commented 1 year ago

@krishankanhaya ag-psd will not update the text layer image for you and it will not update composite image, you can update them yourself by replicating how photoshop draws text, which might be each for simple cases but very hard for more complex cases. ag-psd on reads and writes data to PSD files, it expects the user to provide all of the bitmaps, so you can't use it for changing and then rendering a document.