get an off-screen thumbnail from a webpage

Hello everyone! This is my first post on this forums.

I'm developing an application to get a thumbnail from a webpage, and save that thumbnail to a file. It has to be a "non-visual", off-screen appllication, because it will run on a machine with no screen. It has to render all, or almost all webpages.

The thumbnails created by this app will be used on another app which lists links from an user, like it's shown in http://del.icio.us ; what I want is to generate these thumbnails.

I've previously searched for a solution in this post: http://forum.java.sun.com/thread.jspa?forumID=20&threadID=709683 , it is not exactly what I want. I need a real image to be generated, not only a page preview.

I've tried to use several java-based projects founded on Internet, but I didn't success because sometimes they render ok the page (using a window), but don't paint ok to file; sometimes they paint ok to file, but doesn't render ok the page (using a window) due to poor support of current HTML and CSS standards, as they are based on JEditorPane or the project is abandoned..

The best approach I have made is with Flying Saucer (https://xhtmlrenderer.dev.java.net/), it does exactly what I need, it has even a method to do this, but it is very rigid about standards and doesn't render "real world html". Related to this I've tried to get code from page, clean it with tagsoup and then pass the xhtml code parsed to Flying Saucer's renderer, but it still has problems rendering the majority of webpages.

Any ideas? Anything that can put me in the right direction is welcome.

Thanks!

[1645 byte] By [pmagundeza] at [2007-11-27 9:38:24]
# 1

Well, it isn't free, but assuming you have a budget, http://www.webrenderer.com/ does what you're trying to do. I was looking into it for a project of my own for use as a pure-java web widget, the rendering engine is a java port of the mozilla engine. Seems to do a high quality job, even on real-world webpages.

lraca at 2007-7-12 23:11:42 > top of Java-index,Security,Cryptography...
# 2
Thanks for your answer. Yes I found webrenderer while searching for a solution, but I discarded it because I don't have a budget : ), I didn't even tried it on my app, but seems to do the work I need. I need something like this but open source, freeware...
pmagundeza at 2007-7-12 23:11:42 > top of Java-index,Security,Cryptography...
# 3

If the web page you want an image of appears on screen (even for a moment) maybe you could take a screen shot of it and use the resulting image for your thumbnail.

There is some code for taking screen shots here:

http://schmidt.devlib.org/java/save-screenshot.html

Although you may have to find a way to locate the specific window and get it's position and size. This should be possible, though, search for stuff like finding windows handles with Java.

Hope this helps, slegge

sleggea at 2007-7-12 23:11:43 > top of Java-index,Security,Cryptography...
# 4
Thanks slegge for your answer, but that's just the problem, the code will run on a linux server which hasn't any screen, so I can't do what you suggest. I tried it before, and it worked on my computer, but it can't be deployed on the server. If the server had only one
pmagundeza at 2007-7-12 23:11:43 > top of Java-index,Security,Cryptography...
# 5

This is of interest to me as well since I might want to do this in the near future. So far I have two suggestions

One is rather evil since it includes leaching of someone else抯 service but if your program isn抰 going to be running up a large number of requests for this feature then I was wondering if you could just piggy back from sites that provide this kind of functionality already. For example:

http://ipinfo.info/netrenderer/

Granted you are restricted to the dimensions of the snap shot but this could provide a simple solution if nothing else works.

Otherwise have you tried JRex which is an embedded Java Browser based on Mozilla GECKO as there might be a possibility you could use it to create a snap shot as this thread in the mailing list archive shows:

http://www.mozdev.org/pipermail/jrex/2006-August/002619.html

Although it uses the Robot class to get a screen shot of the web page; which I understand is not possible to do in your case. Instead you could just convert the jPanel straight into an image.

Check this thread about saving JPanel contents as an image file :

http://forum.java.sun.com/thread.jspa?threadID=477654&messageID=2220990

Or take a look at camickr's ScreenImage class:

http://forum.java.sun.com/thread.jspa?threadID=604040

Keep us posted if you ever do find the solution you were looking for.

4fingersa at 2007-7-12 23:11:43 > top of Java-index,Security,Cryptography...