#!/usr/bin/perl use strict; use warnings; use File::Path; use Imager; use Imager::Font::W32; use Imager::File::TIFF; use Carp 'verbose'; my $filename = "c:\\temp\\test\\errtest.tif"; my $white = Imager::Color->new(255, 255, 255); my $black = Imager::Color->new(0,0,0); my $xres = 240; #Horizontal Resolution (in DPI) of image my $yres = 240; #Vertical Resolution (in DPI) of image my $PageWidth = 8.5; my $PageHeight = 11; #-- End Paramaters --# my $xsize = $xres * $PageWidth; # Horizontal Page Size (Resolution * Inches) my $ysize = $yres * $PageHeight; # Vertical Page Size (Resolution * Inches) my $img = Imager->new(xsize=>$xsize,ysize=>$ysize); $img->settag(name =>'i_xres',value => $xres, name =>'i_yres',value => $yres, name =>'tiff_resolutionunit', value => 2); # Set the resolution unit to DPI # Load up Windows Font Face my $Font_Arial_Bold = Imager::Font->new(face => 'Arial Bold') or carp("Cannot load 'Arial Bold: ".Imager->errstr); $img->box(filled=>1, color=>$white); #Give our new page a white background $Font_Arial_Bold->align(string => 'Test', size => 80, color =>$black, x => $img->getwidth/2, y => 250, halign => 'center', valign => 'center', image => $img); my $bilevel = $img->to_paletted(make_colors => 'mono', translate => 'errdiff', errdiff => 'stucki'); $bilevel->write(file => $filename, type => 'tiff', i_xres=> $xres, i_yres=> $yres, tiff_compression => 4);