-
Notifications
You must be signed in to change notification settings - Fork 73
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
Why isnt it forcing Photoshop to reload the new text? #172
Comments
You have to open the file in actual Photoshop to redraw the text layers, neither |
The code was working perfectly fine. Now what im trying to say is that when i opened the file on Photoshop it still hadn't updated to the new text, and the code used to do that |
I don't see how this could have ever worked, unless |
I dont see neither, but apart from me i saw a guy do it too. But forget about exporting the image, focus on the PSD, when I open the new PSD to check if it has updated the text it hasn't updated |
Do you see this popup when you open the files in Photoshop? You can also check this file that definitely shows the popup for me: |
nope, i dont see that pop up, and thanks for that file ill check it right now. Btw do you have a script that edits the text of a PSD file while also using invalidateTextLayers: true? because maybe i can use it as a template for what im coding and maybe it would work. |
I'm using this in tests: const buffer = fs.readFileSync('text-replace2.psd');
const psd = readPsd(buffer), {});
psd.children[1].text.text = 'Foo bar';
const output = writePsdBuffer(psd, { invalidateTextLayers: true });
fs.writeFileSync('out.psd', output); |
can you check out if this code works for you? initializeCanvas(createCanvas); |
Did you see the popup for the file I sent? If not you might have dismissed it permanently or maybe your version of photoshop changed the way it works. If you dismissed it you might need to re-enable the popup in photoshop settings, but I don't know how to do that. |
did my code worked for you? |
Yes, that code works for me |
and the result of that code is still foo bar? |
The popup shows correctly in photoshop and after confirming I get the new text |
ok, ill try to implement that now with exporting images but im really confused |
|
If you need to update text layer, you need to redraw it yourself, which means you need to re-implement entire text rendering engine of Photoshop, you could just reimplement small part that you need or try to find some other library that implements it. |
and how can i reimplement a small part? |
If you only need to redraw simple text you can probably use canvas api for that, if you need something more complex you'd have to code it yourself. |
how can it be done with canvas api? sorry if im asking to be spoonfed but i usually have problems reading the docs |
You can see canvas api here: https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API And drawing text here: https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Drawing_text |
well i dont need to draw a text on anything, but to edit the text from a PSD template and then convert it to image, sadly i dont know how i made it work |
that doesnt happens in photopea |
I am also working on this feature, have you resolved it? |
I had a version of the code who used to work like intended but now it doesnt works like i intended, what could i be doing wrong here?
`const fs = require('fs');
const { readPsd, writePsd, updateLayerText, writePsdBuffer } = require('ag-psd');
const { createCanvas } = require('canvas');
const { initializeCanvas } = require('ag-psd');
initializeCanvas(createCanvas);
// Read the PSD
const buffer = fs.readFileSync('input.psd');
const psd = readPsd(buffer);
// Find the layer to update
const layerToUpdate = psd.children.find(layer => layer.name === 'Reemplazar_1');
// Update the layer text
if (layerToUpdate && layerToUpdate.text) {
layerToUpdate.text.text = 'No Reemplazar';
}
// Write the updated PSD to a new file
const updatedPsdBuffer = writePsd(psd, { invalidateTextLayers: true });
fs.writeFileSync('output.psd', updatedPsdBuffer);;
// After modifying the PSD
const PSD = require('psd');
PSD.open('output.psd').then(function (psd) {
return psd.image.saveAsPng('modified.png');
}).then(function () {
console.log('PSD converted to PNG successfully!');
});
// // Log the properties of all layers
// function logLayerProperties(layer) {
// console.log(layer);
// if (layer.children) {
// layer.children.forEach(logLayerProperties);
// }
// }
// logLayerProperties(psd);
The problem seems related to
invalidateTextLayers: trueor
fs.writeFileSync(...)` but i have tried changing both and nothing works right now.The text was updated successfully, but these errors were encountered: