...

View Full Version : imagettftext() AHH



pimpz0r
02-18-2006, 06:08 PM
I'm having a little bit of trouble with imagettftext() in my dynamic signature.
I get The image “http://pimpz0r.net/images/php/IC_sig.php” cannot be displayed, because it contains errors. when calling it. I have the GL lib installed and everything works fine until I try using imagettftext().

So here's the relevant stuff:

//http://pimpz0r.net/images/php/IC_sig.php
//http://pimpz0r.net/images/php/IC_sig.png
function getFont()
{
srand(make_seed());
switch (rand(1, 7))
{

case 1: return "StreetWriters.ttf"; break;
case 2: return "chick.ttf"; break;
case 3: return "pusssa.ttf"; break;
case 4: return "rabiohead.ttf"; break;
case 5: return "poornut.ttf"; break;
case 6: return "gloo-gun.ttf"; break;
case 7: return "croobie.ttf"; break;
default: return "rabiohead.ttf"; break;
}
}

$im = @imagecreate(300, 50);

$black = imagecolorallocate($im, 0, 0, 0);

imagettftext ($im, 20, 0, 10, 20, $black, getFont(), "Testing...");


Bleh, any ideas on why it's not working?

edit: I don't think I have the FreeType library (http://www.freetype.org/) installed -- so that may be causing this error.

StupidRalph
02-18-2006, 09:22 PM
Do you already have make_seed() defined somewhere else in your script? It is a user-defined function.


function make_seed()
{
list($usec, $sec) = explode(' ', microtime());
return (float) $sec + ((float) $usec * 100000);
}

Try adding this to the top of your code.

StupidRalph
02-18-2006, 09:26 PM
Do you mean something like this?



<?php
// Set the content-type
header("Content-type: image/png");

function make_seed()
{
list($usec, $sec) = explode(' ', microtime());
return (float) $sec + ((float) $usec * 100000);
}

function getFont()
{
srand(make_seed());
switch (rand(1, 3))
{
case 1: return "marriage_script.ttf"; break;
case 2: return "bnkgothm.TTF"; break;
case 3: return "COMPCTAN.TTF"; break;
}
}
// Create the image
$im = imagecreate(300, 50);

// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);

// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = 'arial.ttf';

// Add the text
imagettftext($im, 20, 0, 10, 20, $black, getFont(), $text);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>

pimpz0r
02-18-2006, 09:52 PM
yeah -- it's defined. Sorry for any confusion. Here's the full script:

