Image::ValidJpeg - Perl extension for validating JPEG files.
use Image::ValidJpeg; open $fh, 'FILE.jpg'; if( Image::ValidJpeg::check_jpeg($fh) ) { print "FILE.jpg is bad\n"; }
This module parses JPEG files to look for errors, such as truncated files.
The methods return 0 if the file is valid, nonzero if an error is detected.
Look for an end of image marker in the last few bytes of $fh.
This is slightly faster than check_jpeg and should catch most truncated images, unless they happen to be truncated at the end of an embedded JPEG.
Scan through the basic structure of the file, validating that it is correct, until it gets to the main image data. Then, look for an end of image marker in the last few bytes of $fh.
This can detect some problems that check_tail cannot, without being noticeably slower, making it useful for scanning a large number of image files.
Scan through the basic structure of the file, validating that it is correct; also scan the main image data byte by byte. Verify that the file ends with end of image marker in the last few bytes of $fh.
This it the most thorough method, but also the slowest, so it's useful for checking a small number of images. It's the only one that can differentiate between a bad image and a valid image with extra data appended, or between a valid jpeg and two jpegs concatenated together.
The following contants are defined, to match the return values of the validation functions:
Returned for a valid JPEG. This is guaranteed to be 0.
Returned if we ran out of data before the end marker was found (i.e. a truncated file). Can only be returned by check_all, since we can't detect this condition without fully parsing the file.
Returned if the jpeg was otherwsie valid, there was more data in the file after the end marker was found. Can only be returned by check_all, since we can't detect this condition without fully parsing the file.
Returned if validation failed for other reasons, such as an invalid marker. Errors from check_jpeg always return BAD.
None by default.
The check_* methods and constants can be imported individually, or they call all be imported via the ':all' tag.
Steve Sanbeg
Copyright (C) 2012 by Steve Sanbeg
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.1 or, at your option, any later version of Perl 5 you may have available.
To install Image::ValidJpeg, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Image::ValidJpeg
CPAN shell
perl -MCPAN -e shell install Image::ValidJpeg
For more information on module installation, please visit the detailed CPAN module installation guide.