How to read / write a single layer's content of the activated document in real-time?

Hey Guys, I’m currently working on a PS UXP plugin containing a backend, and I need to read/update the layer content each time the front-end (I mean, the plugin) submit a request and received the new processed results. But the processing time is tooooo long…

Now for reading a layer to memory, I can only do this by:

  1. hide all layers except the selected layer by layer.visible = false
  2. save the whole document to a file by
  3. read the file to memory by{format:})

And for loading the received image to layer, the process is similar:

  1. save the image binary to a file by storage.file.write(image)
  2. open the image in a new temp document by tempDoc =
  3. extract the new layer to the main doc by tempDoc.layers[0].duplicate(mainDoc)

This is really a low efficient way, especially when the back and forth need to be repeated many times and it could be worse if the opened document contains nearly 10 layers. The user has to wait for 5 or even more than 10 seconds for every request until all layers have been created or updated (that will be annoying to users :sweat_smile:).

I looked at the UXP document but seen there is not such an API could read or write layer easily. And I also searched here but nothing found. Can anyone give me some help or suggestion on this issue?

I think your approach is the only possible one to date. In the last developer meeting the team foreshadowed that some kind of imaging API will come in the future, providing better ways to read and write pixel data. There’s no date for that though, so we’ll have to wait patiently :slight_smile:

Thanks anyway, at least I know I should try in other directions to solve my problem :sweat_smile: