NAME
Image::ValidJpeg - Perl extension for validating JPEG files.
SYNOPSIS
use Image::ValidJpeg;
open $fh, 'FILE.jpg';
if( Image::ValidJpeg::valid_jpeg($fh) ) {
print "FILE.jpg is bad\n";
}
DESCRIPTION
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.
METHODS
- check_tail($fh)
-
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.
- check_jpeg($fh)
-
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.
- check_all($fh)
-
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.
CONSTANTS
The following contants are defined, to match the return values of the validation functions:
- GOOD
-
Returned for a valid JPEG. This is guaranteed to be 0.
- SHORT
-
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.
- EXTRA
-
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.
- BAD
-
Returned if validation failed for other reasons, such as an invalid marker. Errors from check_jpeg always return BAD.
EXPORT
None by default.
The check_* methods and constants can be imported individually, or they call all be imported via the ':all' tag.
AUTHOR
Steve Sanbeg
COPYRIGHT AND LICENSE
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.