| Prima-Image-Magick documentation | Contained in the Prima-Image-Magick distribution. |
Prima::Image::Magick - Juggle images between Prima and Image::Magick
use Prima::Image::Magick; my $i = Prima::Image-> new( ... ); # native prima images $i-> MedianFilter( radius => 5); # can call Image::Magick methods
Allows transformations between Prima images and Image::Magick images.
Exports all methods found on Image::Magick into Prima::Image space, thus
opening the possibilities of ImageMagick for Prima images.
The mutator methods found on Image::Magick namespace are wrapped and
imported into Prima::Image space, so that an image is implictly converted
to Image::Magick and back, so that for example
$prima_image-> Edge( radius => 5);
is actually the same as
my $m = prima_to_magick( $prima_image);
$m-> Edge( radius => 5);
$prima_image = magick_to_prima( $m);
except that $prima_image internally remains the same perl object.
This approach is obviusly ineffective when more than one call to ImageMagick
code is required. To avoid the ineffeciency, wrappers BeginMagick and EndMagick
are declared, so
$prima_image-> BeginMagick;
$prima_image-> Edge( radius => 5);
$prima_image-> Enhance;
$prima_image-> EndMagick;
is same as
my $m = prima_to_magick( $prima_image);
$m-> Edge( radius => 5);
$m-> Enhance;
$prima_image = magick_to_prima( $m);
Returns a deep copy of $magick_image stored in a new instance of Prima::Image
object. $magick_image must contain exactly one ImageMagick bitmap. This means that
empty objects and objects f.ex. after Read('file1', 'file2') cannot be used here.
Use Image::Magick::Deconstruct to break image sequence into constituent parts.
Exported either by explicit request or as a part of use Prima::Image::Magick ':all' call.
Returns a deep copy of $prima_image stored in a new instance of Image::Magick
object.
Exported either by explicit request or as a part of use Prima::Image::Magick ':all' call.
Copies content of $prima_image to $magick_image. Not to be called directy
unless really necessary; the method is not exported, and its syntax may change
in future.
Copies content of $magick_image to $prima_image. Not to be called directy
unless really necessary; the method is not exported, and its syntax may change
in future.
Prima, Image::Magick, example.pl in examples.
Dmitry Karasik, <dmitry@karasik.eu.org>
Copyright (C) 2007 by Dmitry Karasik
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.
| Prima-Image-Magick documentation | Contained in the Prima-Image-Magick distribution. |
# $Id: Magick.pm,v 1.4 2008/01/02 21:16:54 dk Exp $ package Prima::Image::Magick; use strict; use warnings; require Exporter; our @ISA = qw(Exporter); our @EXPORT_OK = qw( prima_to_magick magick_to_prima ); our %EXPORT_TAGS = ( all => \@EXPORT_OK ); our $VERSION = '0.05'; require XSLoader; XSLoader::load('Prima::Image::Magick', $VERSION); use Prima; use Image::Magick; # proxy Image::Magick methods into Prima::Image { my $v = join('|', @Image::Magick::EXPORT); my %d = map { $_ => 1 } grep { !/^([a-z_].*|[A-Z_]+|$v|Prima)$/ } keys %Image::Magick::; # delete aliases for my $meth ( keys %d) { if ( exists $d{"${meth}Image"}) { delete $d{"${meth}Image"}; next; } } for my $meth ( keys %d) { next if exists $Prima::Image::{$meth}; my $sub = sub { my $self = shift; my $mag = $self-> BeginMagick; my @res; if ( wantarray) { @res = $mag-> $meth( @_ ); } else { $res[0] = $mag-> $meth( @_ ); } $self-> EndMagick; return wantarray ? @res : $res[0]; }; no strict 'refs'; *{"Prima::Image::$meth"} = $sub; } } sub Prima::Image::BeginMagick { my $self = $_[0]; if ( exists $self-> {__ImageMagickStorage} ) { $self-> {__ImageMagickStorage}-> [0]++; } else { $self-> {__ImageMagickStorage} = [ 0, prima_to_magick( $self ) ]; } $self-> {__ImageMagickStorage}-> [1]; } sub Prima::Image::EndMagick { my $self = $_[0]; return unless exists $self-> {__ImageMagickStorage} and 0 == $self-> {__ImageMagickStorage}->[0]--; convert_to_prima( $self-> {__ImageMagickStorage}->[1], $self); delete $self-> {__ImageMagickStorage}; } sub prima_to_magick { my ( $p) = @_; die "Not a Prima::Image object" unless $p and $p->isa('Prima::Image'); my $m = Image::Magick-> new(); convert_to_magick( $p, $m); $m; } sub magick_to_prima { my ( $m, %h) = @_; die "Not an Image::Magick object" unless $m and $m->isa('Image::Magick'); my $p = Prima::Image-> new; convert_to_prima( $m, $p); $p; } *Prima::Image::Magick = \&prima_to_magick; *Image::Magick::Prima = \&magick_to_prima; 1; __END__