Explorar el Código

remove deprecated py 'PIL' module 'fromstring', 'tostring' method call (removed from 'PIL' module version >= 8.0.0) (#1223)

Tomas Zigo hace 4 años
padre
commit
3ba94fa958

+ 1 - 2
gui/wxpython/animation/utils.py

@@ -265,8 +265,7 @@ def RenderText(text, font, bgcolor, fgcolor):
 def WxImageToPil(image):
     """Converts wx.Image to PIL image"""
     pilImage = Image.new('RGB', (image.GetWidth(), image.GetHeight()))
-    getattr(pilImage, "frombytes", getattr(pilImage, "fromstring"))(
-        bytes(image.GetData()))
+    pilImage.frombytes(bytes(image.GetData()))
     return pilImage
 
 

+ 4 - 24
gui/wxpython/core/utils.py

@@ -1044,39 +1044,19 @@ def PilImageToWxImage(pilImage, copyAlpha=True):
         wxImage = EmptyImage(*pilImage.size)
         pilImageCopyRGBA = pilImage.copy()
         pilImageCopyRGB = pilImageCopyRGBA.convert('RGB')    # RGBA --> RGB
-        fn = getattr(
-            pilImageCopyRGB,
-            "tobytes",
-            getattr(
-                pilImageCopyRGB,
-                "tostring"))
-        pilImageRgbData = fn()
-        wxImage.SetData(pilImageRgbData)
-        fn = getattr(
-            pilImageCopyRGBA,
-            "tobytes",
-            getattr(
-                pilImageCopyRGBA,
-                "tostring"))
+        wxImage.SetData(pilImageCopyRGB.tobytes())
         # Create layer and insert alpha values.
         if wxPythonPhoenix:
-            wxImage.SetAlpha(fn()[3::4])
+            wxImage.SetAlpha(pilImageCopyRGBA.tobytes()[3::4])
         else:
-            wxImage.SetAlphaData(fn()[3::4])
+            wxImage.SetAlphaData(pilImageCopyRGBA.tobytes()[3::4])
 
     else:    # The resulting image will not have alpha.
         wxImage = EmptyImage(*pilImage.size)
         pilImageCopy = pilImage.copy()
         # Discard any alpha from the PIL image.
         pilImageCopyRGB = pilImageCopy.convert('RGB')
-        fn = getattr(
-            pilImageCopyRGB,
-            "tobytes",
-            getattr(
-                pilImageCopyRGB,
-                "tostring"))
-        pilImageRgbData = fn()
-        wxImage.SetData(pilImageRgbData)
+        wxImage.SetData(pilImageCopyRGB.tobytes())
 
     return wxImage
 

+ 1 - 1
lib/python/imaging/images2gif.py

@@ -792,7 +792,7 @@ class NeuQuant:
 
         # Initialize
         self.setconstants(samplefac, colors)
-        self.pixels = np.fromstring(getattr(image, "tobytes", getattr(image, "tostring"))(), np.uint32)
+        self.pixels = np.fromstring(image.tobytes(), np.uint32)
         self.setUpArrays()
 
         self.learn()

+ 1 - 2
lib/python/imaging/images2swf.py

@@ -169,8 +169,7 @@ class BitArray:
         return self._len  # self.data.shape[0]
 
     def __repr__(self):
-        fn = getattr(self.data[:self._len], "tobytes", getattr(self.data[:self._len], "tostring"))
-        return fn().decode('ascii')
+        return self.data[:self._len].tobytes()
 
     def _checkSize(self):
         # check length... grow if necessary