web page to image [message #175561] |
Sun, 09 October 2011 00:39  |
bob
Messages: 11 Registered: February 2011
Karma: 0
|
Junior Member |
|
|
I want to turn a web page into a 768x1024 image using PHP. For
instance the script might load http://www.example.com/ and output a
768x1024 image. Anyone know how to do this?
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: web page to image [message #175674 is a reply to message #175561] |
Tue, 18 October 2011 00:40  |
gordonb.cydcw
Messages: 1 Registered: October 2011
Karma: 0
|
Junior Member |
|
|
> I want to turn a web page into a 768x1024 image using PHP. For
Is there a reason for this, besides, of course, Copyright Infringement?
> instance the script might load http://www.example.com/ and output a
> 768x1024 image. Anyone know how to do this?
You need something that will render HTML. There are some packages
that are essentially intended to *PRINT* HTML, but can be used to
get the page rendered into some other format.
One way to do it (manually) is to use the Firefox "print to file"
to print to a .pdf file, then use pdftoppm and one other program
from the NetPBM package to convert it to your favorite form of image
(.png (use pnmtopng), .jpeg (use pnmtojpeg), or whatever). Or you
could save to PostScript and use GhostScript to convert it to your
favorite image format.
Another way to do it (manually or from a script) is to use html2ps
to render the page in Postscript, then use GhostScript to convert
it to your favorite format (GhostScript has a variety of "devices"
which amount to outputting an image of various types into a file).
This can be invoked from PHP running a series of shell commands or
a shell script. Be careful of where you create temporary files or
you'll run into permission problems, as PHP usually runs under an
id without many privileges. Also don't use fixed temporary file
names as several users may be requesting this at the same time,
and they'll clobber each other.
You may need to come up with a way of specifying a "paper size"
that matches what you want in an image, as the first step thinks
it's formatting stuff for a printer.
|
|
|