Generate Website(HTML) thumbnails on the fly

A

aussie

Our team needs to have a on the fly website thumbnail. I have found
few scripts for php and .net but nothing for java. Preferably I would
like to set up a servlet that can take url as a parameter and return a
thumbnail image of that website. The only lead I have found on the web
was to use JEditorPane(URL) and then invoking the paint method to a
BufferedImage. Any Java GURUs out there who have an idea or an example
on how to do this?

Thanks in advance.
 
A

aussie

Our team needs to have a on the fly website thumbnail. I have found
few scripts for php and .net but nothing forjava. Preferably I would
like to set up a servlet that can take url as a parameter and return a
thumbnail image of that website. The only lead I have found on the web
was to use JEditorPane(URL) and then invoking the paint method to a
BufferedImage. AnyJavaGURUs out there who have an idea or an example
on how to do this?

Thanks in advance.

/**
* @param args
*/
public static void main(String[] args) {
String url = "http://www.google.com";
try
{
//swing stuff
JFrame someWindow = new JFrame();
JEditorPane htmlPane = new JEditorPane(url);

someWindow.setBounds(30, 30, 750, 750);
htmlPane.setEditable(false);
someWindow.add(new JScrollPane(htmlPane));
someWindow.setVisible(true);

BufferedImage pageImage = new BufferedImage ( 500, 500,
BufferedImage.TYPE_INT_RGB );
Graphics2D pageGraphics = pageImage.createGraphics();
htmlPane.paint ( pageGraphics );
ImageIO.write(pageImage, "jpg", new FileOutputStream("C:\
\Documents and Settings\\lakulish.patel\\Desktop\\test.jpg"));
}
catch(IOException ioe)
{
System.err.println("Error displaying " + url);
}
}
 
A

aussie

Our team needs to have a on the fly website thumbnail. I have found
few scripts for php and .net but nothing forjava. Preferably I would
like to set up a servlet that can take url as a parameter and return a
thumbnail image of that website. The only lead I have found on the web
was to use JEditorPane(URL) and then invoking the paint method to a
BufferedImage. AnyJavaGURUs out there who have an idea or an example
on how to do this?

Thanks in advance.

Here is the code used with JeditorPanel
/**
* @param args
*/
public static void main(String[] args) {
String url = "http://www.google.com";
try
{
//swing stuff
JFrame someWindow = new JFrame();
JEditorPane htmlPane = new JEditorPane(url);

someWindow.setBounds(30, 30, 750, 750);
htmlPane.setEditable(false);
someWindow.add(new JScrollPane(htmlPane));
someWindow.setVisible(true);

BufferedImage pageImage = new BufferedImage ( 500, 500,
BufferedImage.TYPE_INT_RGB );
Graphics2D pageGraphics = pageImage.createGraphics();
htmlPane.paint ( pageGraphics );
ImageIO.write(pageImage, "jpg", new FileOutputStream("C:\
\Documents and Settings\\d\\Desktop\\test.jpg"));
}
catch(IOException ioe)
{
System.err.println("Error displaying " + url);
}
}
 
A

aussie

Here is the code used with JeditorPane but the image doesnt render
with the HTML page, it is just plain white. For the servlet I would
write to responses outputstream Instead of using the fileoutputstream.
/**
* @param args
*/
public static void main(String[] args) {
String url = "http://www.google.com";
try
{
//swing stuff
JFrame someWindow = new JFrame();
JEditorPane htmlPane = new JEditorPane(url);

someWindow.setBounds(30, 30, 750, 750);
htmlPane.setEditable(false);
someWindow.add(new JScrollPane(htmlPane));
someWindow.setVisible(true);

BufferedImage pageImage = new BufferedImage ( 500, 500,
BufferedImage.TYPE_INT_RGB );
Graphics2D pageGraphics = pageImage.createGraphics();
htmlPane.paint ( pageGraphics );
ImageIO.write(pageImage, "jpg", new FileOutputStream("C:\
\Documents and Settings\\d\\Desktop\\test.jpg"));
}
catch(IOException ioe)
{
System.err.println("Error displaying " + url);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top