I personally believe that there are tons of better, more reliable, and format-specific extractors of images for "container" files like pdf, or (those damned) pps, etc.: either free (for one of the two acceptations of the word) or not. But yesterday I was in a quick need of extracting the jpeg images contained in one such file, so I quickly checked JPEG @ Wikipedia for the headers's markers and I concocted up the latter, possibly complete of some minimal YAGNI (I know I shouldn't) for future development: it worked for me!
#!/usr/bin/perl use strict; use warnings; use 5.010; use open IO => ':raw'; use File::Basename; my $progname; BEGIN { ($progname) = fileparse $0, qr/\.pl/i; } local $/; my %cnt; while (<>) { while ( /(\xFF\xD8 .*? \xFF\xD9)/xsg ) { for my $name ($ARGV . ++$cnt{$ARGV} . '.jpeg') { open my $fh, '>', $name or die "Can't open `$name': $!\n"; warn "[$progname] Creating `$name'\n"; print $fh $1; } } } __END__
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Insane (?) Regexp-based jpeg (JFIF) extractor...
by ikegami (Patriarch) on Oct 31, 2008 at 09:15 UTC | |
by blazar (Canon) on Oct 31, 2008 at 10:17 UTC | |
by ikegami (Patriarch) on Nov 02, 2008 at 20:55 UTC | |
by blazar (Canon) on Nov 05, 2008 at 13:08 UTC | |
Re: Insane (?) Regexp-based jpeg (JFIF) extractor...
by Discipulus (Canon) on Oct 31, 2008 at 08:17 UTC | |
Re: Insane (?) Regexp-based jpeg (JFIF) extractor...
by wol (Hermit) on Oct 31, 2008 at 11:46 UTC |
Back to
Cool Uses for Perl