NAME

Image::Import


SUMMARY

    use Image::Import;

    my $I = Image::Import->new(
                               file       => "/htdocs/img/idea.gif",
                               tmp_dir    => "/usr/tmp",
                               mime_types => "/apache/conf/mime.types",
                               verbose    => 1,
                               ) || die $Image::Import::LAST_ERROR->errstr();

    my $img = $I->fetch(
                        thumbnail => 1,
                        th_width   => 170,
                        max_width  => 300,
                        max_height => 300,
                        valid      => [ "gif","jpg","jpeg" ],
                        convert    => 1,
                        ) || die $I->last_error()->errstr();

    my @set = ( map { $_ = "$_=".$sql->quote($img->{$_}); } keys %$img );
    my $cmd = "insert into images set ".join(",",@set);


DESCRIPTION

Slurp an image as a hashref. In the process, you may optionally resize the image, converting the image to another image type, create a thumbnail or any combination thereof.


BACKGROUND

This package was originally developed as part of a web-based database application. This, more than anything, explains why there is a single public function that returns a hash-ref. I am not opposed to the idea of more methods or, at the very least, doing something exciting like passing a filehandle around instead of the file contents but it just hasn't happened yet.

Patches are welcome :-)


CONSTRUCTOR METHODS


$pkg = Image::Import->new(%args)

Valid arguments are :

file

The path to the image you are trying to import. If ImageMagick can read, you can import it. Required

tmp_dir

The path to a directory where your program has permissions to create temporary files. Required

mime_types

The path a file containing Apache-style mime-type pairs. Required

verbose

Boolean.


PUBLIC METHODS


$pkg->fetch(%args)

Valid arguments are :

thumbnail

Boolean. Determines whether or not a thumbnail is created.

th_width

Int. The maximum width, in pixels, of your thumbnail. Height is scaled accordingly.

th_height

Int. The maximum height, in pixels, of your thumbnail. Width is scaled accordingly.

max_width

The maximum width that the image you are importing may be. If the width of the source file exceeds this value, the method will create a temporary file resized to the new dimensions. The original source file will not be altered.

Height is scaled accordingly.

max_height

Int. The maximum height that the image you are importing may be. If the height of the source file exceeds this value, the method will create a temporary file resized to the new dimensions. The original source file will not be altered.

Width is scaled accordingly.

valid

Array ref. An list of valid file-types.

convert

Boolean. If this value is true and the source does not a valid file-type, the method will create a temporary file attempt to convert it to one of the specified valid file-types. The method will try to convert in the order the valid file-types are specified, stopping on success.

On success, returns a hash ref containing the following keys

image

The actual contents of the image file.

height

The height, in pixels, of the image.

width

The width, in pixels, of the image.

thumbnail

The actual contents of a thumbnail image, if applicable.

th_height

The height, in pixels, of the thumbnail image.

width

The width, in pixels, of the thumbnail image.

type

The mime-type for the image.


$pkg->last_error()

Returns an object as returned by the Error::LastError::last_error() method.


PRIVATE METHODS


$pkg->define()


$pkg->make_thumbnail()


$pkg->resize(%args)

Valid arguments are :

infile
outfile

Default is $args-{'infile'}>

background

Default is white.


$pkg->get_geometry($x,$y)

Valid arguments are

$x

Int. Default is the width of the current image.

$y

Int. Default is the height of the current image.

Returns an array.


$pkg->get_src($f)

Returns a scalar.


$pkg->get_mime_types($f)

Returns true or false.


$pkg->magick()

Returns a valid Image::Magick object.


TODO

Finish POD


VERSION

2.1.1


DATE

December 07, 2001


CHANGES


0.1 -> 2.1.1

You know, stuff.


AUTHOR

Aaron Straup Cope


SEE ALSO

Image::Magick

http://aaronland.net/toys/error-lasterror


LICENSE

Copyright 2001, Aaron Straup Cope.

This is free software, you may use it and distribute it under the same terms as Perl itself.