How to detect corrupt image

Started by snsinha, July 21, 2020, 02:52:44 AM

Previous topic - Next topic

snsinha

Hey I m new to this forum as well as exiftool.I am using this in a java application .I am trying to find out if an image is corrupted .What are the ways to do it.I cannot use Imagemagick ,as suggested by many stackoverflow solutions.
One of the way I see is - exiftool -validate <image.jpg>.But its output is either "8 Warnings (2 minor)" or "OK". So is there a way I can get the list of warnings and not just a count of warnings.The reason why I want to see the warning is , all kind of warnings do not assure that its a corrupt image
Or any other way that might help.
Thank You

Phil Harvey

exiftool -validate -warning -error -a FILE

(this is FAQ 25)

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

snsinha

Hey Thank You @Phil.Sorry I did not look at FAQs earlier .
So for an image if I get a non-minor issues would that mean that exiftool would not be able to run any other command for that image?

Phil Harvey

ExifTool won't run on an image if it has any errors.  Warnings may prevent a certain type of metadata from being read/written, but not necessarily.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

snsinha

So if I take the attached image an an example , the image is incomplete and corrupt and I get a "Premature end of JPEG" using imagemagick .When I run exiftool -validate  -warning -error -a file , it gives
Validate                        : 8 Warnings (2 minor)
Warning                         : [minor] IPTC TimeCreated too short (6 bytes; should be 11)
Warning                         : [minor] IPTC DigitalCreationTime too short (6 bytes; should be 11)
Warning                         : JPEG format error
Warning                         : Missing required JPEG ExifIFD tag 0x9101 ComponentsConfiguration
Warning                         : Missing required JPEG ExifIFD tag 0xa000 FlashpixVersion
Warning                         : Missing required JPEG ExifIFD tag 0xa002 ExifImageWidth
Warning                         : Missing required JPEG ExifIFD tag 0xa003 ExifImageHeight
Warning                         : Missing required JPEG IFD0 tag 0x0213 YCbCrPositioning
and all other exiftool command(read a metadata , delete a metadata) are working fine.

snsinha

all the above outputs are warning.But I do not want to process these problematic images.Is there a way

Phil Harvey

An image like this may be read but not written.  ExifTool it is able to read the metadata from it, but won't write it for fear of further image corruption.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

snsinha

I tried to run exiftool -Vibrance=+35 corrupt.jpg on the same image and it got updated:|

Phil Harvey

#8
You're right.  And I see why.  The JPEG writer doesn't validate the image, and it copies the image data blindly since there is no risk of further corruption.  It would be different for any TIFF-based format.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

snsinha

Okay.So I will have to figure out someother way to validate an image before processing it. :'(

StarGeek

I've looked long and hard for a program to detect corrupt jpgs and haven't found much.  The best answer I've found is to using jpegtran, redirect the output to nul, and check the return code.  It is far from 100%, though, and only detects the very worst corruption.

For Windows, here's a bat file I use that adds a keyword to files it detects as corrupt
set Full=%*
set Full=%Full:"=%
for /f "delims=" %%i in ('dir /b /s "%Full%\*.jpg"') do (
echo Checking %%i
"C:\Programs\UnixUtils\libjpeg-turbo64\bin\jpegtran.exe" -outfile nul:  "%%i" || (
exiftool -P -overwrite_original -Subject+="Corrupt Jpeg" -HierarchicalSubject+="Workflow|Corrupt Jpeg" "%%i"
)
)
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype