简体   繁体   English

枕头奇数截断的jpg图像在同一图像上的行为

[英]pillow odd truncted jpg images behavior on the same image

I have the same image, one of them is the original one stored on my machine, another one uploaded to the azure blob storage and downloaded back to my local machine. 我有相同的映像,其中一个是存储在我的计算机上的原始映像,另一个是上载到azure blob存储并下载回我的本地计算机的映像。 Here is a piece of code (Python 3.6.3, Pillow-SIMD 4.3.0post0, libjpeg-turbo, ubuntu 17.10/alpine docker container): 以下是一段代码(Python 3.6.3,Pillow-SIMD 4.3.0post0,libjpeg-turbo,ubuntu 17.10 / alpine docker容器):

image_stream = open('src/app/resize/resizer/corrupted_blob.jpg', 'rb')
image = Image.open(image_stream)
image.load()

When the interpreter hits the .load method exception is raised: OSError: image file is truncated (6 bytes not processed) 解释器命中时,将引发.load方法异常: OSError: image file is truncated (6 bytes not processed)

so it happens only with corrupted_blob.jpg , corrupted_original.jpg is loaded and displayed correctly. 所以它发生仅corrupted_blob.jpgcorrupted_original.jpg被加载并正确显示。 I know that the first assumption would be 'here is something happened during uploading', but either a browser or windows/ubuntu image viewer or another piece of software which renders images handle both of the images correctly. 我知道第一个假设是“上传过程中发生了某些事情”,但是浏览器或Windows / Ubuntu图像查看器或另一种渲染图像的软件都可以正确处理这两个图像。 So there is something with pillow or with underlying libjpeg. 因此,有些东西带有枕头或底层的libjpeg。

I have tried to use ImageFile.LOAD_TRUNCATED_IMAGES = True but all I get is a black image -_- 我试图使用ImageFile.LOAD_TRUNCATED_IMAGES = True但我得到的只是黑色图像-_-

Please help! 请帮忙!

original image 原始图像

blob uploaded/downloaded image Blob上传/下载的图片

So after investigation, I found out that for some reason suffix JPEG bytes were missing. 因此,经过调查,我发现由于某种原因缺少了后缀JPEG字节。 Here is the workaround: 解决方法如下:

except OSError as e:
    fixed_image_bytes = image_stream.getvalue() + b'\xff\xd9'
    with io.BytesIO(fixed_image_bytes) as fixed_image_stream:
        image = Image.open(fixed_image_stream)
        image.load()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM