How to resize PhotoshopImageData

Hi everyone,

Currently, I am using the Imaging API to develop my own plugin, mainly for background removal. I have obtained the image of the layer and converted it to base64 format to send it to my API. I have successfully received the buffer returned by the API and used the createImageDataFromBuffer function to convert it to a gray imageData. I have also successfully called putSelection to select the desired area.

However, I have encountered a problem. If the resolution of the image is too high, I need to reduce its size before sending it out in the getPixels function by setting the sourceBounds.

But I don’t know how to resize the returned mask to match the original image size.

I’ve been searching all day, but there is limited information available on imaging-related topics. I hope to get some help from everyone here. Thank you!

ref: https://developer.adobe.com/photoshop/uxp/2022/ps_reference/media/imaging

I solve it in a weird way on my own.

I first put the smaller selection using putSelection, and then resize it to the size of the original image’s selection using the targetSize from getSelection (requiring special calculation), and put the selection again.