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

Replace layer image #122

Open
HediMlika opened this issue Dec 23, 2017 · 1 comment
Open

Replace layer image #122

HediMlika opened this issue Dec 23, 2017 · 1 comment

Comments

@HediMlika
Copy link

HediMlika commented Dec 23, 2017

I have two layers and I want to replace the second layer's image and save the output as PNG

{ children:
   [ { type: 'layer',
       visible: true,
       opacity: 1,
       blendingMode: 'normal',
       name: 'Layer 1',
       left: 0,
       right: 0,
       top: 0,
       bottom: 0,
       height: 0,
       width: 0,
       mask: [Object],
       text: undefined,
       image: {} },
     { type: 'layer',
       visible: true,
       opacity: 1,
       blendingMode: 'normal',
       name: 'Layer 2',
       left: 0,
       right: 1000,
       top: 0,
       bottom: 665,
       height: 665,
       width: 1000,
       mask: {},
       text: undefined,
       image: {} } ],
  document:
   { width: 1000,
     height: 665,
     resources: { layerComps: [], guides: [], slices: [] } } }

I have tried doing it this way but the image is not being replaced.

const PSD = require("psd");
const fs = require("fs");

fs.readFile("new_image.png", (err, data) => {
    if (err) throw err;
    let new_buffer = data;
    let psd = PSD.fromFile("./file.psd");
    psd.parse();
    psd.tree().descendants()[1].layer.file.data = new_buffer;
    png = psd.image.toPng();
    psd.image.saveAsPng('out.png').then(() => console.log('Exported!'));
});
@gamegee
Copy link

gamegee commented Jan 17, 2018

Hi @HediMlika the purpose of this project is only to parse psd files. So unfortunately you can't update the psd tree.
The idea of updating a PSD file through JS is really cool, but it probably need a lot of work.

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