Problems with opening Image PIL
i have a working script for opening and resizing Image from my local photo storage. Like this:
asset = photos.get_asset_with_local_id(file['id']) print (asset) data = asset.get_image() print (data) wpercent = (mywidth/float(data.size)) hsize = int((float(data.size)*float(wpercent))) data = data.resize((mywidth,hsize)) imgByteArr = io.BytesIO() data.save(imgByteArr, format='JPEG')
Before i updated to IOS 14 everything works fine. Without changing the script, i no can sometimes use this functions and sometimes i get the Error with file has 0 bytes and is truncated.
Here is the output from the files which are working and which are not working:
<Asset A4F64DB3-683C-4514-8B27-ED45763434D7/L0/001 - image (3024 x 4032)>
<PIL.Image.Image image mode=RGB size=3024x4032 at 0x113C58128>
<Asset 1F758F7F-7F2C-4D78-9B6E-EEBA2134AD45/L0/001 - image (1200 x 1600)>
<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=1200x1600 at 0x1143338D0>
Can someone tell me what my problem is?
Thx a lot.
thanks a lot for the answer, but sometimes my script is working. Is there any new feature with the right to access images in iOS14?
@kami, from your output it seems that jpeg images are failing. Maybe you should reload them as PNG? You could also try getting all images with
get_ui_imageand then convert to PIL PNG.
Will be slow, though.
@mikael I've tried his code with a lot of jpeg photos, without any error.