0

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!

Tobias Hagenbeek
  • 1,212
  • 3
  • 15
  • 30
  • 1
    The problem you're facing seems similar to this one. [Converting HTML to plain text in PHP for e-mail](http://stackoverflow.com/questions/1884550/converting-html-to-plain-text-in-php-for-e-mail/2564472). Perhaps that would of some help – Kostis Mar 06 '16 at 17:32
  • I knew i was looking at the problem wrong. That looks like a good direction, thank you!! – Tobias Hagenbeek Mar 06 '16 at 17:34

0 Answers0