weixin_39731107
weixin_39731107
2021-01-12 07:13

Not sure if bug, feature or wrong aproach: "Premature end of JPEG file" msg when vipsthumbnail to same file.

When I run following command:


vipsthumbnail /var/www/example.com/tmp/josephine-mb2016-3-2.jpg --eprofile srgb --size="4096x4096>" -o /var/www/example.com/tmp/josephine-mb2016-3-2.jpg[Q=90,interlace,profile=none,optimize_coding]

I get:


(vipsthumbnail:30921): VIPS-WARNING **: 19:16:13.505: read gave 2319 warnings

(vipsthumbnail:30921): VIPS-WARNING **: 19:16:13.507: VipsJpeg: Premature end of JPEG file
VipsJpeg: JPEG datastream contains no image

vipsthumbnail: unable to thumbnail /var/www/example.com/tmp/josephine-mb2016-3-2.jpg
VipsJpeg: Premature end of JPEG file
VipsJpeg: JPEG datastream contains no image

Image josephine-mb2016-3-2.jpg has following dimensions 1000x662.

My goal is resize image above "4096x4096" so I can start to cut thumbnails from it later on.

Expected behaviour: Optimize image with no resize.

My VIPS version: libvips 8.11.0-Thu Oct 1 06:21:43 UTC 2020

该提问来源于开源项目:libvips/libvips

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

4条回答

  • weixin_39596668 weixin_39596668 3月前

    Hi ,

    That's weird. Could the image file be truncated? Try uploading it somewhere.

    I wouldn't use 8.11-- it's in active development and not very stable. I would stick to 8.10.

    点赞 评论 复制链接分享
  • weixin_39956612 weixin_39956612 3月前

    Does this error only occur if the input and output image are the same? If so, https://stackoverflow.com/a/63589444/10952119 might be relevant here.

    点赞 评论 复制链接分享
  • weixin_39596668 weixin_39596668 3月前

    Oh heh you're right, it won't work if the input and output files are the same, I hadn't noticed. Nice catch Kleis.

    点赞 评论 复制链接分享
  • weixin_39731107 weixin_39731107 3月前

    Then we have an answer on question from title: Wrong approach :-)

    libvips is a streaming image-processing library -- pixels are processed from source to destination in a series of small chunks, and entire images are not held in memory. This means the source file and destination file must both exist at the same time, which means you can't use the same filename for both.

    The best solution is to write to a temporary file, then rename the temporary file over the source file once processing finishes.

    点赞 评论 复制链接分享