开发者

How use Gridfs of mongodb with PIL (Python Image Library)

开发者 https://www.devze.com 2023-02-07 04:14 出处:网络
i use mongodb and save file to gridfs now i want edit images from gridfs ... i use this code def thumbnail(file_obj):

i use mongodb and save file to gridfs

now i want edit images from gridfs ...

i use this code

def thumbnail(file_obj):
    import StringIO
    from PIL import Image

    im = StringIO.StringIO()

    im开发者_StackOverflow中文版.write(file_obj.raw_file)

    im_ful = Image.open(im)

    return im_ful.info

but pil said "cannot identify image file"

thats image also ;) how can fix it


You need an im.seek(0) before the Image.open(im) call. Otherwise PIL tries to read from the end of the file, gets no data, and fails.

0

精彩评论

暂无评论...
验证码 换一张
取 消