Hello all,
I’m currently playing with the imaging API and I’m facing an issue I do not understand. After retrieving a PhotoshopImageData with the getPixels method, I am currently trying to save the related data as a png file (but the png file is currently inoperable).
I also tried with the exportSelectionAsFileTypePressed action (batchPlay), but that do not seem to be supported anymore (photoshop 24.7).
As a side note, fixing this issue will prevent me from using document/layer methods (crop, bringToFront, suspendHistory…) to properly export layers as png files.
From what I see. The bitmap is not converted to PNG. You should convert bitmap to PNG in first place and then save it. It will not do the conversion automatically.
BMP has a header that you do not save. That is why it can’t open. Try File → Open as → Raw.
Since it does not have header you will need to fill dialog correctly.
Have you considered creating a blank Photoshop document, dropping your image data there and then do a document save (all programmatically of course)? Photoshop does have the smarts to convert to different file types for its own documents as part of a save/export, but as far as I know ‘fs’ is only meant to write raw binary or text data and you’d be on the hook to essentially compose the PNG file with file header etc. like @Jarda mentioned.
This line here only ensures that the filename contains ‘.png’:
This line here only tells ‘fs’ to interpret your data array as binary data. Unless your array is structured as .png file with header etc. you’re not gonna automatically get that:
Thank you @dotproduct for your answer. I already tried that (and I shared the generated bmp file above, if you would like to test it).
I understand all of what you are saying, but I do not have any solution to tackle this issue properly (if it is from code, it would be better). Do you have any?
I guess what I mean is not to generate a bmp file (and read that back in). Rather I would try creating a clean/blank document, make that your current document and drop your image data into it (via Imaging API’s putPixels) and then use a document save. This new document would just be a sidecar file, just for the purpose of saving out your pixels, you can close it once done, no nead for any undo, etc.
Hi @maxplaystudios , well, on my side, I also tried a lot of things (app permissions…) & didn’t get any errors. So I thought this would not work anymore (and I do not remember any official documentation about it.).
Aha! I did get it to work! And it was both unintuitive and obvious…
I had to create a session token for the folder I was exporting to, even if I was not going to pass the token to the command. Even though I have full access enabled in the manifest. Once I opened a session token, it exported to the target folder just fine.