Wx::Perl::Imagick - A drop-in replacement for Wx::Image with all functionality of Image::Magick |
GetSubImage(rect)
LoadFile(filename)
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:
new(bitmap)
new(icon)
Wx::Perl::Imagick->new('somefile.jpg', undef, 0); # you can omit the last two parameters if you like
This method does nothing. Wx::Perl::Magick does not use wxWidget's ImageHandlers;
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
This method does nothing. Wx::Perl::Magick does not use wxWidget's ImageHandlers;
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
This method does nothing. Wx::Perl::Magick does not use wxWidget's ImageHandlers;
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.
GetSubImage(rect)
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 method does nothing. Wx::Perl::Magick does not use wxWidget's ImageHandlers;
This method does nothing. Wx::Perl::Magick does not use wxWidget's ImageHandlers;
LoadFile(filename)
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 method does nothing. Wx::Perl::Magick does not use wxWidget's ImageHandlers;
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.
Not implemented
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>
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.
I will be notified, and then you'll automatically be notified of progress on
your bug as I make changes.
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.
Wx::Perl::Imagick - A drop-in replacement for Wx::Image with all functionality of Image::Magick |