Thursday, May 14, 2009

HTML2Image web frontend

For those interested in the technical details, Guangming Software distributes a mini web server with their program that only talks to their program. The program works from the command line or as a CGI from their web server (and no other, AFAIK). The first thing you need to do is start the background X imager like this (use the 64 Bit Ubuntu version, not the one they supply):

Download Location :

Install the package into /usr/local/html2image, you'll also need to install some software thus:

apt-get install ia32-libs
apt-get install ia32-libs-gtk
apt-get install xserver-xorg
apt-get install xhost

Make sure the following is in /etc/environment:


Run XHOST to allow Screen access:

xhost +

Then you can start with running the Xvfb server:

cd /usr/local/html2image
Xvfb :1 -screen 0 1024x768x16 -nolisten tcp -auth X1.cfg >$LOG 2>&1 &

Then, you need to start their mini web server, running as the same user as the regular web server:

su www-data
/usr/local/html2image/nweb 8181 /usr/local/html2image

Then you can use a url to get an image:


The only problem is what you get back is the text output of the html2image program itself, not the image. The image goes to a file on the local server's hard drive (/tmp/image.jpg in this case) which isn't very helpful unless it runs on the same server you're working from. Create the html2image.php file in the www root:

$HOST = "http://localhost:8181";
$OPT = "/para=-H&768&-W&1024&-Q&100&-t&8000&";
$URL = $_GET["url"];
$OUTFILE = "/tmp/image".getmypid().".jpg";
$TMPFILE = "/tmp/image".getmypid().".txt";
# This should work, but you get some sort of
# a stream creation error that screws the image up.
#$lines = file($HOST.$OPT.$URL."&".$OUTFILE);
# This works, but isn't pretty!
exec("wget -O ".$TMPFILE." '".$HOST.$OPT.$URL."&".$OUTFILE."'");
header("Content-Type: image/jpeg");
$img = @imagecreatefromjpeg($OUTFILE);

Execute the Image grab with the URL:


No comments:

Post a Comment