Navan Chauhan
1 minute readCreated on January 14, 2020Last modified on June 1, 2020

Converting between image and NumPy array

import numpy import PIL # Convert PIL Image to NumPy array img = PIL.Image.open("foo.jpg") arr = numpy.array(img) # Convert array to Image img = PIL.Image.fromarray(arr)

Saving an Image

try: img.save(destination, "JPEG", quality=80, optimize=True, progressive=True) except IOError: PIL.ImageFile.MAXBLOCK = img.size[0] * img.size[1] img.save(destination, "JPEG", quality=80, optimize=True, progressive=True)
Tagged with: