Error loading font file using Imager::Font module in perl

Posted by user211808 on Stack Overflow See other posts from Stack Overflow or by user211808
Published on 2010-04-30T13:59:34Z Indexed on 2010/04/30 15:37 UTC
Read the original article Hit count: 177

Filed under:
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;
    }
  }

© Stack Overflow or respective owner

Related posts about perl