我偶然发现了我相当古老的照片对象磁盘,遗憾的是发现该公司 (hemera) 不再提供支持。这给我留下了一大堆 .hpi 文件。幸运的是,我找到了 this information关于提取文件的 jpg 和 png 组件。
不幸的是,我无法让它发挥作用。谁能弄清楚这段代码有什么问题?如果 Perl 不是你的菜,我会很高兴使用 PHP 或 Python 解决方案。 :)
open(I, "$name") || die;
binmode(I);
$_ = <I>;
close(I);
my ($j, $p) = m|^.{32}(.*)(\211PNG.*)$|s;
open(J, ">$name.jpg") &&
do { binmode(J); print J $j; close J; };
open(P, ">$name.png") &&
do { binmode(P); print P $p; close P; };
我从 CD 上截取的当前测试文件的 hexdump 在这里,如果它有帮助的话:
0000000 89 48 50 49 0d 0a 1a 0a 64 00 00 00 20 00 00 00
0000010 45 89 00 00 65 89 00 00 0a 21 00 00 00 d0 d0 00
最佳答案
我在从 MS Word 文档中提取图像时遇到了类似的问题。这是我为此编写的程序。不过,它只提取 PNG:
#!/usr/bin/perl
use strict;
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;
}
}
__END__
关于binaryfiles - 如何提取 .hpi 文件的 .jpg/.png 组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/228165/