Imager::Tutorial 0.54 review
Download
|
|
Imager::Tutorial is an introduction to Imager.
Before you start
If you have the necessary knowledge, install the image format libraries you want Imager image file support for, and Imager itself, otherwise arrange to have it done.
You will also want some sort of image viewer tool, whether an image editor like Photoshop or the GIMP, or a web browser.
Hello Boxes! - A Simple Start
As with any perl program it's useful to start with a #! line, and to enable strict mode:
#!/usr/bin/perl -w
# you might to 'use warnings;' instead of the -w above
use strict;
These lines will be omitted in further examples.
As with any module, you need to load it:
use Imager;
Now create a image to draw on:
my $image = Imager->new(xsize => 100, ysize => 100);
and draw a couple of filled rectangles on it:
$image->box(xmin => 0, ymin => 0, xmax => 99, ymax => 99,
filled => 1, color => 'blue');
$image->box(xmin => 20, ymin => 20, xmax => 79, ymax => 79,
filled => 1, color => 'green');
Since the first box fills the whole image, it can be simplified to:
$image->box(filled => 1, color => 'blue');
and save it to a file:
$image->write(file=>'tutorial1.ppm')
or die 'Cannot save tutorial1.ppm: ', $image->errstr;
So our completed program is:
use Imager;
my $image = Imager->new(xsize => 100, ysize => 100);
$image->box(filled => 1, color => 'blue');
$image->box(xmin => 20, ymin => 20, xmax => 79, ymax => 79,
filled => 1, color => 'green');
$image->write(file=>'tutorial1.ppm')
or die 'Cannot save tutorial1.ppm: ', $image->errstr;
Requirements:
Perl
Imager::Tutorial 0.54 search tags