got this error when the file is not really a jpeg, basically the extension is wrong. Did you check that ?
0.5.0 giving "Premature end of JPEG file" error.
Not sure what may be causing this. I've been using 0.2.0 because it's been stable for me, but went to test out 0.5.0 in hopes it would fix a problem that was being reported to me with our
grunt build task. However, when I went to upgrade I discovered the same bug that was being reported!
Running "imagemin:dist" (imagemin) task ✔ _dist/images/code_bg.png (already optimized) ✔ _dist/images/bird_32_gray_fail.png (already optimized) ✔ _dist/images/bird_32_gray.png (already optimized) ✔ _dist/images/comics/comic.jpg (already optimized) ✔ _dist/images/comics/characters.jpg (already optimized) ✔ _dist/images/comics/kcco-ep1.jpg (already optimized) ✔ _dist/images/comics/introduction-to-keep-calm-and-code-on.jpg (already optimized) ✔ _dist/images/comics/keep-calm-and-code-on-1-pokemon-institute-security-reports.jpg (already optimized) ✔ _dist/images/comics/keep-calm-and-code-on-3-code-signing.jpg (already optimized) ✔ _dist/images/comics/keep-calm-and-code-on-2-card-skimmers.jpg (already optimized) Warning: Premature end of JPEG file Use --force to continue. Aborted due to warnings.
Not sure what all information is needed. Please let me know. Thanks!
- 点赞 评论 复制链接分享
Thanks for the reply, . I hadn't checked that! This post is after I've walked through everything again and not necessarily in chronological order of my actions ;p
Exploring the issue
I removed many images until the error stopped occurring and started adding in one by one. As I was adding in the images, and getting errors on particular ones, I realized the the one it errors on may not be the last one or even next one in the list of those it has optimized. So I used the
--forceoption to see if I could get a little more data, and wound up with this:
Running "imagemin:dist" (imagemin) task ✔ _dist/images/code_bg.png (already optimized) ✔ _dist/images/bird_32_gray_fail.png (already optimized) ✔ _dist/images/bird_32_gray.png (already optimized) ✔ _dist/images/comics/comic.jpg (already optimized) ✔ _dist/images/comics/characters.jpg (already optimized) ✔ _dist/images/comics/introduction-to-keep-calm-and-code-on.jpg (already optimized) ✔ _dist/images/comics/kcco-ep1.jpg (already optimized) ✔ _dist/images/comics/keep-calm-and-code-on-1-pokemon-institute-security-reports.jpg (already optimized) Warning: Premature end of JPEG file Used --force, continuing. /Users/joshmatz/Projects/blog/node_modules/grunt-contrib-compass/node_modules/tmp/lib/tmp.js:261 throw err; ^ TypeError: Cannot read property 'diffSizeRaw' of undefined at /Users/joshmatz/Projects/blog/node_modules/grunt-contrib-imagemin/tasks/imagemin.js:35:35 at Socket.<anonymous> (/Users/joshmatz/Projects/blog/node_modules/grunt-contrib-imagemin/node_modules/image-min/imagemin.js:70:16) at Socket.EventEmitter.emit (events.js:95:17) at Socket.<anonymous> (_stream_readable.js:736:14) at Socket.EventEmitter.emit (events.js:92:17) at emitReadable_ (_stream_readable.js:408:10) at emitReadable (_stream_readable.js:404:5) at readableAddChunk (_stream_readable.js:165:9) at Socket.Readable.push (_stream_readable.js:127:10) at Pipe.onread (net.js:526:21) </anonymous></anonymous>
The only file I currently have triggering is
*-7-*. As you can see, though it appears to be stopping at after
*-1-*, when I remove 7 the error goes away completely. Now that it's narrowed down to this particular image, I have found that it is, in fact, a corrupt image. Photoshop won't open it and gives this warning:
Could not complete your request because a JPEG marker segment length is too short (the file may be truncated or incomplete).
I'll see if I can get my hands on a non-corrupt image and I'm sure that will fix it.
Fixing the issue without fixing the issue
Oddly enough, with the additional
--forcedata, I found #143 which seems to be the same problem. mentioned that changing her src string fixed it. I tried that, and what do you know? Error is gone! That's not necessarily the best solution as now every time I want a new image folder I have to manually add to our Gruntfile... I'm also not sure why changing my src string has any effect on whether the corrupt image is able to be optimized...
While my initial instincts on a corrupt jpeg were correct (seeing as how that is what the error basically says!), narrowing down just which corrupt file it was was not that easy since the listed optimized files don't seem to match to the file that actually causes the error. I wonder if there's a way to output this information better?
Also curious why the above solution worked and if it's working correctly. If it's working, I wonder if it's possible to output a warning rather than completely breaking?点赞 评论 复制链接分享
Regarding the error itself,
TypeError: Cannot read property 'diffSizeRaw' of undefinedyes it is easy to fix in fact. there shouldbe a else starting on line 33 until line 43.
For better debuging, see line 32, the error message is damn poor and rely on the external binaries to eventually provide interesting information.
Lastly, concerning #143, i can t say, i have same interrogations !
Remains the missing pr !点赞 评论 复制链接分享
npm install gruntjs/grunt-contrib-imageminand see if the problem persists.点赞 评论 复制链接分享
Actually works with PNG, I was trying with
0.5.0and always save 0-bytes files.
I just update to
0.6.0-preand now everything is fine (for PNGs).
:+1:点赞 评论 复制链接分享
0.6.0 is out. Let us know if you still have this problem.点赞 评论 复制链接分享
- R语言安装包失败 but >= 1.0.6 is required
- 使用lint命令构建docker go应用
- 如何在巨大的Apache / PHP驻留内存使用上找到罪魁祸首模块或脚本？
- CentOS6.3 运行yum update 时报错：Requires: libstdc++.so.6(GLIBCXX_3.4.15)(64bit)
- 安装 mysql2时出错: 未能构建 gem 原生扩展