html to image php script

App or game developer always need a tool / script that convert your static or dynamic html to image . As in case if you are php developer and want to know how to convert html to jpeg image in simple way then this article is for you.

In this post you will learn how to convert html to image. I have to discover this trick when I was making a facebook game and script need to post dynamic game score  on user’s wall. My client provided me the html of result webpage but all we need is just to convert this dynamic result html to jpeg.

This is the simple way and you have to compromise with its image quality.This html to image php script  does not require any external api or GD Library, Most of the server does not have GD library extension.

 

Demo

Why we need to convert html to image.

As i told if we have some html and it is changeable html or php page and we want to capture it as snapshot.

  • Facebook application development
  • For Tutorial website
  • For development purposes

What we don’t need to convert html to image with php

We will create html to snapshot without using any php gd library or any third party API. Now we will convert html to pdf with php

  • Without using third party API.
  • Without using php GD Library.
  • Without any shell script or window command.

What we need to convert html to image

How it Works

The idea behind conversion is simple. We will first convert html of any webpage to pdf using HTML2PDF utility and then we will convert pdf doc to an image.
html to image php script

convert html to image

Load html from file or url

This is example how to convert webpage into image with php script

echo file_get_contents('http://buffernow.com/');

Convert html to pdf

 $html2pdf = new HTML2PDF('P', 'A4');
 $html2pdf->writeHTML($html_content);
 $file = $html2pdf->Output('temp.pdf','F');

Convert pdf to image

$im = new imagick('temp.pdf');
$im->setImageFormat( "jpg" );
$img_name = time().'.jpg';
$im->setSize(800,600);
$im->writeImage($img_name);
$im->clear();
$im->destroy();

This is all about how to convert webpage or html to image.

Demo

 

 Download

[social_lock]Download [/social_lock]

 

 

  • M Ali

    thanks for the info, can you send me the source code of the demo. thanks

    • buffernow

      hi Ali
      download is available now
      enjoy..

  • M Ali

    thanks for the info, can you send me the source code of the demo. thanks

    • buffernow

      hi Ali
      download is available now
      enjoy..

  • M Ali

    thanks

  • M Ali

    thanks

  • sujit

    hi, can this be used along with Codeigniter framework ?

    • buffernow

      yes sure .

  • sujit

    hi, can this be used along with Codeigniter framework ?

    • buffernow

      yes sure .

  • Andy Hug

    i’m trying to download the script and when i click the button nothing happens. I mention that I have javascript enabled

    thxs

    • buffernow

      Sorry For that.
      we were updating the blog
      Now its working.

  • Andy Hug

    i’m trying to download the script and when i click the button nothing happens. I mention that I have javascript enabled

    thxs

    • buffernow

      Sorry For that.
      we were updating the blog
      Now its working.

  • dammah

    Fatal error: Class ‘imagick’ not found in C:xampphtdocshtml2_imagehtml2image.php on line 27

    • buffernow

      seems like
      imagick extension is not activated or installed.

  • dammah

    Fatal error: Class ‘imagick’ not found in C:xampphtdocshtml2_imagehtml2image.php on line 27

    • buffernow

      seems like
      imagick extension is not activated or installed.

  • Marco Restom

    Great guide!

    That code says “>” insetad of “>”

  • Marco Restom

    Great guide!

    That code says “>” insetad of “>”

  • mubarak

    Hi, if i try to update a large content, it doesnt work, am i missing anything?

  • Hongkong LaserJet

    Thankx.. I want to capture full screen screenshot with full height and width. What is the change in it…

    another one issue in your code is It doesn’t support Gujarati text..

    I want to capture gujarati text html as a image. Please help me to find out issue

  • mayur

    Hello there,
    Unable to download demo source code

    thanks in advance.