OpenGL-Image
view release on metacpan or search on metacpan
=head1 DESCRIPTION
This module is an extensible wrapper to abstract imaging interfaces
By default, this module uses the OpenGL::Image::Targa module; support for
other imaging libraries may be added by providing plug-in modules
in the OpenGL/Image folder.
An OpenGL::Image::Magick module is also provided for use with
PerlMagick. For best performance, ImageMagick 6.3.5 or newer should
be installed.
=head1 SYNOPSIS
##########
# Check for installed imaging engines
use OpenGL::Image;
Image/Magick.pm view on Meta::CPAN
############################################################
#
# OpenGL::Image::Magick - Copyright 2007 Graphcomp - ALL RIGHTS RESERVED
# Author: Bob "grafman" Free - grafman@graphcomp.com
#
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
############################################################
package OpenGL::Image::Magick;
require Exporter;
use Carp;
use vars qw($VERSION $DESCRIPTION @ISA);
$VERSION = '1.02';
$DESCRIPTION = qq
{Supports optimized internal interfaces to the ImageMagick library.};
use OpenGL::Image::Common;
@ISA = qw(Exporter OpenGL::Image::Common);
use OpenGL(':constants');
=head1 NAME
OpenGL::Image::Magick - copyright 2007 Graphcomp - ALL RIGHTS RESERVED
Author: Bob "grafman" Free - grafman@graphcomp.com
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=head1 DESCRIPTION
This is a driver module for use with the OpenGL module.
While it may be called directly, it will more often be called
by the OpenGL::Image abstraction module.
Note: OpenGL::Image defaults to this module.
This is a subclass of the OpenGL::Image::Common module.
Requires the Image::Magick module; 6.3.5 or newer is recommended.
=head1 SYNOPSIS
##########
# Check for installed imaging engines
use OpenGL::Image;
my $img = new OpenGL::Image(engine=>'Magick',source=>'MyImage.png');
Image/Magick.pm view on Meta::CPAN
$img->Ptr();
# Save file - automatically does a Sync before write
$img->Save('MyImage.png');
# Get image blob.
my $blob = $img->GetBlob();
=cut
eval 'use Image::Magick';
# Get engine version
sub EngineVersion
{
return $Image::Magick::VERSION;
}
# Get engine description
sub EngineDescription
{
return $DESCRIPTION;
}
# Base constructor
sub new
Image/Magick.pm view on Meta::CPAN
$self->{params}->{version} = EngineVersion();
$self->{params}->{components} = 4;
$self->{params}->{alpha} = 0;
$self->{params}->{flipped} = 1;
# Use source image if supplied
my $img;
if ($self->{params}->{source})
{
$img = new Image::Magick();
return undef if (!$img);
my $stat = $img->Read($self->{params}->{source});
return undef if ($stat);
($self->{params}->{width},$self->{params}->{height}) =
$img->Get('Width','Height');
return undef if (!$self->{params}->{width} || !$self->{params}->{height});
$self->{native} = $img;
Image/Magick.pm view on Meta::CPAN
# Otherwise create uninitialized image
else
{
my $w = $self->{params}->{width};
my $h = $self->{params}->{height};
my $blob = $self->{params}->{blob};
if ($w && $h)
{
my $dim = $w.'x'.$h;
$self->{native} = new Image::Magick(size=>$dim, magick=>'RGBA', depth=>8);
}
elsif ($blob)
{
$self->{native} = new Image::Magick();
}
return undef if (!$self->{native});
$img = $self->{native};
# Populate with blob
if ($blob)
{
my $stat = $img->BlobToImage($blob);
return undef if ($stat);
t/OpenGL-Image.t view on Meta::CPAN
eval($exec);
$t->bail("OpenGL::Image failed to load: $@") if ($@ || !$ogi_ver);
$t->ok("OpenGL::Image module loaded: v$ogi_ver");
#2 Get ImageMagick version
my $im_ver = 0;
$exec = qq
{
use Image\::Magick;
\$im_ver = \$Image::Magick::VERSION;
};
eval($exec);
if ($@ || !$im_ver)
{
$t->skip("Image::Magick module not installed: $@")
}
elsif ($im_ver lt '6.3.5' )
{
$t->skip("Image::Magick module installed: v$im_ver - recommend 6.3.5 or newer");
}
else
{
$t->ok("Image::Magick module installed: v$im_ver");
}
#3 Enumerate installed engines
$t->status("Testing OpenGL::Image::GetEngines():");
my $engines = OpenGL::Image::GetEngines();
my @engines = keys(%$engines);
$t->bail("No imaging engines installed!") if (!@engines);
my $has_TGA = 0;
my $has_IM = 0;
t/OpenGL-Image.t view on Meta::CPAN
{
$t->bail("Native->Get('width','height') returned invalid dimensions");
}
$t->ok("Native->Get('width','height') returned: $x x $y");
#24 Test GetBlob()
$blob = $src->GetBlob(magick=>'jpg');
$t->bail("GetBlob(type=>'jpg') failed to return a blob") if (!$blob);
my $im = Image::Magick->new(magick=>'jpg');
$im->BlobToImage($blob);
my($w0,$h0) = $im->Get('width','height');
if (!$w0 || !$h0)
{
$t->bail("GetBlob(type=>'jpg') failed");
}
elsif ($w != $w0 || $h != $h0)
{
$t->bail("GetBlob(type=>'jpg') returns invalid dimensions: $w0 x $h0");
}
( run in 0.840 second using v1.01-cache-2.11-cpan-beeb90c9504 )