Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2007

Tip: Looking for answers? Try searching our database.

Generate Website(HTML) thumbnails on the fly

Thread view: 
aussie - 27 Mar 2007 14:00 GMT
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.
aussie - 27 Mar 2007 14:27 GMT
> 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
[quoted text clipped - 5 lines]
>
> 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);
        }
    }
aussie - 27 Mar 2007 14:29 GMT
> 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
[quoted text clipped - 5 lines]
>
> 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);
        }
    }
aussie - 27 Mar 2007 14:36 GMT
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);
        }
    }


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.