Imager
view release on metacpan or search on metacpan
lib/Imager/Files.pod view on Meta::CPAN
to autoload it.
=head1 PRELOADING FILE MODULES
=over
=item preload()
C<< Imager->preload >> preloads the file support modules included with or
that have been included with Imager in the past.
It isn't typically needed, but some cases where you might want to use
it:
=over
=item *
For use in forking servers such as mod_perl to allow as many pages as
possible to be shared between parent and child processes.
=item *
to avoid runtime loading of a module from delaying output in an
animation.
=item *
if you're loading modules from a relative C<$ENV{PERL5LIB}> and expect
to change directories.
=back
You probably don't need it.
If the module is not available no error occurs.
Preserves $@.
use Imager;
Imager->preload;
=back
=head1 EXAMPLES
=head2 Producing an image from a CGI script
Once you have an image the basic mechanism is:
=for stopwords STDOUT
=over
=item 1.
set STDOUT to autoflush
=item 2.
output a content-type header, and optionally a content-length header
=item 3.
put STDOUT into binmode
=item 4.
call write() with the C<fd> or C<fh> parameter. You will need to
provide the C<type> parameter since Imager can't use the extension to
guess the file format you want.
=back
# write an image from a CGI script
# using CGI.pm
use CGI qw(:standard);
$| = 1;
binmode STDOUT;
print header(-type=>'image/gif');
$img->write(type=>'gif', fd=>fileno(STDOUT))
or die $img->errstr;
If you want to send a content length you can send the output to a
scalar to get the length:
my $data;
$img->write(type=>'gif', data=>\$data)
or die $img->errstr;
binmode STDOUT;
print header(-type=>'image/gif', -content_length=>length($data));
print $data;
=head2 Writing an animated GIF
The basic idea is simple, just use write_multi():
my @imgs = ...;
Imager->write_multi({ file=>$filename, type=>'gif' }, @imgs);
If your images are RGB images the default quantization mechanism will
produce a very good result, but can take a long time to execute. You
could either use the standard web color map:
Imager->write_multi({ file=>$filename,
type=>'gif',
make_colors=>'webmap' },
@imgs);
or use a median cut algorithm to built a fairly optimal color map:
Imager->write_multi({ file=>$filename,
type=>'gif',
make_colors=>'mediancut' },
@imgs);
By default all of the images will use the same global color map, which
will produce a smaller image. If your images have significant color
differences, you may want to generate a new palette for each image:
Imager->write_multi({ file=>$filename,
( run in 1.513 second using v1.01-cache-2.11-cpan-524268b4103 )