Gossamer Forum
Home : General : Perl Programming :

Image::Magick showing blank images on some server, but not others?

Quote Reply
Image::Magick showing blank images on some server, but not others?
Hi. Could anyone shed some light on why this code works ok on some server, but on others it shows a blank image? (i.e everything *but* the text)

Its got me baffled :(

TIA

Code:
# this is the routine we will run when creating
# an Image::Magick image...
sub gen_Magick {

# grab stuff we need...
my ($string,$date) = @_;

# now we have our 'random' string, and date stuff, lets create the image...
use Image::Magick;

my $image = Image::Magick->new();
print $image->Set( size => "110x50");
print $image->ReadImage('xc:white');
print $image->Colorize( fill => $BackgroundColor );
print $image->Border( width => 5, height => 5, fill => $BorderColor );

# only do these things if the user has decided to...
if ($DoRaise) {
print $image->Raise( width => 5, height => 5, raise => 'True' );
}

# only do these things if the user has decided to...
if ($DoWave) {
print $image->Wave( amplitude => 5, wavelength => 30 );
}

# decide a random font to use...
my @fonts = ('Charter','Arial');
my @number= (0..2);
my $rand = int(rand scalar(@number));
my $font = $fonts[$rand]; #"Charter";

# annotate the image, so we have our string they need to enter...
$image->Annotate(
text => $string,
fill => $TextColor,
x => 15,
y => 30,
pointsize=> 15,
font => $font);


# setup some paths/urls etc...
my $path = $CFG->{build_root_path} . "/AddImages/" . $date . ".gif";
my $url = $CFG->{build_root_url};

print $image->Write($path);
undef $image;

# pass stuff back into our templates....
$IN->param( SessionDate => $date );
$IN->param( ImageURL => "$url/AddImages/$date.gif" );

}

1;

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Image::Magick showing blank images on some server, but not others? In reply to
Take advantage of Image Magick's built in error reporting. You should change every function to read something like:

Code:
my $x;

$x = $image->Write(filename=>"$writeimage");
die $x if $x

Do that for every function and then just look up in your error.log for the error message which is usually very intuitive.

- wil

Last edited by:

Wil: Oct 17, 2003, 10:11 AM
Quote Reply
Re: [Wil] Image::Magick showing blank images on some server, but not others? In reply to
That never worked for me before, but I'll give it a go again, and see if that uncovers anything :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Image::Magick showing blank images on some server, but not others? In reply to
Managed to track it down to this line;

Code:
print $image->Set(size=>'110x50') || die &error($! . __LINE__);

That is line 14, in the full routine below;

Code:
# this is the routine we will run when creating
# an Image::Magick image...
sub gen_Magick {

# grab stuff we need...
my ($string,$date) = @_;

# now we have our 'random' string, and date stuff, lets create the image...
use Image::Magick;

my $image = Image::Magick->new();
print $image->Set(size=>'110x50') || die &error($! . __LINE__);
print $image->ReadImage('xc:white') || die &error($! . __LINE__);
print $image->Colorize( fill => $BackgroundColor ) || die &error($! . __LINE__);
print $image->Border( width => 5, height => 5, fill => $BorderColor ) || die &error($! . __LINE__);

# only do these things if the user has decided to...
if ($DoRaise) {
print $image->Raise( width => 5, height => 5, raise => 'True' ) || die &error($! . __LINE__);
}

# only do these things if the user has decided to...
if ($DoWave) {
print $image->Wave( amplitude => 5, wavelength => 30 ) || die &error($! . __LINE__);
}

# decide a random font to use...
my @fonts = ('Charter','Arial');
my @number= (0..2);
my $rand = int(rand scalar(@number));
my $font = $fonts[$rand]; #"Charter";

# annotate the image, so we have our string they need to enter...
print $image->Annotate(
text => $string,
fill => $TextColor,
x => 15,
y => 30,
pointsize=> 15,
font => $font) || die &error($! . __LINE__);


# setup some paths/urls etc...
my $path = $CFG->{build_root_path} . "/AddImages/" . $date . ".gif";
my $url = $CFG->{build_root_url};

print $image->Write($path) || die &error($! . __LINE__);
undef $image;

# pass stuff back into our templates....
$IN->param( SessionDate => $date );
$IN->param( ImageURL => "$url/AddImages/$date.gif" );

}

sub error {

my $error = $_[0];

print $IN->header();
print "An error occured. It was: $error";
exit;

}

1;



Perl version is reported as 5.8.1 (see below);

Quote:
[gossamer@roger home]$ perl -v

This is perl, v5.8.1 built for i686-linux

Copyright 1987-2003, Larry Wall

Image::Magick's version.h file contains;

Quote:
#define MagickLibVersion 0x557
#define MagickLibVersionText "5.5.7"
#define MagickLibVersionNumber 5,5,7,2

That any help to anyone?

TIA

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Image::Magick showing blank images on some server, but not others? In reply to
What is the error message?

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Image::Magick showing blank images on some server, but not others? In reply to
The error was;

Quote:
An error occured. It was: Bad file descriptor

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Image::Magick showing blank images on some server, but not others? In reply to
Anyone got any ideas? Unsure

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!