[EMAIL PROTECTED] wrote:
> Hello Is there a function to test if a given.jpg file is a valid jpg file?
> thanks
if you don't want to install/load another module, try:
#!/usr/bin/perl -w
use strict;
if(is_jpeg('your file')){
print "it's a valie jpeg\n";
}else{
print "doesn't look like a jpeg\n";
}
sub is_jpeg{
my $jpeg_file = shift;
my $id = undef;
open(JPEG,$jpeg_file) || croak("Unable to open $jpeg_file: $!");
sysread(JPEG,$id,6);
sysread(JPEG,$id,5);
my($j,$p,$e,$g,$z) = unpack("CCCCC",$id);
close(JPEG);
return $j == 74 && $p == 70 && $e == 73 && $g == 70 && $z == 0;
}
__END__
david
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]