Can I fix photos with corrupt jpeg data?

社会主义新天地 提交于 2019-12-20 20:00:10

问题


My phone (android, fwiw) takes pictures that are corrupted. I'm not sure why or how it is doing this, but it seems to prevent me from uploading the photos to some services. If I move the photos to my computer and open them in GIMP I see a warning message:

Corrupt JPEG data: 1130 extraneous bytes before marker 0xd9

The error doesn't prevent me from viewing or editing the photos, but I'm wondering if there's some way to set up a batch process that would fix this problem?


回答1:


It's hard to tell without an image to try it on, but I would think ImageMagick would rewrite your images properly without the superfluous data. If you are on Linux it is probably installed, look for a program called convert and/or mogrify whcih belong to ImageMagick, else you can install it from here.

Then you want a command that does nothing too drastic to your image, so something like this should be pretty harmless:

mogrify -set comment 'Extraneous bytes removed' *.jpg

Back up your files first though, and test before applying to thousands of images!




回答2:


I had the problem that the jpg file ended prematurely and mogrify wouldn't resize my images. My solution to this problem was to convert the images to png and back to jpg. This fixed the problem:

#!/bin/bash

mogrify -format png *.jpg
rm *.jpg
mogrify -format jpg *.png
rm *.png

There might be a quality loss due to compression artifacts, but for my purpose this was fine.




回答3:


I encountered the same issue when I was building an image classification model: I retrained the model (written in Tensorflow) using lots of images as input.

After some investigation, I found the error are caused by the image editing(crop and rotate). As the EXIF info still keep the original dimension, it doesn't match the latest dimension after editing. Fix is very easy, we can use mogrify of imagick to delete the outdated EXIF info.

mogrify <file name>

or

mogrify -strip <file name>



来源:https://stackoverflow.com/questions/24805500/can-i-fix-photos-with-corrupt-jpeg-data

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!