Perl Tutorials - Herong's Tutorial Examples - v6.01, by Dr. Herong Yang
Imager - Create and Save Image
This section provides a tutorial example on using stat() to return many statistics of the specified file, including file size, creation time, and last modification time.
"Imager" is a Perl module for creating and altering 24-bit images. It can read and write various image formats, draw primitive shapes like lines, and polygons, blend multiple images together in various ways, scale, crop, render text, etc..
To try the Imager module, you can create a new image and save to it to a file.
1. Make sure the Imager module is installed. You can use CPAN Shell to do it.
2. Write a Perl script to create an image of 200x200 px size and save it to Imager-New.bmp.
#- Imager-Create-New.pl #- Copyright (c) HerongYang.com. All Rights Reserved. use Imager; $img = Imager->new(xsize=>200, ysize=>200); print "Image created:\n"; print " Width: ", $img->getwidth(), "\n"; print " Height: ", $img->getheight(), "\n"; $file = "Imager-New.bmp"; $img->write(file=>$file) or die $img->errstr; print "Image saved:\n"; print " File: $file\n";
3. Run the above script:
herong$ perl Imager-Create-New.pl Image created: Width: 200 Height: 200 Image saved: File: Imager-New.bmp herong$ ls -l -rw-r--r--@ 1 herong staff 396 Imager-Create-New.pl -rw-r--r--@ 1 herong staff 120054 Imager-New.bmp
4. View Imager-New.bmp. You see an image with black color.
Table of Contents