Jump to content

[SOLVED] Trouble Writing Text to an Image


Patriot

Recommended Posts

Thanks for helping.  I'm having trouble with the following:

 

<!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>
<?php
$image = imagecreatefrompng("images/esuom.png");
if(!$image)
die("Error loading image.");
$text_color = imagecolorallocate($image, 13, 37, 62); 
$x = 100;
$y = 30;
$fontsize = 12;
$fontfile = "fonts/VAG Rounded BT.ttf";
$text = "Hello World!";

imagettftext($image, $fontsize, 0, $x, $y, $text_color, $fontfile, $text);

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

imagepng($image);
imagedestroy($image);
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
</body>
</html>

 

I have it uploaded here: http://imobworld.com/dynamicsigs/

Does anyone know what's wrong?

 

Thanks,

Gil

Link to comment
https://forums.phpfreaks.com/topic/161843-solved-trouble-writing-text-to-an-image/
Share on other sites

first ofall, when you start sending text, you send the headers, so right off the bat, your script isn't going to work with all that html surrounding your php code

 

so first step up is a big one.. get rid of the html..

 

<?php
$image = imagecreatefrompng("images/esuom.png");
if(!$image)
die("Error loading image.");
$text_color = imagecolorallocate($image, 13, 37, 62); 
$x = 100;
$y = 30;
$fontsize = 12;
$fontfile = "fonts/VAG Rounded BT.ttf";
$text = "Hello World!";

imagettftext($image, $fontsize, 0, $x, $y, $text_color, $fontfile, $text);

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

imagepng($image);
imagedestroy($image);
?>

 

oh.. and nice font name :P VAG Rounded :P

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.