Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Blank images with image::Magick, only one some servers?

Status
Not open for further replies.

youradds

Programmer
Jun 27, 2001
817
GB
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
 
Give me some more info, what are the differences in these servers? Do they all have the same version of perl, and image magick? Are they all using the same setuids and gids?

Nick
 
I wouldn't be able to say any of that, as I'm not a perl guru :(

Cheers

Andy
 
Well, do this.

Check the versions of perl and imagemagick.

Imagemagick has its own subset of command line manipulations, although I can't recall any of the commands. I'm sure using the switch -v will give you the version information.

perl -v

Will give you the PERL version.

My guess is that the libraries are not completely installed with imagemagick, as it has a lot of dependencies.

Talk to your server administrators and have them take a look, imagemagick CAN be tricky to install.
 
Managed to track it down to this line;

>
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]; #&quot;Charter&quot;; 
  
     # 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} . &quot;/AddImages/&quot; . $date . &quot;.gif&quot;;
      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 => &quot;$url/AddImages/$date.gif&quot; );

}

sub error {

  my $error = $_[0];

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

}

1;



Running;

perl -v gives me;

----------------------------------------------------------

[gossamer@roger home]$ perl -v

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

Copyright 1987-2003, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'. If you have access to the
Internet, point your browser at the Perl Home Page.

----------------------------------------------------------

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

----------------------------------------------------------
#define MagickLibVersion 0x557
#define MagickLibVersionText &quot;5.5.7&quot;
#define MagickLibVersionNumber 5,5,7,2
----------------------------------------------------------

That any help to anyone?

TIA

Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top