<?php
function make_seed()
{
list($usec, $sec) = explode(' ', microtime());
return (float) $sec + ((float) $usec * 100000);
}
function getQuote()
{
$quotes = array(
"lolz",
"Rub my body",
"Give me sex",
"Do drugs",
"Don't make me shank you",
"He's simple, he's dumb, he's the pilot",
"Paramedic?",
"I hope you can",
"Are you ready?",
"Yup",
"2:50",
"How's it going?",
"Yo, 2000 man",
"Welcome back to solid ground",
"Sputnik Baby?",
"Rocket heart",
"CNN!",
"FOX!",
"Nice nade, buddy",
"Awping noob",
"Hai 2 U",
"LOL",
"ROFL",
"OMG",
"OMFG",
"Jerk",
"Cool",
"10 years",
"Robin Hood",
"Shaq",
"Drugs",
"Flight-93",
"K",
"KKK",
"Mother",
"Father",
"Get these gats smoking",
"Wait for my go",
"A.M. 180",
"Lincoln == JERK",
"Break it down",
"You're out of line",
"***",
"CD-ROM",
"Sixty-Nine",
"Stay in school",
"Pimpz0r rokkZ",
"I live for r00t",
"Eat the weak",
"Go, Champ!",
"WTF",
"ACID",
"LSD",
"Magic Mushrooms",
"Fig Newtons",
"I love you",
"Yo",
"Get bent",
"****",
"Sex me",
"Stronger, Taller and Badder",
"Transportation",
"The warming sun",
"Lets go get high",
"Yeah, really high",
"I havn't been that bad",
"I havn't been that good",
"I want it really good",
"It hurts so good",
"No need to hide",
"I'm going inside",
"Haxx0r",
"Pimpz0r.net",
"Google it!",
"Trippy",
"Slippery",
"Run!",
"*** blood",
"Dill",
"Neck meats",
"Rub my flab",
"Stone abs, I have",
"Nigg",
"How's the mellon, bud?",
"Rape me",
date('H:i:s'),
date('Y'),

);

if(isset($_GET['q'])){return $quotes[$_GET['q']];}

srand(make_seed());
return $quotes[rand(0, count($quotes)-1)];
}
function getColorCode()
{
$colorCodes = "000000|000033|000066|000099|0000CC|0000FF|
003300|003333|003366|003399|0033CC|0033FF|
006600|006633|006666|006699|0066CC|0066FF|
009900|009933|009966|009999|0099CC|0099FF|
00CC00|00CC33|00CC66|00CC99|00CCCC|00CCFF|
00FF00|00FF33|00FF66|00FF99|00FFCC|00FFFF|
330000|330033|330066|330099|3300CC|3300FF|
333300|333333|333366|333399|3333CC|3333FF|
336600|336633|336666|336699|3366CC|3366FF|
339900|339933|339966|339999|3399CC|3399FF|
33CC00|33CC33|33CC66|33CC99|33CCCC|33CCFF|
33FF00|33FF33|33FF66|33FF99|33FFCC|33FFFF|
660000|660033|660066|660099|6600CC|6600FF|
663300|663333|663366|663399|6633CC|6633FF|
666600|666633|666666|666699|6666CC|6666FF|
669900|669933|669966|669999|6699CC|6699FF|
66CC00|66CC33|66CC66|66CC99|66CCCC|66CCFF|
66FF00|66FF33|66FF66|66FF99|66FFCC|66FFFF|
990000|990033|990066|990099|9900CC|9900FF|
993300|993333|993366|993399|9933CC|9933FF|
996600|996633|996666|996699|9966CC|9966FF|
999900|999933|999966|999999|9999CC|9999FF|
99CC00|99CC33|99CC66|99CC99|99CCCC|99CCFF|
99FF00|99FF33|99FF66|99FF99|99FFCC|99FFFF|
CC0000|CC0033|CC0066|CC0099|CC00CC|CC00FF|
CC3300|CC3333|CC3366|CC3399|CC33CC|CC33FF|
CC6600|CC6633|CC6666|CC6699|CC66CC|CC66FF|
CC9900|CC9933|CC9966|CC9999|CC99CC|CC99FF|
CCCC00|CCCC33|CCCC66|CCCC99|CCCCCC|CCCCFF|
CCFF00|CCFF33|CCFF66|CCFF99|CCFFCC|CCFFFF|
FF0000|FF0033|FF0066|FF0099|FF00CC|FF00FF|
FF3300|FF3333|FF3366|FF3399|FF33CC|FF33FF|
FF6600|FF6633|FF6666|FF6699|FF66CC|FF66FF|
FF9900|FF9933|FF9966|FF9999|FF99CC|FF99FF|
FFCC00|FFCC33|FFCC66|FFCC99|FFCCCC|FFCCFF|
FFFF00|FFFF33|FFFF66|FFFF99|FFFFCC";
$color = explode("|", trim($colorCodes));
srand(make_seed());
}
function GetColorVal()
{
srand(make_seed());
return rand(0, 255);
}
function getFont()
{
srand(make_seed());
switch (rand(1, 7))
{

case 1: return "StreetWriters.ttf"; break;
case 2: return "chick.ttf"; break;
case 3: return "pusssa.ttf"; break;
case 4: return "rabiohead.ttf"; break;
case 5: return "poornut.ttf"; break;
case 6: return "gloo-gun.ttf"; break;
case 7: return "croobie.ttf"; break;
default: return "rabiohead.ttf"; break;
}
}
function getAngle()
{
srand(make_seed());
return rand(0, 180);
}
//HEADERS:
Header ("Expires: Mon, 22 Dec 1969 05:00:00 GMT");

// always modified
Header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");

// HTTP/1.1
Header ("Cache-Control: no-store, no-cache, must-revalidate");
Header ("Cache-Control: post-check=0, pre-check=0", false);

// HTTP/1.0
Header ("Pragma: no-cache");

Header ("Content-type: image/png");

//forge image
$im = @imagecreate(300, 50) or die();

//setup some colors
$background_color = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
//nice border effecet
imagefilledrectangle($im,2,2, 297, 47, $white);

//imagettftext ($im, 20, 0, 10, 20, $black, getFont(), "Testing...");

