problems using Image.open with png file
The following code
from PIL import Image img = Image.open('test.png') img.show()
IOError: broken data stream when reading image file". Reading the image from the camera roll works flawlessly, though:
import photos img = photos.pick_image() img.show()
The first image prints as
<PIL.PngImagePlugin.PngImageFile image mode=RGBA size 152x152 at 0xDFB438C>
the second one as
<Image.Image image mode=RGBA size 152x152 at 0xDFB460C>
PIL.PngImagePlugin.PngImageFileis a subclass of
Image.Imageand things like
img.show()should work in both cases. In fact, nothing seems to work with the first
A quick peruse of google seems to suggest that this might be caused by a
PS: It used to work with Pythonista 1.3.
This code seems to work quite consistently:
import Image, photos pngFileName = 'test.png' def img_info(img): print(img) print(img.format, img.mode, img.size, img.palette, img.info) img = photos.pick_image() img_info(img) img.save(pngFileName) # write out the image as .png img = Image.open(pngFileName) # read in the image img_info(img) img.show() # This might take a few seconds
Is the image.format of your image really set to 'PNG'?<br />
Can you use the code above to create a new .png file that you can successfully .show()?
img.formatis set to 'PNG'.
Your code, however, is a working fine and can be used to create a new .png file that can successfully be dealt with. Kind of weird, though. Why wouldn't it work if saved directly by a dropbox sync?
Thanks for the workaround, ccc.
If you create a gist of the Dropbox code then perhaps others in the Forum can discover why it is not working.