Wx::Perl::Imagick - A drop-in replacement for Wx::Image with all functionality of Image::Magick
Version 0.01
use Wx::Perl::Imagick; # Load an imagefile that contains more than one image my $image = Wx::Perl::Imagick->new('pvoice.ico'); my $bmp = Wx::StaticBitmap->new($panel, -1, $image->ConvertToBitmap); # Select the next image in the file $image->SetIndex(1); $bmp = Wx::StaticBitmap->new($panel, -1, $image->ConvertToBitmap, [100,100]); # We can also create an image from a Wx::Image my $img = Wx::Image->new('car.jpg','image/jpeg'); my $magick = Wx::Perl::Imagick->new($img->GetWidth, $img->GetHeight, $img->GetData); my $bitmap = $magick->ConvertToBitmap; my $bmp2 = Wx::StaticBitmap->new($panel, -1, $bitmap, [300,300]) if $bitmap->Ok; # Or we can create an image from a Wx::Bitmap my $frombmp = Wx::Perl::Imagick->new($bitmap); my $newbitmap = $newbitmap->ConvertToBitmap; $bmp = Wx::StaticBitmap->new($panel, -1, $newbitmap, [400,400]) if $newbitmap->Ok; # And we can create an image from a Wx::Icon my $icon = Wx::Icon->new('pvoice.ico',wxBITMAP_TYPE_ICO, 16,16 ); my $fromicon = Wx::Perl::Imagick->new($icon); my $anotherbitmap = $fromicon->ConvertToBitmap; $bmp = Wx::StaticBitmap->new($panel, -1, $anotherbitmap, [500,500]) if $anotherbitmap->Ok; ... # Now it's also possible to use Image::Magick's conversions and filters $magick->->Crop(geometry=>'100x100"+100"+100'); ...
This class is meant to be a replacement for Wx::Image, adding all functionality of Image::Magick. Hence the name Wx::Perl::Imagick. Most of the API of Wx::Image has been copied for backwards compatibility, but you can also call any method of Image::Magick on a constructed Wx::Perl::Magick instance. This will greatly improve the possibilities you have with an image in wxPerl.
While I've tried to keep all methodcalls that Wx::Image knows the same for Wx::Perl::Imagick, there are some incompatible differences. You can find these differences in the 'Wx::Image compatible METHODS' section below.
There are several ways to construct a new Wx::Perl::Imagick object. These are:
Simply supply a Wx::Bitmap and it will create a Wx::Perl::Imagick object from it.
Simply supply a Wx::Icon and it will create a Wx::Perl::Imagick object from it.
This will create a new, empty Wx::Perl::Imagick object with the given width and height.
This will create a new Wx::Perl::Imagick object from the supplied data (which can be -for example- generated from Wx::Image's GetData), using the given width and height.
This will load the file indicated. If a mimetype or type is supplied, the constructor will generate a print STDERRing, because Wx::Perl::Imagick lets Image::Magick figure out the type of the file, and ignores this parameter. The index points out which of the images that the indicated file provides will be the default one. To use this form without print STDERRings, you'd better call it like this:
Wx::Perl::Imagick->new('somefile.jpg', undef, 0); # you can omit the last two parameters if you like
This form IS NOT SUPPORTED. Therefore it's an incompatible difference between Wx::Image and Wx::Perl::Imagick.
This method does nothing. Wx::Perl::Magick does not use wxWidget's ImageHandlers;
Unlike wxPerl, Wx::Perl::Imagick does implement it, albeit just an alias for Image::Magick's Histogram() method. It returns the unique colors in the image and a count for each one. The returned values are an array of red, green, blue, opacity, and count values.
Unlike wxPerl, Wx::Perl::Imagick does implement this, because we need a way to convert between Wx::Perl::Imagick objects and Wx::Bitmap objects. Since Wx::Bitmap does not know about Wx::Perl::Magick, we need to make Wx::Perl::Magick aware of a Wx::Bitmap... It does just what it suggests, it returns a bitmap from the currently loaded image.
Returns monochromatic version of the image. The returned image has white colour where the original has (r,g,b) colour and black colour everywhere else.
Returns an identical copy of the image.
Not implemented. Use new() instead.
Destroys the image data
Not implemented in wxPerl, not here either
Returns the blue intensity at the given coordinate.
Returns the image data as an array. This is most often used when doing direct image manipulation. The return value points to an array of characters in RGBRGBRGB... format.
Returns the green intensity at the given coordinate.
Not implemented. See GetLoadedImageCount below
Gets the height of the image in pixels.
Gets the blue value of the transparent colour.
Gets the green value of the transparent colour.
Gets the red value of the transparent colour.
Not implemented.
Returns the red intensity at the given coordinate.
Returns a sub image of the current one as long as the rect (of type Wx::Rect) belongs entirely to the image.
Gets the width of the image in pixels
Returns 1 if there is a mask active, 0 otherwise.
This is implemented in a different manner than in Wx::Image. It is in fact an alias for Image::Magick's Get() method. The suggested option 'quality' in the Wx::Image documentation works perfectly with GetOption('quality'). Since this method not documented any further in the wxWidgets documentation, I implemented it this way.
It can however return anything that Image::Magick returns (being a string or an integer)
See GetOption.
This loads the file indicated by filename. The second parameter that Wx::Image specifies is ignored (the filetype), since Image::Magick doesn't need any specification of the filetype.
This returns 1 if an image has been loaded. Returns 0 otherwise.
This saves the image to a file named filename. The second parameter that Wx::Image specifies is ignored (the filetype), since Image::Magick doesn't need any specification of the filetype.
Returns a mirrored copy of the image. The parameter horizontally indicates the orientation.
This has not yet been implemented.
see Scale();
Rotate is an Image::Magick method. To prevent name conflicts, the Wx::Image compatibility function has not been implemented. Image::Magick's Rotate knows the following parameters:
Returns a copy of the image rotated 90 degrees in the direction indicated by clockwise.
Scale is an Image::Magick method. To prevent name conflicts, the Wx::Image compatibility function has not been implemented. Image::Magick's Scale knows the following parameters:
Sets the image data without performing checks. The data given must have the size (width*height*3) or results will be unexpected. Don't use this method if you aren't sure you know what you are doing.
Specifies whether there is a mask or not.
This sets the transparent color of the current image. For some reason, after setting the MaskColour you cannot retrieve the color you just set with GetMaskRed, GetMaskGreen and GetMaskBlue. This seems to be a bug in Image::Magick. If you save the image after setting the MaskColour, it does use the color you indicated for transparency.
Not implemented
This is implemented in a different manner than in Wx::Image. It is in fact an alias for Image::Magick's Set() method. The suggested option 'quality' in the Wx::Image documentation works perfectly with SetOption(quality => 100). Since this method not documented any further in the wxWidgets documentation, I implemented it this way.
Sets the pixel at the given coordinate to the given red, green and blue values.
You can call any Image::Magick method on any Wx::Perl::Imagick object. The module tries to AUTOLOAD the Image::Magick method and returns the output immediately. See the documentation of Image::Magick at http://www.imagemagick.org/script/perl-magick.php
There are a few methods I've added that are neither part of Wx::Image, nor of Image::Magick. They are just for convenience:
If you perform an Image::Magick operation, you may want to call it like this:
my $img = Wx::Perl::Imagick->new('someimage.jpg'); $img->MagickError( $img->Resize(geometry => '100x100');
This will output the error if Image::Magick encounters anything.
If you load an imagefile that contains multiple images, you can call SetIndex to indicate on which of the images you want to perform the action. For example:
my $img = Wx::Perl::Imagick->new('pvoice.ico'); # contains 3 different icons $img->SetIndex(2); # we want to use the third icon my $data = $img->GetData; # now we get only the data from the third icon
This returns the index we set earlier with SetIndex.
If we have loaded more than one image, this will return the number of images loaded.
Jouke Visser, <jouke@cpan.org>
<jouke@cpan.org>
Please report any bugs or feature requests to bug-wx-perl-imagick@rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Wx-Perl-Imagick. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-wx-perl-imagick@rt.cpan.org
Copyright 2005 Jouke Visser, All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Wx::Perl::Imagick, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Wx::Perl::Imagick
CPAN shell
perl -MCPAN -e shell install Wx::Perl::Imagick
For more information on module installation, please visit the detailed CPAN module installation guide.