IOError:无法识别图像文件 - 在本地工作但在Heroku上不工作

时间:2013-08-13 23:45:16

标签: django heroku python-imaging-library pillow

我知道在StackOverflow上有关于此错误的大量问题和答案,我已经阅读了所有这些并尝试了许多建议(Pillow而不是PIL,io.BytesIO而不是stringIO),但我仍然得到与以下相同的问题:

我正在处理从S3处理图像的代码 - 特别是将它们重新保存为JPG,必要时旋转它们,并创建各种缩略图。代码的相关部分获取引用S3上的图像的URL列表。我可以确认,是的,图像位于S3指定的位置的S3上。在每个URL上,我调用以下内容:

def process_new_image(file_url):        
    # Load the image and make it a PIL object
    try:
        fd = urllib.urlopen(file_url)
        image_file = io.BytesIO(fd.read())
        image = Image.open(image_file)
    except Exception, e:
        # ===> This is where the issue happens. <====
        raise

    # Read the exif data and potentially rotate the image
    transpose = Transpose()
    transposed_image = transpose.process(image)

    # Resave the image as a jpeg
    new_image_data = io.BytesIO()
    transposed_image.save(new_image_data, 'jpeg', quality=100)
    new_image_data.seek(0)

    try:
        self.image.save('image', ContentFile(new_image_data.read()), save=True)
    except Exception, e:         
        raise

    new_image_data.seek(0)
    self.process_thumbnails(new_image_data)

此代码在本地工作正常。但是当我在Heroku的临时环境中运行它时,我得到“IOError:无法识别图像文件”。它在JPG,PNG和GIF上都失败了,这些都在本地工作。

关于我的环境的细节:

的Django == 1.5.1

枕== 2.1.0

pilkit == 1.1.1

Python 2.7.3(两者都有)

本地枕头编译:

--- TKINTER support available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
*** TIFF G3/G4 (experimental) support not available
--- FREETYPE2 support available
*** LITTLECMS support not available
*** WEBP support not available

On Heroku Pillow编译:

       *** TKINTER support not available
       --- JPEG support available
       --- ZLIB (PNG/ZIP) support available
       --- TIFF G3/G4 (experimental) support available
       --- FREETYPE2 support available
       --- LITTLECMS support available
       *** WEBP support not available

1 个答案:

答案 0 :(得分:0)

与S3存储桶相关的问题。图像需要在桶中公开。问题应该结束。