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

Text content updated in PSD layer object but image remains unchanged #174

Open
AsiF-Py opened this issue Apr 30, 2024 · 1 comment
Open
Assignees

Comments

@AsiF-Py
Copy link

AsiF-Py commented Apr 30, 2024

I encountered an issue while using the ag-psd library in Node.js to programmatically update text content in a PSD file. Despite successfully updating the text content in the PSD layer object, the image remains unchanged after saving the modified PSD file.

Here's the relevant code snippet:

import * as fs from 'fs';
import 'ag-psd/initialize-canvas.js';
import { readPsd, writePsdBuffer } from 'ag-psd';

const buffer = fs.readFileSync('UK DL FRONT.psd');
const psd = readPsd(buffer);

const kumonLayer = psd.children[4].children.find(layer => layer.name === 'KUMON');

if (kumonLayer) {
    kumonLayer.text.text = 'MD. Asif';
    console.log('Updated text content:', kumonLayer.text.text);
    console.log('Updated layer:', kumonLayer.name);

    const modifiedBuffer = writePsdBuffer(psd);
    fs.writeFileSync('modified_UK_DL_FRONT.psd', modifiedBuffer);
    console.log('Text for KUMON layer updated successfully.');
} else {
    console.log('Layer with name "KUMON" not found.');
}

Expected behavior:

I expect that when I update the text content of the PSD layer object and save the modified PSD file, the image in the PSD file should also reflect the changes made to the text content.

Actual behavior:

After running the above code, the text content in the PSD layer object (kumonLayer.text.text) is updated successfully, but when I open the modified PSD file, the image remains unchanged. It seems like the changes made to the layer object are not reflected in the saved PSD file.

@Agamnentzar
Copy link
Owner

The library will not redraw the text layer for you, you need to provide the new bitmap yourself in layer.canvas, see more here:
https://github.com/Agamnentzar/ag-psd?tab=readme-ov-file#updating-text-layers

@Agamnentzar Agamnentzar self-assigned this Apr 30, 2024
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