From bde1a7a941be0bcf6fa9b04e5aeed72b27464dcc Mon Sep 17 00:00:00 2001 From: JT Smith Date: Thu, 26 Jul 2007 03:23:47 +0000 Subject: [PATCH] Graphics::Magick is now the standard graphics package in WebGUI, but Image::Magick will be supported for backwards compatibility. See gotcha.txt for details. --- docs/changelog/7.x.x.txt | 3 +++ docs/gotcha.txt | 11 +++++++++++ lib/WebGUI/Image.pm | 19 +++++++++++++++++-- lib/WebGUI/Image/Graph/Pie.pm | 4 ++-- lib/WebGUI/Storage/Image.pm | 25 ++++++++++++++++++++----- sbin/testEnvironment.pl | 3 ++- 6 files changed, 55 insertions(+), 10 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 635c685c1..7ef765309 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -10,6 +10,9 @@ - api: You may now use a customDrawMethod attribute in your asset properties list that will enable you to add custom display options for that fields when the edit form is automatically generated. + - Graphics::Magick is now the standard graphics package in WebGUI, but + Image::Magick will be supported for backwards compatibility. See gotcha.txt + for details. - Added file attachments to the Wiki. - Added a new attachments form control. - Added a form control skeleton. diff --git a/docs/gotcha.txt b/docs/gotcha.txt index a3bbd3306..76f54651a 100644 --- a/docs/gotcha.txt +++ b/docs/gotcha.txt @@ -33,6 +33,17 @@ save you many hours of grief. Class::InsideOut HTML::TagCloud + * WebGUI now uses Graphics::Magick instead of Image::Magick for + image processing functions. However, for the next few versions you + will still be able to use Image::Magick if you already have it + installed, to make the transition easier. Graphics::Magick is a + fork of Image::Magick, but it's focus is stability and compatibility + over adding new features. Another note will be added to this file + when support for Image::Magick is officially removed. That will + most likely happen in WebGUI 7.6.0. Note that WRE 0.8.0 includes + Graphics::Magick, so if you upgrade to WRE 0.8.0 then you'll + automatically be ready for the future. + * Any customizations made to the Inbox or Inbox/Message tempalates will be lost. Please back up your custom templates before running the upgrade diff --git a/lib/WebGUI/Image.pm b/lib/WebGUI/Image.pm index 198103615..f4df72211 100644 --- a/lib/WebGUI/Image.pm +++ b/lib/WebGUI/Image.pm @@ -1,8 +1,23 @@ package WebGUI::Image; use strict; -use Image::Magick; use WebGUI::Image::Palette; +use Carp qw(croak); +eval 'use Graphics::Magick'; +my $graphicsMagickAvailable = ($@) ? 0 : 1; +eval 'use Image::Magick'; +my $imageMagickAvailable = ($@) ? 0 : 1; +my $graphicsPackage = ''; +if ($imageMagickAvailable) { + $graphicsPackage = "Image::Magick"; +} +elsif ($graphicsMagickAvailable) { + $graphicsPackage = "Graphics::Magick"; +} +else { + croak "You must have either Graphics::Magick or Image::Magick installed to run WebGUI.\n"; +} + =head1 NAME @@ -173,7 +188,7 @@ sub new { my $width = shift || 300; my $height = shift || 300; - my $img = Image::Magick->new( + my $img = $graphicsPackage->new( size => $width.'x'.$height, ); diff --git a/lib/WebGUI/Image/Graph/Pie.pm b/lib/WebGUI/Image/Graph/Pie.pm index 6290fbcdd..4c9a45bbd 100644 --- a/lib/WebGUI/Image/Graph/Pie.pm +++ b/lib/WebGUI/Image/Graph/Pie.pm @@ -1118,8 +1118,8 @@ sub processDataset { } my $dataIndex = 0; - - my $stepsize = ($self->getTopHeight + $self->getBottomHeight) / scalar(@{$self->getDataset}); + my $divisor = scalar(@{$self->getDataset}) || 1; # avoid division by zero + my $stepsize = ($self->getTopHeight + $self->getBottomHeight) / $divisor; foreach (@{$self->getDataset}) { $self->addSlice({ percentage => $_ / $total, diff --git a/lib/WebGUI/Storage/Image.pm b/lib/WebGUI/Storage/Image.pm index d31a53701..621a9f216 100644 --- a/lib/WebGUI/Storage/Image.pm +++ b/lib/WebGUI/Storage/Image.pm @@ -14,10 +14,25 @@ package WebGUI::Storage::Image; =cut -use Image::Magick; use strict; use WebGUI::Storage; use WebGUI::Utility; +use Carp qw(croak); +eval 'use Graphics::Magick'; +my $graphicsMagickAvailable = ($@) ? 0 : 1; +eval 'use Image::Magick'; +my $imageMagickAvailable = ($@) ? 0 : 1; +my $graphicsPackage = ''; +if ($imageMagickAvailable) { + $graphicsPackage = "Image::Magick"; +} +elsif ($graphicsMagickAvailable) { + $graphicsPackage = "Graphics::Magick"; +} +else { + croak "You must have either Graphics::Magick or Image::Magick installed to run WebGUI.\n"; +} + our @ISA = qw(WebGUI::Storage); @@ -62,7 +77,7 @@ sub addFileFromCaptcha { srand; $challenge.= ('A'..'Z')[rand(26)] foreach (1..6); my $filename = "captcha.".$self->session->id->generate().".png"; - my $image = Image::Magick->new(); + my $image = $graphicsPackage->new(); $image->Set(size=>'105x26'); $image->ReadImage('xc:white'); $image->AddNoise(noise=>"Multiplicative"); @@ -144,7 +159,7 @@ sub generateThumbnail { $self->session->errorHandler->warn("Can't generate a thumbnail for something that's not an image."); return 0; } - my $image = Image::Magick->new; + my $image = $graphicsPackage->new; my $error = $image->Read($self->getPath($filename)); if ($error) { $self->session->errorHandler->error("Couldn't read image for thumbnail creation: ".$error); @@ -211,7 +226,7 @@ sub getSizeInPixels { $self->session->errorHandler->error("Can't check the size of something that's not an image."); return 0; } - my $image = Image::Magick->new; + my $image = $graphicsPackage->new; my $error = $image->Read($self->getPath($filename)); if ($error) { $self->session->errorHandler->error("Couldn't read image to check the size of it: ".$error); @@ -303,7 +318,7 @@ sub resize { $self->session->errorHandler->error("Can't resize with no resizing parameters."); return 0; } - my $image = Image::Magick->new; + my $image = $graphicsPackage->new; my $error = $image->Read($self->getPath($filename)); if ($error) { $self->session->errorHandler->error("Couldn't read image for resizing: ".$error); diff --git a/sbin/testEnvironment.pl b/sbin/testEnvironment.pl index 34e3f2458..ad12ec96d 100644 --- a/sbin/testEnvironment.pl +++ b/sbin/testEnvironment.pl @@ -94,7 +94,8 @@ checkModule("DateTime",0.2901); checkModule("Time::HiRes",1.38); checkModule("DateTime::Format::Strptime",1.0601); checkModule("DateTime::Format::Mail",0.2901); -checkModule("Image::Magick",6.0); +checkModule("Image::Magick","6.0",2); +checkModule("Graphics::Magick","1.1.7",2); checkModule("Log::Log4perl",0.51); checkModule("Net::LDAP",0.25); checkModule("HTML::Highlight",0.20);