//Text:
$textColor = imagecolorallocate($im, GetColorVal(), GetColorVal(), GetColorVal());
imagestring($im, rand(2, 5), rand(0, 300), rand(0, 50), getQuote(), $textColor);

$textColor = imagecolorallocate($im, GetColorVal(), GetColorVal(), GetColorVal());
imagestring($im, rand(2, 5), rand(0, 300), rand(0, 50), getQuote(), $textColor);

$textColor = imagecolorallocate($im, GetColorVal(), GetColorVal(), GetColorVal());
imagestring($im, rand(2, 5), rand(0, 300), rand(0, 50), getQuote(), $textColor);

$textColor = imagecolorallocate($im, GetColorVal(), GetColorVal(), GetColorVal());
imagestring($im, rand(2, 5), rand(0, 300), rand(0, 50), getQuote(), $textColor);

$textColor = imagecolorallocate($im, GetColorVal(), GetColorVal(), GetColorVal());
imagestring($im, rand(2, 5), rand(0, 300), rand(0, 50), getQuote(), $textColor);

$textColor = imagecolorallocate($im, GetColorVal(), GetColorVal(), GetColorVal());
imagestring($im, rand(2, 5), rand(0, 300), rand(0, 50), getQuote(), $textColor);

$textColor = imagecolorallocate($im, GetColorVal(), GetColorVal(), GetColorVal());
imagestring($im, rand(2, 5), rand(0, 300), rand(0, 50), getQuote(), $textColor);

//imagefilledrectangle($im, 0, 2, 47, 47, $black); //left side
//imagefilledrectangle($im, 297, 300, 47, 47, $black); //right side
//imagefilledrectangle($im,2,2, 47, 47, $black); //top
//imagefilledrectangle($im,2,2, 47, 47, $black); //bottom

//finish it up
imagepng($im);
imagedestroy($im);
?>

getColorCode() does nothing right now -- but it took me a while to make so I figured why not leave it in :)

StupidRalph
02-19-2006, 06:33 AM
This is what worked for me. Just tweak the parameters around in imagegettftext() as to how you want them.
Don't ask me what I did, cuz I left and came back. Anyway, which version of GD library do you have 1 or 2? I have 2 so when I give a value for the font size it is represented as 'point' if you have version 1 it is represented in terms of 'pixels'.


<?php
function make_seed()
{
list($usec, $sec) = explode(' ', microtime());
return (float) $sec + ((float) $usec * 100000);
}
function getQuote()
{
$quotes = array(
"lolz",
"Rub my body",
"Give me sex",
"Do drugs",
"Don't make me shank you",
"He's simple, he's dumb, he's the pilot",
"Paramedic?",
"I hope you can",
"Are you ready?",
"Yup",
"2:50",
"How's it going?",
"Yo, 2000 man",
"Welcome back to solid ground",
"Sputnik Baby?",
"Rocket heart",
"CNN!",
"FOX!",
"Nice nade, buddy",
"Awping noob",
"Hai 2 U",
"LOL",
"ROFL",
"OMG",
"OMFG",
"Jerk",
"Cool",
"10 years",
"Robin Hood",
"Shaq",
"Drugs",
"Flight-93",
"K",
"KKK",
"Mother",
"Father",
"Get these gats smoking",
"Wait for my go",
"A.M. 180",
"Lincoln == JERK",
"Break it down",
"You're out of line",
"***",
"CD-ROM",
"Sixty-Nine",
"Stay in school",
"Pimpz0r rokkZ",
"I live for r00t",
"Eat the weak",
"Go, Champ!",
"WTF",
"ACID",
"LSD",
"Magic Mushrooms",
"Fig Newtons",
"I love you",
"Yo",
"Get bent",
"****",
"Sex me",
"Stronger, Taller and Badder",
"Transportation",
"The warming sun",
"Lets go get high",
"Yeah, really high",
"I havn't been that bad",
"I havn't been that good",
"I want it really good",
"It hurts so good",
"No need to hide",
"I'm going inside",
"Haxx0r",
"Pimpz0r.net",
"Google it!",
"Trippy",
"Slippery",
"Run!",
"*** blood",
"Dill",
"Neck meats",
"Rub my flab",
"Stone abs, I have",
"Nigg",
"How's the mellon, bud?",
"Rape me",
date('H:i:s'),
date('Y'),

);

if(isset($_GET['q'])){return $quotes[$_GET['q']];}

srand(make_seed());
return $quotes[rand(0, count($quotes)-1)];
}
function getColorCode()
{
$colorCodes = "000000|000033|000066|000099|0000CC|0000FF|
003300|003333|003366|003399|0033CC|0033FF|
006600|006633|006666|006699|0066CC|0066FF|
009900|009933|009966|009999|0099CC|0099FF|
00CC00|00CC33|00CC66|00CC99|00CCCC|00CCFF|
00FF00|00FF33|00FF66|00FF99|00FFCC|00FFFF|
330000|330033|330066|330099|3300CC|3300FF|
333300|333333|333366|333399|3333CC|3333FF|
336600|336633|336666|336699|3366CC|3366FF|
339900|339933|339966|339999|3399CC|3399FF|
33CC00|33CC33|33CC66|33CC99|33CCCC|33CCFF|
33FF00|33FF33|33FF66|33FF99|33FFCC|33FFFF|
660000|660033|660066|660099|6600CC|6600FF|
663300|663333|663366|663399|6633CC|6633FF|
666600|666633|666666|666699|6666CC|6666FF|
669900|669933|669966|669999|6699CC|6699FF|
66CC00|66CC33|66CC66|66CC99|66CCCC|66CCFF|
66FF00|66FF33|66FF66|66FF99|66FFCC|66FFFF|
990000|990033|990066|990099|9900CC|9900FF|
993300|993333|993366|993399|9933CC|9933FF|
996600|996633|996666|996699|9966CC|9966FF|
999900|999933|999966|999999|9999CC|9999FF|
99CC00|99CC33|99CC66|99CC99|99CCCC|99CCFF|
99FF00|99FF33|99FF66|99FF99|99FFCC|99FFFF|
CC0000|CC0033|CC0066|CC0099|CC00CC|CC00FF|
CC3300|CC3333|CC3366|CC3399|CC33CC|CC33FF|
CC6600|CC6633|CC6666|CC6699|CC66CC|CC66FF|
CC9900|CC9933|CC9966|CC9999|CC99CC|CC99FF|
CCCC00|CCCC33|CCCC66|CCCC99|CCCCCC|CCCCFF|
CCFF00|CCFF33|CCFF66|CCFF99|CCFFCC|CCFFFF|
FF0000|FF0033|FF0066|FF0099|FF00CC|FF00FF|
FF3300|FF3333|FF3366|FF3399|FF33CC|FF33FF|
FF6600|FF6633|FF6666|FF6699|FF66CC|FF66FF|
FF9900|FF9933|FF9966|FF9999|FF99CC|FF99FF|
FFCC00|FFCC33|FFCC66|FFCC99|FFCCCC|FFCCFF|
FFFF00|FFFF33|FFFF66|FFFF99|FFFFCC";
$color = explode("|", trim($colorCodes));
srand(make_seed());
}
function GetColorVal()
{
srand(make_seed());
return rand(0, 255);
}
function getFont()
{
srand(make_seed());
switch (rand(1, 4))
{
case 1: return "StreetWriters.ttf"; break;
case 2: return "chick.ttf"; break;
case 3: return "pusssa.ttf"; break;
case 4: return "rabiohead.ttf"; break;
case 5: return "poornut.ttf"; break;
case 6: return "gloo-gun.ttf"; break;
case 7: return "croobie.ttf"; break;
default: return "rabiohead.ttf"; break;
}
}
function getAngle()
{
srand(make_seed());
return rand(0, 180);
}
//HEADERS:
Header ("Expires: Mon, 22 Dec 1969 05:00:00 GMT");

// always modified
Header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");

// HTTP/1.1
Header ("Cache-Control: no-store, no-cache, must-revalidate");
Header ("Cache-Control: post-check=0, pre-check=0", false);

// HTTP/1.0
Header ("Pragma: no-cache");

Header ("Content-type: image/png");

//forge image
$im = @imagecreate(300, 50) or die();

//setup some colors
$background_color = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
//nice border effecet
imagefilledrectangle($im,2,2, 297, 47, $white);
for ($i=0;$i<7;$i++) {
$textColor = imagecolorallocate($im, GetColorVal(), GetColorVal(), GetColorVal());
imagettftext($im, rand(8,20), getAngle(), rand(20,284), rand(8,50), $textColor, getFont(), getQuote());
}

//finish it up
imagepng($im);
imagedestroy($im);
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum