I am trying to take a piece of HTML, ie:
<p>This is a nice test</p><p><br></p><p></p><ol><ol><li>We have a great product!</li><li>Our store is awesome!</li><li>We love what we do, which makes us really good at it!</li></ol></ol><p></p>
And get it printed onto an image, centered for the size of this certain piece of HTML.
I don't care much if it will become a JPG, PNG or whatever, but i would like to have an image the size of 1080p or so (1920x1080), not sure if that even matters.
I can create an image with a string printed in the center, using something like this:
$image = imagecreate( 1920, 1080 );
$rgb = $this->hex2rgb($data['color']);
$background = imagecolorallocate( $image, $rgb[0], $rgb[1], $rgb[2] );
$text_colour = imagecolorallocate( $image, 255, 255, 0 );
imagecenteredstring( $image, 4, 210, 1710, 540, '<p>This is a nice test</p><p><br></p><p></p><ol><ol><li>We have a great product!</li><li>Our store is awesome!</li><li>We love what we do, which makes us really good at it!</li></ol></ol><p></p>', $text_colour );
$tmpPath = '/tmp/' . strtotime('now') . '.jpg';
imagesetthickness ( $image, 5 );
header( "Content-type: image/jpeg" );
imagejpeg( $image, $tmpPath);
imagecolordeallocate( $text_color );
imagecolordeallocate( $background );
imagedestroy( $image );
where hex2rgb
is a function to convert the rgb input, this works, and where imagecenteredstrng
takes a string and centers it onto an image, this also works.
So my main issue is how to "translate" the raw html into "interpreted", and then onto the image...
Thanks!