SAFAD
SAFAD

Reputation: 784

create image from html

i want to create an image from html, i couldn't use painty since it is outdated and no longer working and i want something similar. i have already tried to create image using GD library like this

<?php
$html_code = "<b> this is the body </b> "; 
// Create the image 
 $img = imagecreate("300", "600"); 
 imagecolorallocate($img,0,0,0); 
 $c = imagecolorallocate($img,70,70,70); 
 imageline($img,0,0,300,600,$c2); 
 imageline($img,300,0,0,600,$c2); 

$white = imagecolorallocate($img, 255, 255, 255); 
imagettftext($img, 9, 0, 1, 1, $white, "arial.ttf", $html_code); 

// Display the image 
header("Content-type: image/jpeg"); 
imagejpeg($img);

but it doesn't "compile" the html tags and prints them in the image as text.

Best Regards

Upvotes: 3

Views: 4639

Answers (2)

symcbean
symcbean

Reputation: 48357

Short answer is that you can't render HTML without a browser.

A longer answer is that you can render HTML in a browser but you can't easily automate capture of a screenshot (there are activeX widgets to do this - but activeX is such a bad idea). A better approach is to use a HTML client which can render to a suitable format - e.g. xhtml2pdf, there are also online services available for this

Upvotes: 0

heximal
heximal

Reputation: 10517

the GD lib does not have the ablilty to render html-code and draw it on the image. if you want to draw bold text you need to use bold font, e.g. arialbd.ttf

Upvotes: 3

Related Questions