Pass HTML to image [closed]

1

My problem is this, I need a js or PHP library to be able to pass HTML code to an image and it is downloaded automatically.

$html = "<div><p>Soy un código HTML</p></div>"

htmltoPNG(<?php echo $html ?>);
<script>
        function htmltoPNG(html) {
          //Codigo que convierta el html a una imagen png
          descarga(imagen);
        }
</script>
    
asked by Federico 28.04.2016 в 19:13
source

1 answer

2

Using html2pdf you can convert html to jpg :

<?php
 require_once('html2_pdf_lib/html2pdf.class.php');

if(isset($_POST['snapshot'])){
   $html = stripslashes($_POST['url']); 
   ob_start(); 

?>

<page style="font-size: 14px">
<?php
   echo $html;
?>
</page>
<?php 
   $content = ob_get_clean();
   ob_clean ();


  try
  {
      $html2pdf = new HTML2PDF('P', 'A4', 'en');

      $html2pdf->setDefaultFont('courier');
      $html2pdf->writeHTML($content);
      $file = $html2pdf->Output('temp.pdf','F');
      //pdf creation

      $im = new imagick('temp.pdf');
      $im->setImageFormat( "jpg" );
      $img_name = time().'.jpg';
      $im->setSize(300,200);
      $im->writeImage($img_name);
      $im->clear();
      $im->destroy(); 
      //remove temp pdf
      unlink('temp.pdf');
 }
 catch(HTML2PDF_exception $e) {
    echo $e;
    exit;
 }
}
    
answered by 28.04.2016 / 20:16
source