0

当我使用下面的代码时,它会给出输出,但我想要“width”、“file_media_type”、“file_ext”值,但我无法单独获得这个值。我对 Perl 很陌生,请帮助我!

代码

use warnings ;
use strict;
use Image::Info qw[image_info];
use Data::Dumper;

my $file = 'd:\perl\test\a.jpg';
my $info = Dumper(image_info($file));
print $info;

输出

$VAR1 = {
          'width' => 45,
          'file_media_type' => 'image/png',
          'file_ext' => 'png',
          'PNG_Chunks' => [
                            'IHDR',
                            'gAMA',
                            'cHRM',
                            'IDAT',
                            'IEND'
                          ],
          'Chunk-cHRM' => '  z%  Çâ  ·   ÇF  u0  O`  :ù  ?o',
          'PNG_Filter' => 'Adaptive',
          'color_type' => 'RGB',
          'height' => 20,
          'Gamma' => '0.45454',
          'resolution' => '1/1',
          'SampleFormat' => 'U8',
          'Compression' => 'Deflate'
        };
4

1 回答 1

0

image_info($file)返回一个哈希引用。查看转储,您知道可用的键(键是之前的字符串=>

    $info = image_info($file);

    foreach my $key ( qw/width file_media_type file_ext/ ){
        print "$key:$info->{$key}\n";
    }
于 2016-02-16T04:41:02.133 回答