Anonymous
Not applicable

 @Yan Chong Tan​ :

The error you are facing is due to the fact that you are trying to access the attribute "width" of a string object in the resize_image function. Specifically, input_dim is a string object, but you are trying to access its width attribute, which does not exist for strings.

To fix this error, you should first extract the width and height values from the input_dim struct using the

getField() method, like this:

input_width = input_dim.getField("width")
input_height = input_dim.getField("height")

Then, you can proceed with the rest of your code as before. Here's the modified resize_image function:

def resize_image(data, input_dim):
    input_width = input_dim.getField("width")
    input_height = input_dim.getField("height")
    output_width = input_width * 0.5
    output_height = input_height * 0.5
    img = Image.frombytes("RGB", [input_width, input_height], bytes(data))
    img = resizeimage.resize_cover(img, [output_width, output_height])
    img = np.asarray(img)
    img = bytearray(img)
    return img

This should resolve the issue you were facing.

View solution in original post