Gossamer Forum
Home : General : Perl Programming :

Anything wrong?

Quote Reply
Anything wrong?
Hi. Can anyone see anything wrong with this line;

my $date = localtime();

If I use

my $date = "";

...the script runs fine. However, when using the top example, I get errors;

[Sat May 24 03:35:27 2003] [error] [client 172.190.49.169] malformed header from script. Bad header= Tahoma-ISO Tahoma-ISO T: /home/bn123/bn123.net/www/index.cgi
GNU Ghostscript 7.05: Unrecoverable error, exit code 1
GNU Ghostscript 7.05: Unrecoverable error, exit code 1

Anyone got any ideas? If needed, I'll post the whole routine....but I know for a fact th#e routine works fine without the localtime() call Frown

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] Anything wrong? In reply to
my $date = scalar localtime();

should work fine. I suspect it's something to do with how you are using $date later on in the script. Can you post that part?

- wil
Quote Reply
Re: [Andy] Anything wrong? In reply to
Just to clear something up.

my $date = localtime;

...and Wil's suggestion of:

my $date = scalar localtime;

....are both exactly the same. Not parenthesizing $date automatically forces scalar context.

my ($date) = localtime;

...however would produce something different =)
Quote Reply
Re: [Paul] Anything wrong? In reply to
Still not working. That part still gives me 500 IS errors.

[Sat May 24 09:10:42 2003] [error] [client 172.191.22.110] malformed header from script. Bad header= Tahoma-ISO Tahoma-ISO T: /home/bn123/bn123.net/www/index.cgi
GNU Ghostscript 7.05: Unrecoverable error, exit code 1
GNU Ghostscript 7.05: Unrecoverable error, exit code 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] Anything wrong? In reply to
Just looks like a screwy header.
Quote Reply
Re: [Paul] Anything wrong? In reply to
The only place aheader is defined in the script, is here;

Code:
print "Content-type: image/gif\n\n";
binmode STDOUT;
print $image->Write('gif:-');

That is *after* the $date variable...

The whole subroutine is;

Code:
sub test {

$ENV{PATH} .= q{:/home/bn123/ghostscript/bin};

my ($date) = localtime;
use Image::Magick;

my $image = Image::Magick->new();
print $image->Set( size => "100x50");
print $image->ReadImage('xc:white');
print $image->Colorize( fill => 'red' );
print $image->Border( width => 5, height => 5, fill => 'blue' );
print $image->Raise( width => 5, height => 5, raise => 'True' );
print $image->Wave( amplitude => 5, wavelength => 30 );

$image->Annotate(
text => $date,
fill =>"black",
x =>15,
y =>30,
pointsize=>14,
font =>"Tahoma");


print "Content-type: image/gif\n\n";
binmode STDOUT;
print $image->Write('gif:-');


}

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] Anything wrong? In reply to
Hi Andy

The following script works fine for me.

Code:
#!/usr/bin/perl -w

use strict;
use Image::Magick;
use CGI;

my $q = CGI->new();

my $image = Image::Magick->new();
$image->Set( size => "100x50");
$image->ReadImage('xc:white');
$image->Colorize( fill => 'red' );
$image->Border( width => 5, height => 5, fill => 'blue' );
$image->Raise( width => 5, height => 5, raise => 'True' );
$image->Wave( amplitude => 5, wavelength => 30 );

my $date = localtime;

$image->Annotate(
text => $date,
fill =>"black",
x =>15,
y =>30,
pointsize =>14,
font =>"Tahoma"
);

print $q->header('image/png');

print $image->Write('png:-');

OUTPUT:

See attached.

- wil

Last edited by:

Wil: May 24, 2003, 9:44 AM
Quote Reply
Re: [Wil] Anything wrong? In reply to
Eugh...still gives me the same error Unimpressed Something wrong with the server config maybe?

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: [Wil] Anything wrong? In reply to
Turned out to be a problem with Image::Magick's 'Annotate' function. Its all fixed up now Smile

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] Anything wrong? In reply to
What was the problem?

- wil
Quote Reply
Re: [Wil] Anything wrong? In reply to
Because the font 'Tahoma' didn't exist, it was trying to show an error. However, this error just resulted in a 500 IS Error. Changing the font seems to have fixed it (thanks Aki).

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] Anything wrong? In reply to
Heh. That's bad on the module's part surely. Any bug reports on this?

- wil
Quote Reply
Re: [Wil] Anything wrong? In reply to
I don't know. I was just about to report it. We are using the latest version of Image::Magick, and I don't think it would be more than a couple of lines of code (max) to sort that bug out.

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] Anything wrong? In reply to
Its not a bug. You just needed to RTFM =) ...the tahoma font doesn't exist on linux by default.

Last edited by:

Paul: May 26, 2003, 8:25 AM
Quote Reply
Re: [Paul] Anything wrong? In reply to
Yeah, but its still a bug that it doesn't return an error if the font doesn't exist Wink

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] Anything wrong? In reply to
Did you try my suggestion of printing the line?

eg...

print $image->Annotate( ... )
Quote Reply
Re: [Paul] Anything wrong? In reply to
>>>Did you try my suggestion of printing the line? <<<

Nope.

Does anyone know of good *working* examples of a script in Perl that writes an image to a static.gif file? I have the following;

Code:
use Image::Magick;

my $image = Image::Magick->new();
print $image->Set( size => "100x50");
print $image->ReadImage('xc:white');
print $image->Colorize( fill => 'red' );

$image->Annotate(
text => $date,
fill =>"black",
x =>15,
y =>30,
pointsize=>14,
font =>"Charter");


my $path = "/home/bn123/bn123.net/www/test";
my $url = "http://www.bn123.net/test";

$image = Image::Magick->new;
my $cover = $path . "/AddImages/" . $date . ".gif";
my $w = $image->Write($cover);
return $w if $w;
undef $image;

However, this just writes blank files (in the correct place, but they just have no content Unimpressed).

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] Anything wrong? In reply to
Well...that's probably because you have:

$image = Image::Magick->new

...right above the line where you write the image Crazy

Last edited by:

Paul: May 27, 2003, 2:41 AM
Quote Reply
Re: [Paul] Anything wrong? In reply to
OMG...how did I miss that! That will serve me right for just copy/pasting the 'write' code from ImageMagick.org Tongue

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] Anything wrong? In reply to
Yeah, it pays to spend at least 5 seconds reading over your code befeore posting a question Wink
Quote Reply
Re: [Andy] Anything wrong? In reply to
Funny you should mention it. I was working on this just last week for a project. Here's what I knocked up. Not the best of codes, but it works, therefore it will stay for the time being.

What it basically does is check to see if there's a cached version of a file on disk. If there isn't, it will create a new thumbnail.

Code:
sub _th_old_pic {
# --------------------------------------------------------------------------
#

my $self = shift;

my $picture = shift;

my $image_path = $picture;

my $image_path_png = "th_" . $image_path . ".png";

my $resized = $htdocs . "th_" . $image_path . ".png";

if (-e $resized) {

return $image_path_png;
}

else {

my ($image,$x);

$image = Image::Magick->new();

$x = $image->Read(filename =>"$htdocs/$image_path");
$x = $image->Resize(geometry =>'150x75');

$x = $image->Write(filename =>"$htdocs/th_$image_path.png");

return $image_path_png;
}

}

- wil