not sure if thats what you are looking for:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Feb 4 17:10:02 2021
@author: Pietro
"""
from PIL import Image
import numpy as np
new_pixels = np.array([
(255, 0, 0, 255),
(0, 255, 0, 255),
(0, 0, 255, 255),
(0, 0, 0, 255)
]).astype('uint8')
new_pixelsRGBA = np.array([[
[255, 0, 0, 255],
[0, 255, 0, 255],
[0, 0, 255, 255],
[0, 0, 0, 255]]
]).astype('uint8')
new_pixelsRGBA2 = np.array([[
[255, 0, 0, 255],
[0, 255, 0, 255]],
[[0, 0, 255, 255],
[0, 0, 0, 255]]
]).astype('uint8')
pippo = Image.fromarray(new_pixels)
pippoRGBA = Image.fromarray(new_pixelsRGBA, mode='RGBA')
# pippoRGBA = Image.fromarray(new_pixelsRGBA)
print('pippo image size : ', pippo.size)
print('pippo image mode : ', pippo.mode)
pippo.show()
print('pippoRGBA image size : ', pippoRGBA.size)
print('pippoRGBA image mode : ', pippoRGBA.mode)
pippoRGBA.show()
pippoRGBA2 = Image.fromarray(new_pixelsRGBA2)
print('pippoRGBA2 image size : ', pippoRGBA2.size)
print('pippoRGBA2 image mode : ', pippoRGBA2.mode)
pippoRGBA2.show()
the image I got is:
pippo image size : (4, 4)
pippo image mode : L : (8-bit pixels, black and white)
Apparently your array is not a RGBA pixel array ?! Or not ?
using my new_imageRGBA or new_imageRGBA2 array see above I got:
pippoRGBA image size : (4, 1)
pippoRGBA image mode : RGBA
or (pippoRGBA2 image):
pippoRGBA2 image size : (2, 2)
pippoRGBA2 image mode : RGBA
note that :
pippoRGBA = Image.fromarray(new_pixelsRGBA)
works as well; PIL knows we are talking about RGBA array