Jump to content

Php GD library


suzzane2020

Recommended Posts

Hi friends,

 

    I had a doubt regarding the gd library functions in php. This is what iam trying to do:

 

I need to read contents from a html file and convert that to an image uding the gd functions. I can get the code to work using simple text(without html tags) but not without them.

  How do I convert the contents of the file which has html tags to an image.

This is the code i have been using:

 

<?php
header ("Content-type: image/png");
$handle = ImageCreate (400, 400) or die ("Cannot Create image");
$bg_color = ImageColorAllocate ($handle, 255, 0, 0);
$txt_color = ImageColorAllocate ($handle, 0, 0, 0);
ImageString ($handle, 5, 5, 18, "<b>hello</b>", $txt_color);
ImagePng ($handle);
?>

 

I would really appreciate it if someone could help.

Thank You

Link to comment
Share on other sites

Your code seems to work just fine for me, unless you are actually wanting the HTML to be interpreted within your image? Are you wanting that text to be bold? If so, you'll have to build a full parser and select a bold font face for those areas where you want bold, etc. Check out the options for using TTF with this function: http://us3.php.net/imagettftext[/ur].

Link to comment
Share on other sites

Yes, Thats exactly what i want to do. And as I would  be reading the contents of a file and passing that as the string, there would a lot more tags than the bold. <html><head>....etcIs there a way to do that.

 

Not built in, no. Keep in mind that simply calling bold on a font is actually a different font set. For instance, with Arial, you have the plain arial.ttf file for normal font face, but for bold, you actually have arialbd.ttf. For italic, there is ariali.ttf and for bold-italic, there is arialbi.ttf. You would actually have to parse out the text, choose which font will accurately represent what you are after and continue your line with the new font.

 

Do a Google search, and maybe there are some classes or tools out there that may help you along to getting where you want to be. Sounds like a very major undertaking to me, though. Good luck with it!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.