Forum Moderators: coopster

Message Too Old, No Replies

php, gd and text style

         

Lolalola

4:22 pm on Aug 8, 2010 (gmt 0)



Hi,

for example i have this html code:
<p><strong>Text text.</strong></p>
<p><span style="font-size: 14pt;"><span style="background-color: #ff0000;">Text text...</span></span></p>


Possible write this text with this style on the image (with php GD)?

Thanks

enigma1

6:13 pm on Aug 8, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's possible but you need to parse the html and then use the appropriate gd functions to do it. And you will need to create some fonts if the default ones aren't sufficient

Here is a simple example using the gd functions


$im = imagecreate(200, 100);
$bg1 = imagecolorallocate($im, 255, 255, 255);
$bg2 = imagecolorallocate($im, 255, 0, 0);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 200 ,100, $bg1);
imagestring($im, 2, 0, 0, 'Test Text.', $tc);
imagefilledrectangle($im, 0, 20, 200 ,40, $bg2);
imagestring($im, 5, 14, 23, 'Text text...', $tc);

//render
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);