开发者

Why do I get an error when I try to load a font file with Perl's Imager::Font?

开发者 https://www.devze.com 2022-12-29 05:47 出处:网络
use strict; use Imager; use Imager::Font; my $img= Imager->new(); my $file= \"D:\\\\table.png\"; $img->open(file=>$file) or die $img->errstr();
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 $fo开发者_StackOverflowrmat ( 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;
    }
  }


If you are trying to use a .png you'll get this error:

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

Is this the problem? If so convert it to a bitmap and try again.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号