From 81ae1cfaf44f9f188e35936a660e82a4e9af238e Mon Sep 17 00:00:00 2001 From: Navan Chauhan Date: Tue, 14 Jan 2020 23:03:43 +0530 Subject: Publish deploy 2020-01-14 23:03 --- posts/2020-01-14-Converting-between-PIL-NumPy/index.html | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 posts/2020-01-14-Converting-between-PIL-NumPy/index.html (limited to 'posts/2020-01-14-Converting-between-PIL-NumPy') diff --git a/posts/2020-01-14-Converting-between-PIL-NumPy/index.html b/posts/2020-01-14-Converting-between-PIL-NumPy/index.html new file mode 100644 index 0000000..fb685a2 --- /dev/null +++ b/posts/2020-01-14-Converting-between-PIL-NumPy/index.html @@ -0,0 +1,15 @@ +Converting between image and NumPy array | Navan Chauhan
🕑 0 minute read.

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:
\ No newline at end of file -- cgit v1.2.3