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.
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
convert html to image
Load html from file or url
This is example how to convert webpage into image with php script
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.