View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Lyle Hopkins > Image-Mate-0.05 > Image::Mate



Annotate this POD

Related Modules

View/Report Bugs
Module Version: 0.05   Source  


Image::Mate - Interface to Gd, Imager, ImageMagick modules


This document refers to version 0.05


    use Image::Mate;

    # Get available graphics modules
    my %list = &Image::Mate->im_available("hash");

    # Set new preference list
    my $error = &Image::Mate->im_setpref("Imager","GD","Image::Magick");
    # create a new image
    $img = Image::Mate->new(blank => {x => 100, y => 100, c => 1});
    $img = Image::Mate->new(file => "image.jpg");

    # colour the whole image red
    $img->fillall(c => "#ff0000");

    # draw a black line in the image
    $img->line(c => "#000000", start => {x => 0, y => 0}, end => {x => 10, y => 10});
    # save image
    $img->save(filename => "picture.jpg", type => "jpg", quality => 90);

DESCRIPTION ^ is an interface to the Perl GD, Imager and ImageMagick modules. Theoretically you'll be able to code the same image routines no matter which of the before mentioned modules you have available. Very useful if your scripts can end up on all different kinds of servers and you never know what image modules are available.


Here are the routines.

$error = Image::Mate->im_available(["array","hash"])

This method returns a list of what graphics modules are available. List can be in the form of a hash listing all modules with either a 1 or 0 value. Or an array listing only those available. NOTE: If you run setpref before this routine then the array returned by this method will only contain what you set. This routine can be exported the local namespace using use Image::Mate qw( im_available );

$error = Image::Mate->im_setpref(LIST)

This method allows you to set the preference list of which graphics modules you should use first. The default is "Imager","GD","Image::Magick". If successful 0 will be returned, otherwise it'll be an error code with descriptive error. You cannot set modules that are not available. If you are unsure what graphics modules you have available run Image::Mate->available first. This routine can be exported the local namespace using use Image::Mate qw( im_setpref );

$img = Image::Mate->new(blank = {x => 100, y => 100, c => 1])> =item $img = Image::Mate->new(file = "image.jpg")>

Returns an image object. If there was an error with creating this object it will be in $img->{ERROR}. "c" can have the value of 0 or 1. 0 for stand colour (usually 8bit) or 1 for high colour (usually 16bit).

$img = Image::Mate->fillall(c = "#FFFFFF")>

Fills the whole image with the set colour.

$img-line(c => "#000000", start => {x => 0, y => 0}, end => {x => 10, y => 10})>

Draws a line from start x,y point to end x,y point of colour c.

$img-save(filename => "FILENAME", type => "TYPE", quality => QUALITY, compression => COMPRESSION)>

Saves the image to a file. Supported types are GIF, PNG, and JPG, default is JPG. For JPG you can define QUALITY as 0-100 (100 best quality, 0 worest). For PNG you can define COMPRESSION as 0-9 (0 best quality, 9 worest).

Obtaining the GD, Imager and Image::Magick perl modules ^

They are all available on CPAN. Just run a search As long as you have any one of these modules installed Image::Mate will work.

On linux I recommend using the CPAN module. Type "perl -MCPAN -e shell;" from your shell. (If this is the first time you've ran the CPAN module you'll have to go through a little config first, but don't worry this is menu driven). Then type either (or all):- install Imager install GD install Image::Magick

On Windows your are probably using ActivePerl from ActiveState (which I also recommend). Use their ppm utility, from the command prompt type:- ppm install ppm install ppm install

Unfortunately, ActiveStates automatic build machine does not include the necessary modules to build Imager, GD and Image::Magick, so they are not available from their default repository.


This is the first release and distinctly lacking in features :( Although I'll be adding new features as time goes on :) Hopefully others will also add new functions as well :D


The Image::Mate interface is copyright 2007, Lyle Raymond Hopkins. It is distributed under the same terms as Perl itself. See the "Artistic License" in the Perl source code distribution for licensing terms.

I welcome other programmers to submit new features to this module!!


Imager, GD, Image::Magick

syntax highlighting: