Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create image from html

Tags:

php

gd

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

like image 404
SAFAD Avatar asked Mar 16 '26 19:03

SAFAD


1 Answers

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

like image 89
heximal Avatar answered Mar 20 '26 23:03

heximal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!