After receiving the information in base64 in my Python application, I save it to an image and check that the selected object is shown three times in the same image and not in the expected place.
Any idea of whatĀ“s happening or how to solve it?
Can you be more specific about what you mean by āsave it to an imageā? I.e. how do you turn the raw pixel data, returned by the imaging API into a .png file?
Maybe to avoid adding this extra phase of loading the data in python and save it to a file, it is OK to copy the value of āmaskā in a page as: Base64 to Image | Base64 Decode | Base64 Converter | Base64 and I get the same result, the image painted three times.
Without actually knowing the problem youāre trying to solve eventually, have you considered not going through the imaging API and instead saving the document (or cropped document) directly as .png (I.e. let Photoshop do what itās pretty great at)? That way you donāt have to deal with handling raw pixel data (and pixel channel ordering).
I cannot solve it that way, because I need to send the information and not saving the output locally.
What IĀ“m trying to do is: select an object in the image, get the selection and convert it to base64.
Ah, gotcha. In that case, think itās just important to understand that what gets returned by the imaging API is raw pixel data, i.e. a flat array of just numbers in a particular order (e.g. all values of the red channel, followed by all values of the green etc. depending on the options you pass). So youāre on the hook to interpret that data correctly later on. The image on the right looks suspiciously like all the channels concatenated horizontally (i.e. misinterpreting the flattened pixel data). To debug I would check the dimensions (width/height) and number of channels (components) at every step in your process, to figure out where the error happens.
I print some information regarding selection.imageData:
W: 32 H: 32, Type: image/uncompressed
Colour space: Grayscale, profile: Gray Gamma 2.2, has alpha: false
Pixel format: Grayscale
Components per pixel: 1, component size (bits): 8
Is chunky: false
so I assume there is only one channel.
Also, I have checked that the size of the result of this:
const data = await selection.imageData.getData();
includes a 1024 Uint8Array (1024 = 32 x 32) so I assume that each element in the array corresponds to one pixel.
So I still donĀ“t understand why the image is repeated several times.
Thanks.
Hi!
I couldnāt manage to get the expected result by directly using the one-channel image from the selection and the Grayscale profile so I replicated each value in the selection image three times in a new image and used the RGB profile. This way, I managed to obtain the expected result.
I add some code that maybe useful to identify the order of the replicated values: