PDA

View Full Version : Help with GD anyone?



lolwut
19-10-2007, 12:01 PM
Right, I've been trying with GDLib for about 1/2 hour now without any luck...
So maybe one of you can assist me (:
Here's my gdtest.php code:



<?php

header("Content-type: image/png");
$string ="If you can see this then I assume it's working?";
$im = imagecreatefrompng("button1.png");
$orange = imagecolorallocate($im, 220, 210, 60);
$px = (imagesx($im) - 7.5 * strlen($string)) / 2;
imagestring($im, 3, $px, 9, $string, $orange);
imagepng($im);
imagedestroy($im);

?>
It outputs "The image “http://localhost/site/gdtest.php” (http://localhost/site/gdtest.php%E2%80%9D) cannot be displayed, because it contains errors."

"gd" part of my phpinfo page:

http://img80.imageshack.us/img80/874/dfgdfgfgdai3.png

Any help would be greatly appreicated, and I'd rep you obv. (:

Verrou
19-10-2007, 12:06 PM
File Name: index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>GD Text Maker!</title>
</head>

<body>
<form action="gd.php" method="post"><br />
Text: <input type="text" name="text" />
<br />
Colour:
<input type="text" name="rgb" value="0,0,0" />
<br />
Size:
<input type="text" name="size" value="1-10" />
<br />
Font:
<select name="font">
<option value="arial.ttf">Arial</option>
<option value="volter.ttf">Volter</option>
<option value="volter-bold.ttf">Volter-Bold</option>
</select>
<br />
<input type="submit" value="Submit!" name="submit" />
</form>
</body>
</html>File Name: gd.php

<?php

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



$font = $_POST['font'];

$get_colour = $_POST['rgb'];

$string = $_POST['text'];

$colours = explode(",", $get_colour);

$font_size = $_POST['size'];

$im = imagecreatetruecolor(700,45)

or die("Cannot initialize GD image stream.");

$bg = imagecolorallocate($im, 255,255,255);

$colour = imagecolorallocate($im, $colours[0], $colours[1], $colours[2]);

imagefill($im, 0,0, $bg);

imagettftext($im,$font_size, 0, 3, 9, $color, $font, $string);

imagepng($im);

imagedestroy($im);

?>Background Image:
http://andrehamon.evenhosting.com/gd/textImage.png
(Save as textImage.png)

And add whatever font's you want.

Want to hide these adverts? Register an account for free!