Bernhard Graf > Imager-Simple-0.010003 > Imager::Simple

Download:
Imager-Simple-0.010003.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.010003   Source  

NAME ^

Imager::Simple - Make easy things easy with Imager

VERSION ^

Version 0.010003

SYNOPSIS ^

Imager::Simple simplyfies common tasks with Imager.

  use Imager::Simple;

  # scale image "anim.gif" and assign output to a variable
  $scaled_data = eval {
    Imager::Simple->read('anim.gif')->scale(100, 100, 'min')->data;
  };
  if ($@) {
    die "error from Imager::Simple: $@";
  }

DESCRIPTION ^

Imager is a powerful module for processing image data, but it is the power that makes it sometimes hard to use for simple tasks, like for example read an image, scale it, convert it to another format and save it somewhere. This module tries to DWIM with as little effort as possible.

METHODS ^

read

  $img = Imager::Simple->read($source, $type);

A constructor method that reads an image and returns an Image::Simple object. $source can be

a scalar

which is taken as a name of a file, that contains the image;

a reference to a scalar

that contains the image data itself;

a file handle

of an opened file from which the image data can be read.

The $type is optional. If given it must be an image type known by Imager like png or jpeg. If not given Imager tries to guess the image type.

Image data is read by Imager's read_multi() method. The returned object provides the individual images through the "frames" method. For most images $img->frames is a reference to an array with one element (@{$img->frames} == 1).

format

  $img->format('gif');

Accessor to the image's output format.

frames

Imager::Simple supports multi-image files, e.g. GIF animations. The individual images are stored in an array of Image objects, that is available through the frames method.

clone

TODO

scale

  $scaled_img = $img->scale(100);
  $scaled_img = $img->scale({y => 100});
  $scaled_img = $img->scale(100, 100, 'min');
  $scaled_img = $img->scale(100, 100, {type => 'min'});
  $scaled_img = $img->scale('min', {height => 100, width => 100});

Scale the image in place.

Accepts absolute and named arguments. Named arguments must be supplied a hash reference as last argument. The order of absolute argument positions is width, height, type. All other arguments can only be supplied as named arguments. Possible names for the image width are width, x and xpixels - names for the image height are height, y and ypixels - and finally the type must be named type. For all other known named arguments see Imager::Transformations.

Absolute and named arguments can be mixed, whereas absolute arguments supersede named ones.

Image tags are copied from the old image(s) where applicable.

write

  $img->write($destination);

Write image data to given destination.

$destination can be:

A scalar

is taken as a filename.

File handle or IO::Handle object

that must be opened in write mode and should be set to binmode.

A scalar reference

points to a buffer where the image data has to be stored.

not given

in what case write acts like the data() method by returning the image buffer.

data

Returns the raw image data.

AUTHOR ^

Bernhard Graf <graf at cpan.org>

BUGS ^

This module definitely needs more work. It only implements some basic functionality (read, scale, write). No test have been written.

Please report any bugs or feature requests to bug-imager-simple at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Imager-Simple. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT ^

You can find documentation for this module with the perldoc command.

    perldoc Imager::Simple

You can also look for information at:

COPYRIGHT ^

Copyright 2007 - 2010 Bernhard Graf.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: