Imager Cookbook
Details
| Last Update: | 2008-01-15 17:01:12 |
| Version: | Imager::Cookbook |
| License/Program Type: | Perl Artistic License |
| Publisher: | Tony Cook |
| Price: | $0.00 |
Description:
Imager::Cookbook contains recipes for working with Imager.
FILES
This is described in detail in Imager::Files.
Reading an image from a file
my $image = Imager->new;
$image->read(file=>$filename) or die
$image->errstr;
See Imager::Files.
Writing an image to a file
$image->write(file=>$filename) or die
$image->errstr;
Write an animated gif.
build an array of images to use in the gif
my @images;
synthesize the images or read them from files, it doesn't
matter
...
write the gif
Imager->write_multi({ file=>$filename, type=>'gif'
}, @images)
or die Imager->errstr;
See "Writing an animated GIF" in Imager::Files for a more
detailed example.
Reading multiple images from one file
Some formats, like GIF and TIFF support multiple images per
file. Use the read_multi() method to read them:
my @images = Imager->read_multi(file=>$filename)
or die Imager->errstr;
Converting from one file format to another
This is as simple as reading the original file and writing the
new file, for single images:
my $image = Imager->new;
Imager auto-detects the input file type
$image->read(file => $input_filename)
or die $image->errstr;
Imager derives the output file format from the filename
$image->write(file => $output_filename)
or die $image->errstr;
or you can supply a type parameter:
$image->write(file => $output_filename, type =>
'gif')
or die $image->errstr;
The main issue that can occur with this is if the input file
has transparency and the output file format doesn't support that.
This can be a problem when converting from GIFs to JPEGs for
example.
To work around that you can compose the source image onto a
background color:
if ($image->getchannels == 4 or $image->getchannels ==
2) {
my $back = Imager->new(xsize => $image->getwidth,
ysize => $image->getheight);
grey background for grayscale images, red for color
my $back_color = $image->getchannels == 2 ? [ 128 ] :
'red';
$back->box(filled => 1, color => $back_color);
$back->rubthrough(src => $image);
$image = $back;
}
now we can write safely to jpeg or pnm
Some formats support multiple files, so if you want to convert
from say tiff to jpeg, you'll need multiple output files:
my @images = Imager->read_multi(file =>
'input.tif')
or die Imager->errstr;
my $index = 1;
for my $image (@images) {
$image->write(file => sprintf('output%02d.jpg',
$index++))
or die $image->errstr;
}
Requirements:
· Perl
0 comments
Add to
Imager Cookbook Version History
Related Software
|
|
From category: Libraries |
| core2 1.0.1 is libraries software developed by Zwetan Kjukov. core2 project is a library that extends the ECMAScript built-in objects: Array, Boolean, Date, Error, Function, Number, Object, and Str... |
|
|
From category: Libraries |
| AxKit2::Plugin 1.1 is libraries software developed by AxKit2::Plugin Team. AxKit2::Plugin is a base class for all plugins. An AxKit2 plugin allows you to hook into various parts of processin... |
|
|
From category: Libraries |
| TuxCap is game framework software.... |
|
|
From category: Interpreters |
| ArrowHead ASP Server 0.2.3 is interpreters software developed by Lazerdye. ArrowHead ASP Server is a Java Servlet which supports the ASP syntax and the VBScript programming language. It aims to sup... |
|
|
From category: Libraries |
| Bio::PrimarySeqI 1.4 is libraries software developed by Ewan Birney. Bio::PrimarySeqI is a Perl Interface definition for a Bio::PrimarySeq. SYNOPSIS Bio::PrimarySeqI is the inte... |
|
|
From category: Libraries |
| UCommon is a lightweight C++ library to facilitate using C++ design patterns.... |
|
|
From category: Libraries |
| Class::XML 0.06 is libraries software developed by Matt S Trout. Class::XML is a Perl module for simple XML Abstraction. SYNOPSIS package Foo; use base qw/Class::XML/; \... |
|
|
From category: Libraries |
| Bigtop::Docs::TentTut 0.14 is libraries software developed by Phil Crow. Bigtop::Docs::TentTut is Perl module for tentmaker Tutorial (best viewed in html). If you don\'t know what Bigtop is,... |
|
|
From category: Libraries |
| ASNMTAP::Asnmtap::Plugins::Nagios 3.000.010 is libraries software developed by Alex Peeters. ASNMTAP::Asnmtap::Plugins::Nagios provides a nice object oriented interface for building Nagios compatib... |
|
|
From category: Version-Control |
| Ant SVK Task 0.0.10 is version control software developed by Ant SVK Task Team. Ant SVK Task is a software that can create fully functional support for the SVK SCM tool within Ant build files. \... |
|
|
From category: Quality-Assurance-and-Testing |
| Datamixer 0.1.88 is quality assurance and testing software developed by Rick Wood. How do you build a web application without data? Suppose it has many pages, including forms and pages for display.... |
|
|
From category: Libraries |
| Bio::Root::Object 1.4 is libraries software developed by Bio::Root::Object Team. Bio::Root::Object is a core Perl 5 object. SYNOPSIS Use this module as the root of your inheritanc... |
|
|
From category: Libraries |
| DateTime::Format::Epoch::DotNet 0.10 is libraries software developed by Eugene van der Pijli. DateTime::Format::Epoch::DotNet is a Perl module that can convert DateTimes to/from .NET epoch seconds.... |
|
|
From category: Perl-Modules |
| Pod::Tidy is a reformatting Pod processor.... |
|
|
From category: Preprocessors |
| CLIP 1.2.0 is preprocessors software developed by ITK. CLIP is a Clipper/XBase compatible compiler with initial support other xBase dialects. CLIP project features support for international languag... |
Leave a comment