in reply to extract jpg from binary file
my $HEADER = "\211PNG"; my $FOOTER = "IEND\xAEB`\x82"; foreach my $file ( @ARGV ) { print "Extracting $file\n"; (my $image_base = $file) =~ s/(.*)\..*/$1/; my $data = do { local $/; open my( $fh ), $file; <$fh> }; my $count = 0; while( $data =~ m/($HEADER.*?$FOOTER)/sg ) { my $image = $1; $count++; my $image_name = "$image_base.$count.png"; open my $fh, "> $image_name" or warn "$image_name: $!", next; print "Writing $image_name: ", length($image), " bytes\n"; print $fh $image; close $fh; } }
|
|---|