"copy pasting" without using the actual clipboard


I need to copy paste my selection into another document, but I’m trying to not use the clipboard.

So I found the imaging API, using getSelection I could “copy” the image data.
Using putPixels I could then insert the selection back into a layer, I thought.
But I keep having an error:
“the target colourspace does not match the source data. A colour profile must be specified for the source data.”, so I tried setting the colour profile for the source (the ImageData received by getSelection), but that was readOnly, so didn’t work.

I thought, maybe use getPixels, but that wouldn’t make much sense in my eyes since I’d have to get the sourceBounds using getSelection then.

Another way could be to duplicate the selection into another document, I couldn’t get this working as Layer#duplicate duplicates the whole layer, and I couldn’t find something to remove an selection (I could selection invert → delete then)

I’m probably overthinking this or missing something, help is greatly appreciated!

How about copying selection to a new layer and then duplicating that into a new document?

Heya Timothy,
You mean using putPixels into a layer in the original’s document? And then using Layer#duplicate?
I can try!

For context, I’m writing a script which creates images in a certain format (and sometimes with removed background), this script worst case has do 100 images, so I’m trying to not use the users clipboard so they can focus on something else while the script does its thing. (so many images takes couple minutes)

Performance improvements are something for the future, most important is a working script that doesn’t interfere anyone atm.

Nah, I mean New Layer via Copy from the Layers drop-down menu - CTRL + J.
It copies the active layer (or selection) into a new layer in the existing document.
Then you duplicate the new layer into a new document.
No clipboard or image API.

1 Like

That works! Thanks sincerely for the help.

1 Like