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
https://forums.phpfreaks.com/topic/93683-php-gd-library/
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
https://forums.phpfreaks.com/topic/93683-php-gd-library/#findComment-479993
Share on other sites

There's no easy way. You would have to build a script to interpret all of the HTML, which would then decide how to format the text on the image.

 

If you using windows with php 5.2.2 or greater, then this might be a possible solution. Basically, it allows you to take a screenshot of a window.

Link to comment
https://forums.phpfreaks.com/topic/93683-php-gd-library/#findComment-480023
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
https://forums.phpfreaks.com/topic/93683-php-gd-library/#findComment-480025
Share on other sites

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.