The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Wx::Perl::Imagick - A drop-in replacement for Wx::Image with all functionality of Image::Magick

VERSION

Version 0.01

SYNOPSIS

    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');
    ...

DESCRIPTION

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.

INCOMPATIBILITIES

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.

Wx::Image compatible METHODS

new

There are several ways to construct a new Wx::Perl::Imagick object. These are:

Wx::Perl::Imagick->new(bitmap)

Simply supply a Wx::Bitmap and it will create a Wx::Perl::Imagick object from it.

Wx::Perl::Imagick->new(icon)

Simply supply a Wx::Icon and it will create a Wx::Perl::Imagick object from it.

Wx::Perl::Imagick->new(width, height)

This will create a new, empty Wx::Perl::Imagick object with the given width and height.

Wx::Perl::Imagick->new(width, height, data)

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.

Wx::Perl::Imagick->new(file, (mime)type, index = 0)

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
Wx::Perl::Imagick->new( stream, (mime)type, index )

This form IS NOT SUPPORTED. Therefore it's an incompatible difference between Wx::Image and Wx::Perl::Imagick.

AddHandler

This method does nothing. Wx::Perl::Magick does not use wxWidget's ImageHandlers;

CleanupHandlers

This method does nothing. Wx::Perl::Magick does not use wxWidget's ImageHandlers;

ComputeHistogram

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.

ConvertToBitmap

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.

ConvertToMono

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.

Copy

Returns an identical copy of the image.

Create

Not implemented. Use new() instead.

Destroy

Destroys the image data

FindFirstUnusedColour

Not implemented in wxPerl, not here either

FindHandler

This method does nothing. Wx::Perl::Magick does not use wxWidget's ImageHandlers;

GetBlue(x, y)

Returns the blue intensity at the given coordinate.

GetData

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.

GetGreen(x, y)

Returns the green intensity at the given coordinate.

GetImageCount

Not implemented. See GetLoadedImageCount below

GetHandlers

This method does nothing. Wx::Perl::Magick does not use wxWidget's ImageHandlers;

GetHeight

Gets the height of the image in pixels.

GetMaskBlue

Gets the blue value of the transparent colour.

GetMaskGreen

Gets the green value of the transparent colour.

GetMaskRed

Gets the red value of the transparent colour.

GetPalette

Not implemented.

GetRed(x, y)

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.

GetWidth

Gets the width of the image in pixels

HasMask

Returns 1 if there is a mask active, 0 otherwise.

GetOption

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)

GetOptionInt

See GetOption.

HasOption

InitStandardHandlers

This method does nothing. Wx::Perl::Magick does not use wxWidget's ImageHandlers;

InsertHandler

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.

Ok

This returns 1 if an image has been loaded. Returns 0 otherwise.

RemoveHandler

This method does nothing. Wx::Perl::Magick does not use wxWidget's ImageHandlers;

SaveFile

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.

Mirror(horizontally = 1)

Returns a mirrored copy of the image. The parameter horizontally indicates the orientation.

Replace

This has not yet been implemented.

Rescale

see Scale();

Rotate

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:

degrees => double
color => colorname

Rotate90(clockwise = 1)

Returns a copy of the image rotated 90 degrees in the direction indicated by clockwise.

Scale

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:

geometry => geometry
width => integer
height => integer

SetData

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.

SetMask(HasMask = 1)

Specifies whether there is a mask or not.

SetMaskColour

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.

SetMaskFromImage

Not implemented

SetOption

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.

SetPalette

Not implemented

SetRGB(x, y, red, green, blue)

Sets the pixel at the given coordinate to the given red, green and blue values.

Image::Magick compatible METHODS

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

CONVENIENCE METHODS

There are a few methods I've added that are neither part of Wx::Image, nor of Image::Magick. They are just for convenience:

MagickError

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.

SetIndex

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

GetIndex

This returns the index we set earlier with SetIndex.

GetLoadedImageCount

If we have loaded more than one image, this will return the number of images loaded.

AUTHOR

Jouke Visser, <jouke@cpan.org>

BUGS

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.

COPYRIGHT & LICENSE

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.