I got this Error :
Traceback (most recent call last): File "/home/runner/Image-Loader/venv/lib/python3.8/site-packages/PIL/Image.py", line 2992, in fromarray mode, rawmode = _fromarray_typemap[typekey] KeyError: ((1, 1, 5), '|u1')
Here is my code :
img = Image.open(f"IMG/{thumb[0]}_{thumb[1]}x{thumb[1]}.png")
height,width = img.size
lum_img = Image.new('L', [height,width] , 0)
draw = ImageDraw.Draw(lum_img)
draw.pieslice([(0,0), (height,width)], 0, 360, fill = 255, outline = "white")
img_arr =np.array(img)
lum_img_arr =np.array(lum_img)
final_img_arr = np.dstack((img_arr,lum_img_arr))
im = Image.fromarray(final_img_arr)
im.save("filename.png")
I want a script who open an image and I want to crop in circle the image like they do here : https://www.geeksforgeeks.org/cropping-an-image-in-a-circular-way-using-python/. But when I want to save my Image, I got the error. Can someone help me please ?
The pixel format of
imgis RGBA and not RGB.Replace
Image.open(f"IMG/{thumb[0]}_{thumb[1]}x{thumb[1]}.png")with:Because pixel format is RGBA, there are 4 color channels instead of 3 (the
Achannel applies "Alpha" transparency channel).The result of
final_img_arr = np.dstack((img_arr,lum_img_arr))is 5 "color channels" instead of 4 channels, and 5 channels is does not apply a valid image format.We my verify that the number of channels is valid by printing the shape of
final_img_arrbefore saving:print(final_img_arr.shape)Make sure that the shape is
(height, width, 4)