Any way to get clipboard dimensions with transparency?

I have a program that needs to create a new document using whatever unknown image size is on the clipboard, and also to include the transparency. I can get the batchPlay to create a new doc with the clipboard size. However, Photoshop ignores empty space and creates the new document with the size excluding any surrounding transparency.

How I have treated similar situations is to fill single pixels in 2 diagonal corners at 1% opacity with 50% gray. At 1% opacity, in is more or less an invisible pixel and it then Photoshop will calculate the entire space of the selection or layer.

However, in this case, I’m wanting to use the clipboard from a user’s copy to clipboard so I can’t do the fill method. I am wondering if there is any possible way to obtain the full clipboard size, including the surrounding transparency?

Can you place bitmap into document mode that does not support transparency?

I need to keep the transparency and create a new doc with the same size and then paste (or Paste In Place) into the new document with the exact same transparency spacing.

It is easy to do if I have control over what is being copied, or if the clipboard dimensions were always the same. However, it this case I’m putting in a “Paste From Clipboard” button for the user and the dimensions and transparency will be whatever the user decides to copy to the clipboard ahead of time.

I mean temporary document just for that measurement. Perhaps with indexed color mode without transparency in table?

I just tried creating new 1 bit bitmap doc with the clipboard preset. It still makes the doc size the size of the clipboard minus the transparency.

Photoshop must know what the transparent spacing is on the clipboard however. If manually creating a new document of the same dimensions and using Paste In Place, it is able to place the image with the exact same transparent edge spacing as what was copied to the clipboard.

Again, this would be easy except I have no idea what the user will decide to copy and from where. I’m kind of thinking there isn’t a way to get the info.

How does pasting bitmap from clipboard works in web browsers?

Could you create a new document, paste, query the layer size, and then use that information to create a new document of the correct size (and do the paste again)?

(This assumes that the Paste operations can be triggered by batchPlay. @Barkin/@heewoo thoughts?)

I have already tried that. The paste, paste in place, and create new document from the clipboard presets all work fine with batchPlay. Also, batch play can be used to query the layer bounds which also works fine.

The issues isn’t with anything broken in UXP. It is just how Photoshop operates which I’m trying to find a workaround for. When creating a document from the clipboard, it creates the document size minus the transparency.

As an example, say the clipboard is 2400x3000 pixels and contains a person cutout and sized where the user wants within the transparency. Say the the actual size of the person cutout is 1500x2000. Creating a new document form the clipboard preset creates a document at 1500x2000, not 2400x3000. When pasted, the person takes up the entire space of the new document with no margins. When queried for layer bounds using batchPlay, it returns 1500x2000, not 2400x3000.

Photoshop behaves the same way doing everything manually so I don’t think anything in UXP performs differently than it should. However, the information for transparency spacing must be buried somewhere in the clipboard. From the same sizes from the prior example, if a document is manually created at the correct size of 2400x3000 and “paste in place” is used, it will place the cutout of the person in the exact correct location. So paste in place somehow knows what the surrounds extra space is.

I have other programs I have created that can easily work around this. If if the size of the document where the cutout comes from is known, then a new doc can be created at the same size. Then paste in place can be used with no issues. However, in this specific case for this new program, I’m wanting to give the user a “paste from clipboard” option so they can copy/paste from their other documents. With this, the program has no way to know what the original size of the document they copied from was. As this information seems to be stored somewhere on the clipboard, I was trying to figure out if there was a way to query that from the clipboard.

Oh, now I see what you’re trying to do. I’m not sure I see a reasonable* path forward at this point in time since you’d need access to the image data itself (or something else on the clipboard, if it’s being added as some sort of custom metadata).

* an unreasonable path is a helper app that can inspect all the contents of the clipboard and the communicate that to the plugin via websockets or the like. But that seems a bit over the top.

OK, thanks for confirming what I thought. I think I’ll pass on the helper app. That sounds like too much extra work :slight_smile: It’s not mission-critical. I’ll just tell users they can only use images with transparency from the “load from file” button. Most use cases don’t involve transparency anyway. Maybe in the future there will be an easier way to access the data.