Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
problems using Image.open with png file
-
The following code
from PIL import Image img = Image.open('test.png') img.show()
throws "
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>
But
PIL.PngImagePlugin.PngImageFile
is a subclass ofImage.Image
and things likeimg.show()
should work in both cases. In fact, nothing seems to work with the firstimg
.A quick peruse of google seems to suggest that this might be caused by a
libjpeg
version problem.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()? -
Yes,
img.format
is 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.