Wx-Perl-Imagick

 view release on metacpan or  search on metacpan

META.yml  view on Meta::CPAN

# http://module-build.sourceforge.net/META-spec.html
#XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
name:         Wx-Perl-Imagick
version:      0.02
version_from: lib\Wx\Perl\Imagick.pm
installdirs:  site
requires:
    Image::Magick:                 0
    Test::More:                    0
    Wx:                            0

distribution_type: module
generated_by: ExtUtils::MakeMaker version 6.17

Makefile.PL  view on Meta::CPAN


WriteMakefile(
    NAME                => 'Wx::Perl::Imagick',
    AUTHOR              => 'Jouke Visser <jouke@cpan.org>',
    VERSION_FROM        => 'lib\Wx\Perl\Imagick.pm',
    ABSTRACT_FROM       => 'lib\Wx\Perl\Imagick.pm',
    PL_FILES            => {},
    PREREQ_PM => {
        'Test::More'    => 0,
        'Wx'            => 0,
        'Image::Magick' => 0
    },
    dist                => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
    clean               => { FILES => 'Wx-Perl-Imagick-*' },
);

README  view on Meta::CPAN

Wx-Perl-Imagick

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.

INSTALLATION

To install this module, run the following commands:

    perl Makefile.PL
    make
    make test
    make install

lib/Wx/Perl/Imagick.pm  view on Meta::CPAN

package Wx::Perl::Imagick;
use strict;
use warnings;

our $VERSION = '0.02';

use Wx qw(wxNullBitmap);
use Image::Magick;
use IO::Scalar;
use Wx::Perl::Carp qw(cluck);
use base 'Clone';
#----------------------------------------------------------------------
# Compatibility methods for Wx::Image
#
sub new
{
    my $proto    = shift;
    my $class    = ref($proto) || $proto;
    my $self     = {};
    $self->{_im} = Image::Magick->new();
    
    # When we convert the Wx::Perl::Imagick object to a Wx::Bitmap we convert
    # it to PNG first...so we need the PNGHandler
    Wx::Image::AddHandler(Wx::PNGHandler->new);
    
    bless $self, $class;
    
    if (UNIVERSAL::isa($_[0], 'Wx::Bitmap'))
    {
        my $bitmap = shift;

lib/Wx/Perl/Imagick.pm  view on Meta::CPAN

    print STDERR "Wx::Perl::Imagick::SetPalette is not implemented";
}

sub SetRGB
{
    my ($self, $x, $y, $r, $g, $b) = @_;
    $self->Set("pixel[$x,$y]", sprintf('#%02x%02x%02x', $r,$g,$b));
}

#----------------------------------------------------------------------
# Compatibility methods for Image::Magick
#
our ($AUTOLOAD);
sub AUTOLOAD
{
    my $self = shift;
    my @params = @_;
    (my $auto = $AUTOLOAD) =~ s/.*:://;
    my $obj;
    if ((exists $self->{_im}->[$self->{_index}]) && ($auto ne 'Read'))
    {

lib/Wx/Perl/Imagick.pm  view on Meta::CPAN

    }
}

#----------------------------------------------------------------------
# Convenience methods
#
sub MagickError
{
    my $self  = shift;
    my $error = shift;
    cluck "Image::Magick returned an error: \n$error" if $error;
}

sub SetIndex
{
    $_[0]->{_index} = $_[1];
}

sub GetIndex
{
    $_[0]->{_index};
}

sub GetLoadedImageCount
{
    return $#{$_[0]->{_im}}+1;
}


=head1 NAME

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

=head1 VERSION

Version 0.01

=head1 SYNOPSIS

    use Wx::Perl::Imagick;

    # Load an imagefile that contains more than one image

lib/Wx/Perl/Imagick.pm  view on Meta::CPAN

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

=head1 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.

=head1 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. 

=head1 Wx::Image compatible METHODS

=head2 new

lib/Wx/Perl/Imagick.pm  view on Meta::CPAN

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

=item 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.

=item 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

=item 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.

lib/Wx/Perl/Imagick.pm  view on Meta::CPAN

=head2 AddHandler

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

=head2 CleanupHandlers

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

=head2 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.

=head2 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.

lib/Wx/Perl/Imagick.pm  view on Meta::CPAN

=head2 GetWidth

Gets the width of the image in pixels

=head2 HasMask

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

=head2 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)

=head2 GetOptionInt

See GetOption.

=head2 HasOption

=head2 InitStandardHandlers

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

=head2 InsertHandler

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

=head2 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.

=head2 Ok

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

=head2 RemoveHandler

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

=head2 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.

=head2 Mirror(horizontally = 1)

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

=head2 Replace

This has not yet been implemented.

=head2 Rescale

see Scale();

=head2 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:

=over 4

=item degrees => double

=item color => colorname

=back

=head2 Rotate90(clockwise = 1)

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

=head2 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:

=over 4

=item geometry => geometry

=item width => integer

=item height => integer

=back

lib/Wx/Perl/Imagick.pm  view on Meta::CPAN

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.

=head2 SetMask(HasMask = 1)

Specifies whether there is a mask or not. 

=head2 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.

=head2 SetMaskFromImage

Not implemented

=head2 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.

=head2 SetPalette

Not implemented

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

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

=head1 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
L<http://www.imagemagick.org/script/perl-magick.php>

=head1 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:

=head2 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.

=head2 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



( run in 0.725 second using v1.01-cache-2.11-cpan-beeb90c9504 )