Image::Import
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);
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.
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 :-)
Valid arguments are :
The path to the image you are trying to import. If ImageMagick can read, you can import it. Required
The path to a directory where your program has permissions to create temporary files. Required
The path a file containing Apache-style mime-type pairs. Required
Boolean.
Valid arguments are :
Boolean. Determines whether or not a thumbnail is created.
Int. The maximum width, in pixels, of your thumbnail. Height is scaled accordingly.
Int. The maximum height, in pixels, of your thumbnail. Width is scaled accordingly.
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.
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.
Array ref. An list of valid file-types.
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
The actual contents of the image file.
The height, in pixels, of the image.
The width, in pixels, of the image.
The actual contents of a thumbnail image, if applicable.
The height, in pixels, of the thumbnail image.
The width, in pixels, of the thumbnail image.
The mime-type for the image.
Returns an object as returned by the Error::LastError::last_error() method.
Valid arguments are :
Default is $args-{'infile'}>
Default is white.
Valid arguments are
Int. Default is the width of the current image.
Int. Default is the height of the current image.
Returns an array.
Returns a scalar.
Returns true or false.
Returns a valid Image::Magick object.
Finish POD
2.1.1
December 07, 2001
You know, stuff.
Aaron Straup Cope
http://aaronland.net/toys/error-lasterror
Copyright 2001, Aaron Straup Cope.
This is free software, you may use it and distribute it under the same terms as Perl itself.