Re: Turning HTML into an Image
by stephen (Priest) on May 10, 2002 at 23:46 UTC
|
Since HTML is a formatting language, not a layout language, you won't get perfect results.
For basics, though, I'd recommend Image::Magick. It requires installation of ImageMagick (see www.imagemagick.org), ghostscript, and a whole bunch of other subsidiary programs, but you can transform HTML into pretty much any kind of image you want. Plus, you'll find it handy in resizing those images.
You might also want to check out HTML::FormatPS.
stephen
| [reply] |
|
| [reply] |
|
Ah, sounds like you've found the HTML to HTML2PS to GhostScript to JPEG method that I used before I discovered ImageMagick (which still needs HTML2PS to convert HTML files).
First I would download and then (if you really wanted to keep as much of the code in Perl as possible, download PerlMagick: but be warned, I know on Windows machines it can take quite a bit of tweaking to get working). Then install HTML2PS.
Once you've got ImageMagick+HTML2PS setup, I would call the convert function with the command convert myinputfile.html myoutputfile.jpg. The reason I used ImageMagick for the project I worked on was because I needed to make thumbnail images on the fly for a large number of different image types.
| [reply] [d/l] |
Re: Turning HTML into an Image
by tachyon (Chancellor) on May 11, 2002 at 01:40 UTC
|
Is there anything wrong with popping a new window and displaying the HTML template in
it as HTML? Do you need to scale it, thus the desire for an image?
An image of any significant size will be much slower than the real HTML
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
| [reply] |
|
| [reply] |
Re: Turning HTML into an Image
by samtregar (Abbot) on May 11, 2002 at 01:29 UTC
|
I suppose one option would be to build a script that opens the HTML in a web browser and then takes a screenshot of the web browser window. This is likely to be slow and non-portable, but I think it would work. If you could do it offline and cache the images it could probably be made to work.
A better solution might be to try to interface with an HTML rendering engine (like the Gecko engine used by Mozilla) and use it to generate a rendering in an image. This could be a very difficult task, but the results would likely be much better. If you go this route, consider building a Perl module that others can use to do the same task. A Perl interface to Gecko, for example, would be a popular module!
-sam
| [reply] |
Re: Turning HTML into an Image
by cLive ;-) (Prior) on May 11, 2002 at 12:43 UTC
|
Damn you mdog, damn you! Just spent half an hour looking. The word you are looking for is displet.
This looks promising.
cLive ;-)
--
seek(JOB,$$LA,0);
| [reply] |
Re: Turning HTML into an Image
by Stegalex (Chaplain) on May 11, 2002 at 17:49 UTC
|
May not be what you are looking for, but I had to do something similar. I run a small retail website and one of the things I have to do is to convert HTML shipping information into a nicely formated packing slip. What I do is run the HTML through a utility called html2ps and then run the resulting postscript through ps2pdf so that our warehouse guys can open a link to PDF docs and print them and stick them in boxes. Fun fun!
~~~~~~~~~~~~~~~
I like chicken. | [reply] |
Re: Turning HTML into an Image
by ejf (Hermit) on May 12, 2002 at 00:58 UTC
|
If you have the possibility of running parts of KDE on the machine that is going to generate the images, you could use the kwebdesktop program to use the khtml-Engine (the same as in Konqueror, i.e. a /very/ good one ;) to get you a rendered image of your site ...
It is intended for use as a desktop background generator, but it should work for your case just as well :
kankoku:~$ kwebdesktop --help
Usage: kwebdesktop Qt-options KDE-options width height file URL
(...)
Arguments:
width
Width of the image to create
height
Height of the image to create
file
Filename where to dump the output in png format.
URL
URL to open
It is part of kdebase. Hope this helps; it's not strictly perl ;) | [reply] |
Re: Turning HTML into an Image
by BUU (Prior) on May 10, 2002 at 23:52 UTC
|
well, before you embark down the ever fun row of trying to dynamicly generate images, how many templates do you have? It might be (much) easier to just screen shot all your different templates and slice/dice them and just retun the .gifs or what not. | [reply] |
|
The reason I need to generate them dynamically is that designers can drop off templates whenever they want (unbeknownst to me) so I need to be able to schedule something that can go through, check for new templates, and generate new "thumbnails" of the HTML...
| [reply] |
|
| [reply] |