当我尝试使用Perl的Imager :: Font加载字体文件时,为什么会出错?

时间:2010-04-30 13:59:35

标签: perl

use strict;
use Imager;
use Imager::Font;
  my $img   = Imager->new();
  my $file  = "D:\\table.png";    
  $img->open(file=>$file) or die $img->errstr();
  # Create smaller version
  my $thumb  = $img->scale(scalefactor=>1.2);
  my $black  = Imager::Color->new( 0, 0, 0 );
  my $format;

  # Autostretch individual channels
  $thumb->filter(type=>'autolevels');
  my $font_filename = "D:\\courbd.ttf";
  my $font = Imager::Font->new(file=>$font_filename)
    or die "Cannot load $font_filename: ", Imager->errstr;

  for $format ( qw( png gif jpg tiff ppm ) ) {                        
   # Check if given format is supported   
    if ($Imager::formats{$format}) {      
      $file.="_low.$format";
      print "Storing image as: $file\n";
      $thumb->string(x => 50, y => 70,
                     font =>$font,
                     string => "Hello, World!",
                     color => 'red',
                     size => 30,
                     aa => 1);
      $thumb->write(file=>$file) or die $thumb->errstr;
    }
  }

1 个答案:

答案 0 :(得分:2)

如果您尝试使用.png,则会收到此错误:

format 'png' not supported - formats bmp, ico, pnm, raw, sgi, tga available for reading

这是问题吗?如果是这样,将其转换为位图并重试。