GFL::Image - An OO interface to P-e Gougelet's Graphic File Library
use GFL::Image; my $im = GFL::Image-> new; $im -> load("test.png"); $im -> set( output => "jpeg", undolevel => 5 ); $im -> resize (320, 200); $im -> filter( maximum => 3, mediancross => 7 ); $im -> undo; $im -> save("test.jpg"); undef ($im);
This module provides an Object Oriented interface to Pierre-E. Gougelet's Graphic File Library.
GFL provides a comprehensive set of image processing tools and can access more than 300 image formats.
GFL is free for non-commercial use, you can grab the latest version at http://www.xnview.org. People wanting to use it in a commercial application must ask authorization to the author.
Nearly all methods croak their usage when called with improper or missing arguments.
All methods and attributes are case insensitive. You may say either
$a -> set( 'output' => 'bmp')
or
$a -> Set( Output => 'bmp')
or even
$a -> SeT(OUtPuT => 'bmp')
If the idea of loosing 3 seconds per 100000 method calls makes you sick, use all lowercase for method names to avoid Autoloading overhead. (timed on a Duron 850Mhz)
Create a new object. Assigning attributes via new is deprecated.
new
Set single or multiple attributes. Valid attributes are :
Define the number of possible undos.
If undolevel changes and happens to be lower than the current number of undos, older undos are cleared accordingly (in FIFO order).
undolevel
Set the verbosity level on STDERR:
False - no STDERR report 1 - report normal operations + errors (anonymously) 2 - normal operations + errors, with object identifier 3 - the above plus various internal/cleaning operations
The format you want the image to be saved as. Writable formats are:
'alias' : Alias Image File 'arcib' : ArcInfo Binary 'bmp' : Windows Bitmap 'cin' : Kodak Cineon 'degas' : Degas & Degas Elite 'dkb' : DKB Ray-Tracer 'gif' : CompuServe GIF 'gpat' : Gimp Pattern 'grob' : HP-48/49 GROB 'hru' : HRU 'ico' : Windows Icon 'iff' : Amiga IFF 'jif' : Jeff's Image Format 'jpeg' : JPEG / JFIF 'miff' : Image Magick file 'mtv' : MTV Ray-Tracer 'palm' : Palm Pilot 'pbm' : Portable Bitmap 'pcl' : Page Control Language 'pcx' : Zsoft Publisher's Paintbrush 'pgm' : Portable Greyscale 'png' : Portable Network Graphics 'pnm' : Portable Image 'ppm' : Portable Pixmap 'psion3' : Psion Serie 3 Bitmap 'psion5' : Psion Serie 5 Bitmap 'qrt' : Qrt Ray-Tracer 'rad' : Radiance 'raw' : Raw 'ray' : Rayshade 'rla' : Wavefront Raster file 'sgi' : Silicon Graphics RGB 'soft' : Softimage 'tga' : Truevision Targa 'ti' : TI Bitmap 'tiff' : TIFF Revision 6 'uyvy' : YUV 16Bits 'uyvyi' : YUV 16Bits Interleaved 'vista' : Vista 'vivid' : Vivid Ray-Tracer 'wbmp' : Wireless Bitmap (level 0) 'wrl' : VRML2 'xbm' : X11 Bitmap 'xpm' : X11 Pixmap
Boolean.
Preferred dithering method for black & white pictures.
One of: floyd, pattern, halftone45, halftone90
Defaults to floyd.
floyd
Defines picture quality (vs. size) for jpeg, wic , fpx formats.
jpeg
wic
fpx
0 < value > 100 (best quality)
value
Defines compression level for png format.
png
0 < value > 6 (best compression)
Boolean. For gif format.
gif
Boolean. For jpeg format.
Boolean. If set to True, a correct extension is added to the filename when saving, or it's extension is replaced if incorrect.
True
filename
Defines how to store channels in file.
One of: interleaved, sequential, separate Defaults to: interleaved
interleaved
Defines a desired compression method.
One of:
none, rle, lzw, jpeg, zip, sgi_rle, ccitt_rle, ccitt_fax3, ccitt_fax3_2d, ccitt_fax4, wavelet or lzw_predictor
# FIXME : This option does not seem to have any effect ... I'll ask more informations to the GFL library's author.
The input format. Defaults to 'auto', where GFL tries to guess the format.
Input formats are too numerous to be listed here. Just say dumpallformats() for a comprehensive list.
dumpallformats()
An integer.
1 (default), 2, 4, ...
Get single or multiple attributes.
Valid (case insensitive) attributes are all Set-able attributes plus :
Brings you a hash reference containing various informations about the current loaded file (as it is on the disk, not as it is in memory ! - this does not reflect any manipulations you have applied)
e.g:
$infos = $a->get(FileInformations) || die $a->lasterror; foreach (keys %$infos) { print "$_ => $infos->{$_}\n" if $infos->{$_}; }
sample output:
Origin => 16 Description => Sgi RGB Width => 182 CompressionDescription => Sgi Rle BitsPerPlane => 8 FileSize => 98145 NumberOfPlanes => 3 FormatName => sgi NumberOfImages => 1 FormatIndex => 4 Height => 170 BytesPerPlane => 182 Compression => 5
remember this is an hash reference, so you must access every member like this:
$infos->{'Width'}
FileInformations attribute change only when you open a new file.
To retrieve informations about a file before loading it, see function GetFileInformations()
GetFileInformations()
For informations about the current state of the image in memory, see BitmapInformations attribute.
BitmapInformations
Brings you a hash reference containing various informations about the current working Bitmap.
Sample Hash:
Xdpi => 68 BytesPerLine => 546 Width => 182 BitsPerComponent => 8 Ydpi => 68 Data => GFL_UINT8Ptr=SCALAR(0x81834ec) Height => 170 BytesPerPixel => 3 TransparentIndex => -1 Type => 16
Return the number of unique colors in the working bitmap.
Width in pixels of the current working bitmap
Height in pixels of the current working bitmap
Open the given file.
- If input attribute is set to 'auto' (the default), GFL will attempt to guess the format.
input
- ImageIndex indicates which image should be loaded in the case of a multi-image or animated file. It is zero-based.
ImageIndex
Open a custom size preview for the given file.
The preview becomes the current working bitmap.
- If input is set to 'auto' (the default), GFL will attempt to guess the format.
- width and height will be rounded to the nearest integer value if fractionals.
width
height
$i = getfileinformations('foo.png') or die; $a = GFL::Image->new; $a -> loadpreview('foo.png', $i->{'Width'}/3, $i->{'Height'}/3);
Save the current Bitmap using attribute Output as format.
Output
Be aware that there is no checking to see if current Output format support the actual color depth.
If the GFL library reports " Can't save this bitmap in this format !", see ChangeDepth() method.
ChangeDepth()
Rescale the image to the given Width/Height values.
If the keyword 'Quick' is given as third argument, resize method is set to quick ; otherwise, Bilinear method applies.
If Width and Height are fractionals, they are rounded to the nearest integer.
Width
Height
Flip image on the given axis.
Negate current image
Crop image starting at (x,y) coordinates from current Origin
Origin
Apply a rotation of "Angle" degrees.
Apply the given filters.
Where filter_type is one of: average, gaussianblur, maximum, minimum, medianbox, mediancross
average
gaussianblur
maximum
minimum
medianbox
mediancross
And filter_size is one of: 3, 5, 7, 9, 11, 13
3
5
7
9
11
13
Multiple filters are applied following arguments order.
Change the color depth of current working bitmap.
new_depth is one of:
binary, 4g, 8g, 16g, 32g, 64g, 128g, 216g, 256g, 8, 16, 32, 64, 128, 216, 256 ,truecolors
Values containing a "g" like "32g" mean greyscale.
If the dither attribute is set (boolean), then image is dithered with Adaptative algorithm.
dither
If, additionaly, wanted colordepth is 'binary', then dither will read the binarydither attribute and use the corresponding algorithm.
binarydither
Retrieve the last error message.
Those functions aren't really methods : they do not process the object when called from it. Thus, they don't have error handling as defined in ERROR HANDLING section. However, if getfileinformations(filename) is called as a method on an object, you may retrieve an eventual error via $obj->lasterror;
getfileinformations(filename)
$obj->lasterror
getfileinformations() and dumpallformats() are also exported (in lowercase) in your namespace, so you can use them from scratch.
Returns a hash reference containing detailed informations about a given file, or false on error. If format is not defined, GFL tries to autodetect it.
format
See also FileInformations attribute.
FileInformations
If you've got a patent from UNISIS, you may enable LZW compression (this is class wide). This compression algorithm is used by GIF & TIFF formats.
Always the same sad story...
Issue the complete list of supported formats with description and Read/Write flag.
Well, TIMTOWTDI...
To begin with, all methods except get() bring back a status report which is different in LIST and SCALAR context.
Error reporting in LIST context
Here, you are testing for error. You get a list with two values :
- first value is true if the function failed, false otherwise.
- second value is either an error string or the string 'OK'
'OK'
@error = $a -> rotate(100); if ($error[0]) { print STDERR $error[1]; }
Error reporting in SCALAR context
Here, you are testing for Success. You get true if the method succeeded, false otherwise.
$a-> rotate(100) && $success++;
error reporting via LastError attribute
In either SCALAR or LIST context, the LastError attribute is always updated with false or an error message after a method call.
As using get() would also affect lasterror, you must retrieve it via the special accessor ->lasterror.
get()
lasterror
->lasterror
Thus, you can say:
$b = $a -> get('dither'); $errormsg = $a ->lasterror and print "couldn't get dither value : $errormsg\n";
error reporting on STDERR
See the Verbose attribute if you want reports on STDERR.
copyright 2001 Germain Garand (germain@ebooksfrance.com)
This wrapper is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
GD(3), Image::Magick(3)
To install GFL, copy and paste the appropriate command in to your terminal.
cpanm
cpanm GFL
CPAN shell
perl -MCPAN -e shell install GFL
For more information on module installation, please visit the detailed CPAN module installation guide.