Repository: kivy/kivy

Issue:
Error: fromstring() in core/image/img_pil.py
Platform: Linux (OpenSuse, Ubuntu)

[INFO   ] [Kivy        ] v1.9.1
[INFO   ] [Python      ] v2.7.12 (default, Jul 01 2016, 15:36:53) [GCC]

Error:
  File "/usr/lib64/python2.7/site-packages/kivy/core/image/img_pil.py", line 105, in save
    image = PILImage.fromstring(fmt.upper(), (width, height), pixels)
  File "/usr/lib64/python2.7/site-packages/PIL/Image.py", line 2063, in fromstring
    "Please call frombytes() instead.")
Exception: fromstring() has been removed. Please call frombytes() instead.


In File "/usr/lib64/python2.7/site-packages/kivy/core/image/img_pil.py"
Line 105:
image = PILImage.fromstring(fmt.upper(), (width, height), pixels)

use...

image = PILImage.frombytes(fmt.upper(), (width, height), pixels)


Discussion:
Looks like an easy fix. Can you add an example to test this?

There is no easy example.... core.image save some image data string should do it....
https://groups.google.com/forum/#!topic/tilestache/bohED5JiHkI

Its just a simple maintenance of issue in "/usr/lib64/python2.7/site-packages/kivy/core/image/img_pil.py" that is not keeping up with deprecate calls, or the undocumented features of Pillow 3.x. Like it will now throw up an exception for "tostring()" and "fromstring()". 

Prehaps all that is required is an exception trap so when or if according to version an exception thrown up by Pillow for fromstring(), then to use frombytes(). Same for any pillow implantation by kivy for tostring(). If the user has an earlier version of Pillow 2.x it will pass it off with a warning msg of a soon to be deprecate call.   

If your read "http://pillow.readthedocs.io/en/3.1.x/reference/Image.html" documentation it is is almost as fuzzy as the kivy core.image image data implementation ;)

http://pillow.readthedocs.io/en/3.1.x/releasenotes/index.html

"
Deprecated Methods

Several methods that have been marked as deprecated for many releases have been removed in this release:

Image.tostring()
Image.fromstring()
...
"

Never tried this before, but I've put in a pull request for changed version with exception trap?

@steve1805 I cant see the pull request you are talking about. Can you link to the pull request here or mention this issue(# 4710) in that thread  so github automatically links the two!

@udiboy1209 Don't know, it was the first and last time I have attempted this... to darn difficult, rage out time, my personal server version of github via git tools is far easier. I will keep it simple...

https://gist.github.com/steve1805/4fcc915b6195b19745b1dec44810af92

@steve1805 ahh you made one to your own fork! https://github.com/steve1805/kivy/pull/1 ! You had to make a PR to this repository ('kivy/kivy' and not 'steve1805/kivy'). You can follow [this tutorial](https://help.github.com/articles/creating-a-pull-request-from-a-fork/) for future reference. Right now I'll make a PR myself using your file, don't worry :smile: 


Resolving patch:
diff --git a/kivy/core/image/img_pil.py b/kivy/core/image/img_pil.py
--- a/kivy/core/image/img_pil.py
+++ b/kivy/core/image/img_pil.py
@@ -102,7 +102,8 @@ def load(self, filename):
 
     @staticmethod
     def save(filename, width, height, fmt, pixels, flipped=False):
-        image = PILImage.fromstring(fmt.upper(), (width, height), pixels)
+        image = PILImage.frombytes(fmt.upper(), (width, height), pixels)
+
         if flipped:
             image = image.transpose(PILImage.FLIP_TOP_BOTTOM)
         image.save(filename)


Test patch: