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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

errors for image generator

Status
Not open for further replies.

thematking

Programmer
Jul 28, 2010
6
0
0
US
I am getting these errors when someoen tries to insert their personalized text onto an image... here is the code

#!/usr/bin/perl

# church.pl
# Copyright (C) 2008, Ryland Sanders
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

use Image::Magick;
use CGI qw:)standard);
use utf8;

if (param()) {
$text1 = param('text1');
$text2 = param('text2');
$text3 = param('text3');
$text4 = param('text4');

$htext1 = param('htext1');
$htext2 = param('htext2');

$emblem = param('emblem');

$hcolor = param('hcolor');
$fcolor = param('fcolor');
$bcolor = param('bcolor');
$ecolor = param('ecolor');

$download = param('download');
}

utf8::decode($text1);
utf8::decode($text2);
utf8::decode($text3);
utf8::decode($text4);

utf8::decode($htext1);
utf8::decode($htext2);

# filter out invalid hex colors
$hcolor =~ s/[^a-f0-9]//gi;
$fcolor =~ s/[^a-f0-9]//gi;
$bcolor =~ s/[^a-f0-9]//gi;
$ecolor =~ s/[^a-f0-9]//gi;

# if any colors are missing or invalid, replace them with a default.
if (!$hcolor || length($hcolor) != 6) { $hcolor = '781231'; }
if (!$fcolor || length($fcolor) != 6) { $fcolor = 'E4D0D6'; }
if (!$bcolor || length($bcolor) != 6) { $bcolor = 'A0C0BD'; }
if (!$ecolor || length($ecolor) != 6) { $ecolor = '4D862D'; }

if (!$text1 && !$text2 && !$text3 && !$text4) {
$text1 = "";
$text2 = "BLANK SIGNS";
$text3 = "ARE NO FUN";
$text4 = "";
}

if (!$htext1 && !$htext2 && !$htext3 && !$htext4) {
$htext1 = "Church Name";
$htext2 = "GOES HERE";
}

# load the sign photo as our base image. we'll be compositing layers
# on top of this base image to get our final image.
$base = Image::Magick->new;
$base->Set(size=>"400x300");
$base->Read("images/church-base.jpg");

# create an image for use as a 'paint' color and fill it with the
# sign header background color
$tint = Image::Magick->new;
$tint->Set(size=>"400x300",matte=>'True');
$tint->Read("xc:#$hcolor");

# load the sign header background mask. we'll use this sort of like
# a stencil to control which pixels in the tint image get composited
# onto the base image.
$mask = Image::Magick->new;
$mask->Set(size=>"400x300");
$mask->Read("images/church-header-bg-mask.gif");

# composite the tint image onto the base, using the mask image to mask it.
$base->Composite(image=>$tint,compose=>"Over",mask=>$mask,x=>0,y=>0,gravity=>"NorthWest");

# remove the mask from the base image.
$base->Set(mask=>"");

undef $mask;
undef $tint;

# create an image to hold the church name and the sign text. this
# image is 3x larger than it needs to be, because ImageMagick text
# rendering sometimes causes odd spacing errors. making the image larger
# helps hide those errors.
$content = Image::Magick->new;
$content->Set(size=>"900x750");
$content->Read("xc:none");

$hfont = "fonts/Bradley_Gratis.ttf";

# first we find out how large the sign header text is going to be
($x_ppem, $y_ppem, $ascender, $descender, $width1, $height1, $max_advance) = $base->QueryFontMetrics(text=>$htext1,font=>$hfont,pointsize=>96,fill=>'white',strokewidth=>4,stroke=>'white');
($x_ppem, $y_ppem, $ascender, $descender, $width2, $height2, $max_advance) = $base->QueryFontMetrics(text=>$htext2,font=>$hfont,pointsize=>48,fill=>'white',strokewidth=>4,stroke=>'white');

if ($width1 > $width2) { $w = $width1; } else { $w = $width2; }
$w += 40;
$h = ($height1 + $height2) * 2;

# now we create another image large enough to contain the text using
# the values we got above
$letters = Image::Magick->new;
$letters->Set(size=>$w."x".$h);
$letters->Read("xc:none");

# write the text onto that image
if ($htext1) {
$letters->Annotate(text=>$htext1,font=>$hfont,pointsize=>96,fill=>"#$fcolor",x=>int($w/2),y=>int($h/2),align=>"Center");
}

if ($htext2) {
$letters->Annotate(text=>$htext2,font=>$hfont,pointsize=>48,fill=>"#$fcolor",x=>int($w/2),y=>int($h/2)+54,align=>"Center");
}

# trim excess pixels and then resize it to fit into the content image
$letters->Trim();
($w,$h) = $letters->Get('columns','rows');
if ($w > 355 || $h > 132) {
if ($w > 355) { $w = 355; }
if ($h > 132) { $h = 132; }
$letters->Resize(width=>$w, height=>$h, filter=>"Lanczos");
}

# composite the church name onto the content image
$content->Composite(image=>$letters,compose=>"Over",x=>384-int($w/2),y=>200-int($h/2),gravity=>"NorthWest");

undef $letters;

# draw a circular background for the emblem image
$content->Draw(primitive=>"circle",fill=>"#$bcolor",points=>"622,200 622,145");

# create an image for the emblem
$emblemimg = Image::Magick->new;
$emblemimg->Set("100x100");
$emblemimg->Read("xc:none");

# load the emblem GIF and use it as a mask for the tint image
$mask = Image::Magick->new;
$mask->Set(size=>"100x100");
$mask->Read("images/church.gif");

$tint = Image::Magick->new;
$tint->Set(size=>"100x100",matte=>'True');
$tint->Read("xc:#$ecolor");

# composite the tint image onto the emblem image
$emblemimg->Composite(image=>$tint,compose=>"Over",mask=>$mask,x=>0,y=>0,gravity=>"NorthWest");

# composite the emblem image onto the content image
$content->Composite(image=>$emblemimg,compose=>"Over",x=>572,y=>150,gravity=>"NorthWest");

undef $mask;
undef $emblemimg;
undef $tint;

# define the center point and the top edge of the sign text area
$x_center = 445;
$y_offset = 362;

$line_height = 58;

# load the lines of text into an array
@text = ('',uc($text1),uc($text2),uc($text3),uc($text4));

$fontname = "fonts/Signage_Geometric.ttf";
# font width and kerning values are contained in this file in wx and kpx arrays
require "fonts/Signage_Geometric.pl";
$max_line_width = 8650;
$fontcolor = "222222";

# loop through lines array and process each line
for ($l = 1; $l < 5; $l++) {
$x_offset = 0;
$truncate_to = 0;

# loop through each letter in each line and get its width
# and kerning value (if any). if a line is too long to fit
# on the sign, it gets truncated.
for ($i = 0; $i < length($text[$l]); $i++) {
$char = substr($text[$l], $i, 1);
if ($x_offset + ($wx[ord($char)]) <= $max_line_width) {
$x_offset += $wx[ord($char)];
$truncate_to++;
}
}
$text[$l] = substr($text[$l],0,$truncate_to);

# draw the line onto the content image
$content->Annotate(text=>$text[$l],font=>$fontname,antialias=>'True',pointsize=>52,fill=>"#$fontcolor",align=>'Center',x=>$x_center,y=>$y_offset,gravity=>'NorthWest');

# adjust the top edge down for the next line
$y_offset += $line_height;
}

# resize the content image to smooth it down and hide errors
$content->Resize(width=>400,height=>300,filter=>"Lanczos");

# apply a perspective distortion to the content image
$content->Distort('virtual-pixel'=>"transparent", method=>"Perspective", points=>[88,50,85,52, 88,215,88,216, 305,50,304,49, 305,215,307,214]);

# composite the content image onto the base image
$base->Composite(image=>$content,composite=>"Over",x=>0,y=>0,gravity=>"NorthWest");

undef $content;

# load the overlay image. this overlay image contains a
# reflection of a tree-lined street. it's semi-transparent
# so that the letters and the sign show through.
$overlay = Image::Magick->new;
$overlay->Set(size=>"400x300");
$overlay->Read("images/church-overlay.png");

# composite the overlay onto the base image.
$base->Composite(image=>$overlay,compose=>'Over',x=>0,y=>0,gravity=>'NorthWest');

undef $overlay;

# that's it, now we can send it to the browser. we have to send
# a couple of HTTP headers to let the browser know an image is
# coming.

# the first is a Content-Disposition header to tell the
# browser whether to just display the image (inline), or to
# trigger a "Save as..." dialog box (attachment).
if ($download) {
$disposition = "attachment";
} else {
$disposition = "inline";
}
print "Content-Disposition: $disposition; filename=churchsign.jpg\n";

# the second header is a Content-Type header, which tells the browser
# to expect a JPEG image.
print "Content-Type: image/jpeg;\n\n";

# now we write the image data to standard output, and we're done.
binmode STDOUT;
$base->Set(compression=>'JPEG',quality=>'85');
$base->Write('jpg:-');

undef $base;


and here are the errors


[Mon Jul 26 11:40:19 2010] [error] [client 69.36.160.253] GetList: UnrecognizedType 0, referer: [Mon Jul 26 11:40:19 2010] [error] [client 69.36.160.253] sh: gs: command not found, referer: [Mon Jul 26 11:40:19 2010] [error] [client 69.36.160.253] sh: gs: command not found, referer: [Mon Jul 26 11:40:19 2010] [error] [client 69.36.160.253] sh: gs: command not found, referer: [Mon Jul 26 11:40:19 2010] [error] [client 69.36.160.253] sh: gs: command not found, referer: [Mon Jul 26 11:40:19 2010] [error] [client 69.36.160.253] sh: gs: command not found, referer: [Mon Jul 26 11:40:19 2010] [error] [client 69.36.160.253] sh: gs: command not found, referer: [Mon Jul 26 11:40:19 2010] [error] [client 69.36.160.253] sh: gs: command not found, referer: [Mon Jul 26 11:40:19 2010] [error] [client 69.36.160.253] sh: gs: command not found, referer: [Mon Jul 26 11:40:19 2010] [error] [client 69.36.160.253] sh: gs: command not found, referer: [Mon Jul 26 11:40:19 2010] [error] [client 69.36.160.253] sh: gs: command not found, referer: [Mon Jul 26 11:40:19 2010] [error] [client 69.36.160.253] sh: gs: command not found, referer: [Mon Jul 26 11:40:19 2010] [error] [client 69.36.160.253] sh: gs: command not found, referer: [Mon Jul 26 11:40:19 2010] [error] [client 69.36.160.253] Can't locate fonts/Signage_Geometric.pl in @INC (@INC contains: /usr/local/perl-5.8.8/lib/5.8.8/i686-linux /usr/local/perl-5.8.8/lib/5.8.8 /usr/local/perl-5.8.8/lib/site_perl/5.8.8/i686-linux /usr/local/perl-5.8.8/lib/site_perl/5.8.8 /usr/local/perl-5.8.8/lib/site_perl .) at /var/ line 188., referer: [Mon Jul 26 11:40:19 2010] [error] [client 69.36.160.253] Premature end of script headers: church.pl, referer:
any help would be appreciated
 
Thanks for the input. The weird thing is that that perl script exists. Maybe it is in the wrong folder? Here is how i set it up. All of the files are under a folder /vinyl-link/... existing within that folder are two more folders - images and fonts, and the root documents - church.php and church.pl.
 
I believe it resizes the letters to fit the image...heres the code if its any help

# Signage_Geometric.pl
# Copyright (C) 2008, Ryland Sanders
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

$ttftop = 834;
$ttfbottom = -148;
$wx[32] = 250; # space
$wx[33] = 270; # exclam
$wx[34] = 387; # quotedbl
$wx[35] = 513; # numbersign
$wx[36] = 403; # dollar
$wx[38] = 520; # ampersand
$wx[39] = 248; # quotesingle
$wx[40] = 362; # parenleft
$wx[41] = 362; # parenright
$wx[42] = 500; # asterisk
$wx[43] = 511; # plus
$wx[44] = 248; # comma
$wx[45] = 372; # hyphen
$wx[46] = 248; # period
$wx[47] = 618; # slash
$wx[48] = 539; # zero
$wx[49] = 321; # one
$wx[50] = 538; # two
$wx[51] = 540; # three
$wx[52] = 552; # four
$wx[53] = 539; # five
$wx[54] = 539; # six
$wx[55] = 443; # seven
$wx[56] = 537; # eight
$wx[57] = 538; # nine
$wx[58] = 248; # colon
$wx[59] = 248; # semicolon
$wx[60] = 432; # less
$wx[61] = 432; # equal
$wx[62] = 432; # greater
$wx[63] = 480; # question
$wx[64] = 579; # at
$wx[65] = 504; # A
$wx[66] = 538; # B
$wx[67] = 538; # C
$wx[68] = 538; # D
$wx[69] = 420; # E
$wx[70] = 410; # F
$wx[71] = 538; # G
$wx[72] = 529; # H
$wx[73] = 287; # I
$wx[74] = 538; # J
$wx[75] = 548; # K
$wx[76] = 410; # L
$wx[77] = 670; # M
$wx[78] = 538; # N
$wx[79] = 540; # O
$wx[80] = 529; # P
$wx[81] = 540; # Q
$wx[82] = 539; # R
$wx[83] = 538; # S
$wx[84] = 420; # T
$wx[85] = 538; # U
$wx[86] = 525; # V
$wx[87] = 646; # W
$wx[88] = 531; # X
$wx[89] = 542; # Y
$wx[90] = 538; # Z
$wx[91] = 362; # bracketleft
$wx[92] = 618; # backslash
$wx[93] = 362; # bracketright
$wx[94] = 476; # asciicircum
$wx[95] = 500; # underscore
$wx[96] = 265; # grave
$wx[97] = 504; # a
$wx[98] = 538; # b
$wx[99] = 538; # c
$wx[100] = 538; # d
$wx[101] = 420; # e
$wx[102] = 410; # f
$wx[103] = 538; # g
$wx[104] = 529; # h
$wx[105] = 287; # i
$wx[106] = 538; # j
$wx[107] = 548; # k
$wx[108] = 410; # l
$wx[109] = 670; # m
$wx[110] = 538; # n
$wx[111] = 540; # o
$wx[112] = 529; # p
$wx[113] = 540; # q
$wx[114] = 539; # r
$wx[115] = 538; # s
$wx[116] = 420; # t
$wx[117] = 538; # u
$wx[118] = 525; # v
$wx[119] = 646; # w
$wx[120] = 531; # x
$wx[121] = 542; # y
$wx[122] = 538; # z
$wx[123] = 424; # braceleft
$wx[124] = 266; # bar
$wx[125] = 424; # braceright
$wx[126] = 479; # asciitilde
$wx[8364] = 434; # Euro
$wx[8218] = 248; # quotesinglbase
$wx[402] = 386; # florin
$wx[8222] = 381; # quotedblbase
$wx[8230] = 521; # ellipsis
$wx[8224] = 430; # dagger
$wx[8225] = 432; # daggerdbl
$wx[710] = 343; # circumflex
$wx[8240] = 901; # perthousand
$wx[352] = 538; # Scaron
$wx[8249] = 372; # guilsinglleft
$wx[381] = 538; # Zcaron
$wx[8216] = 248; # quoteleft
$wx[8217] = 248; # quoteright
$wx[8220] = 383; # quotedblleft
$wx[8221] = 383; # quotedblright
$wx[8226] = 493; # bullet
$wx[8211] = 372; # endash
$wx[8212] = 552; # emdash
$wx[732] = 360; # tilde
$wx[8482] = 410; # trademark
$wx[353] = 538; # scaron
$wx[8250] = 372; # guilsinglright
$wx[382] = 538; # zcaron
$wx[376] = 542; # Ydieresis
$wx[161] = 270; # exclamdown
$wx[162] = 403; # cent
$wx[163] = 441; # sterling
$wx[164] = 548; # currency
$wx[165] = 426; # yen
$wx[166] = 266; # brokenbar
$wx[168] = 317; # dieresis
$wx[169] = 512; # copyright
$wx[170] = 265; # ordfeminine
$wx[171] = 576; # guillemotleft
$wx[172] = 530; # logicalnot
$wx[174] = 514; # registered
$wx[176] = 301; # degree
$wx[177] = 512; # plusminus
$wx[178] = 268; # twosuperior
$wx[179] = 272; # threesuperior
$wx[180] = 255; # acute
$wx[182] = 573; # paragraph
$wx[183] = 493; # periodcentered
$wx[184] = 269; # cedilla
$wx[185] = 204; # onesuperior
$wx[186] = 269; # ordmasculine
$wx[187] = 576; # guillemotright
$wx[188] = 505; # onequarter
$wx[189] = 527; # onehalf
$wx[190] = 554; # threequarters
$wx[191] = 480; # questiondown
$wx[192] = 504; # Agrave
$wx[193] = 504; # Aacute
$wx[194] = 504; # Acircumflex
$wx[195] = 504; # Atilde
$wx[196] = 504; # Adieresis
$wx[197] = 504; # Aring
$wx[199] = 538; # Ccedilla
$wx[200] = 420; # Egrave
$wx[201] = 420; # Eacute
$wx[202] = 420; # Ecircumflex
$wx[203] = 420; # Edieresis
$wx[204] = 287; # Igrave
$wx[205] = 287; # Iacute
$wx[206] = 287; # Icircumflex
$wx[207] = 287; # Idieresis
$wx[208] = 582; # Eth
$wx[209] = 538; # Ntilde
$wx[210] = 540; # Ograve
$wx[211] = 540; # Oacute
$wx[212] = 540; # Ocircumflex
$wx[213] = 540; # Otilde
$wx[214] = 540; # Odieresis
$wx[215] = 530; # multiply
$wx[216] = 540; # Oslash
$wx[217] = 538; # Ugrave
$wx[218] = 538; # Uacute
$wx[219] = 538; # Ucircumflex
$wx[220] = 538; # Udieresis
$wx[221] = 542; # Yacute
$wx[222] = 529; # Thorn
$wx[223] = 540; # germandbls
$wx[224] = 504; # agrave
$wx[225] = 504; # aacute
$wx[226] = 504; # acircumflex
$wx[227] = 504; # atilde
$wx[228] = 504; # adieresis
$wx[229] = 504; # aring
$wx[231] = 538; # ccedilla
$wx[232] = 420; # egrave
$wx[233] = 420; # eacute
$wx[234] = 420; # ecircumflex
$wx[235] = 420; # edieresis
$wx[236] = 287; # igrave
$wx[237] = 287; # iacute
$wx[238] = 287; # icircumflex
$wx[239] = 287; # idieresis
$wx[240] = 582; # eth
$wx[241] = 538; # ntilde
$wx[242] = 540; # ograve
$wx[243] = 540; # oacute
$wx[244] = 540; # ocircumflex
$wx[245] = 540; # otilde
$wx[246] = 540; # odieresis
$wx[247] = 512; # divide
$wx[248] = 540; # oslash
$wx[249] = 538; # ugrave
$wx[250] = 538; # uacute
$wx[251] = 538; # ucircumflex
$wx[252] = 538; # udieresis
$wx[253] = 542; # yacute
$wx[254] = 529; # thorn
$wx[255] = 542; # ydieresis
 
Try changing the require line to:-
Code:
require "fonts/Signage_Geometric.pl"[red] || print "Cannot Load" [/red];
I am still not convinced the file is being called

Keith
 
I did that, and nothing has changed. Do i input it exactly as how you wrote it? Does this mean that it's not being found?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top