Click here to Skip to main content
Click here to Skip to main content

Webpage thumbnailer

By , 17 Aug 2006
 

Introduction

Once upon a time, I got an idea to have a thumbnail of a webpage associated with each URL that I had on my list. Sort of a URL with "face" :). I began to research on how to implement it, and found no solution for it in the open software domain. Many that I found were commercial products in the form of components and standalone programs. I'm just a poor programmer, and couldn't spend much to buy such a component. I was sure that there would be a way (even several) to achieve this goal without touching my child's spare money. And what I present in this article is what I found.

Using the code

Before you get into the code, you can build it and play around with it. The URL should be in a form http://www.yoursite.com, for example. I didn't write URL validation code, so you have to be careful about it. The project is very simple, and there are only a couple of points that I have to mention. To get the thumbnail image of the webpage, I use the WebBrowser component that comes with Visual Studio 2005 and is a part of the .NET framework v.2. I placed it on a BrowserForm, and set the size of the form to approximately 600 to 800 pixels to get enough visual data. Then, the BrowserForm is initialized, but is actually never shown. And this makes a trick.

private void TestForm_Load(object sender, EventArgs e) {
 browserForm = new BrowserForm(); 
}

What I have to do then is to take a snapshot of the WebBrowser after the page is loaded. That's all!

  Bitmap docImage = new Bitmap(600, 800);
  webBrowser1.DrawToBitmap(docImage, new Rectangle(webBrowser1.Location.X, 
          webBrowser1.Location.Y, webBrowser1.Width, webBrowser1.Height));
}

The page takes some time to load, and because of that, I've split the getting of the image in to three steps:

  1. I call the method getImageFromUrl(string url) on a BrowserForm that starts downloading the page from a given URL.
  2. The WebBrowser event DocumentCompleted is handled by the procedure webBrowser1_DocumentCompleted. It sets the image of the current DocPic object.
  3. The setter of the current DocPic object triggers the refreshPicture event that updates the displayed picture. Some resizing is made on place.

All code provided is purely for demonstration purposes only, so don't try to find design issues in it. You'll certainly find it if you try.

History

It's nice to know that on your website I can write history :). Thanks to the admin!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

dooskoobi
Web Developer
Belgium Belgium
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Questionplease provide alternative versionmembersneha kavinkar24 Jun '12 - 21:23 
GeneralThanksmemberMember 78098223 Apr '11 - 19:39 
Questionapplet problemmemberdomartins10 May '08 - 7:55 
QuestionHow save imagememberrashidpervaiz086 Feb '08 - 23:22 
GeneralReal heightmemberBizounours19 Nov '07 - 2:58 
AnswerRe: Real heightmemberdooskoobi19 Nov '07 - 9:42 
GeneralRe: Real heightmemberBizounours19 Nov '07 - 21:07 
AnswerRe: Real height - SOLUTIONmembertfpds12 Dec '07 - 3:28 
QuestionBlank Image on Websites with Java AppletsmemberJon Ebersole9 Feb '07 - 12:58 
AnswerRe: Blank Image on Websites with Java AppletsmemberWei Tian23 Mar '09 - 20:26 
QuestionHow to fix blank image?memberMatt34229 Dec '06 - 14:16 
QuestionASP.Net environmentmemberFranck Quintana26 Oct '06 - 7:24 
AnswerRe: ASP.Net environmentmemberdooskoobi26 Oct '06 - 10:51 
GeneralRe: ASP.Net environmentmemberFranck Quintana27 Oct '06 - 15:27 
GeneralRe: ASP.Net environmentmembergedw9927 May '07 - 6:36 
GeneralRe: ASP.Net environmentmemberFranck Quintana27 May '07 - 23:24 
GeneralRe: ASP.Net environmentmemberDmitryKirsanov12 Oct '11 - 10:24 
GeneralFixed blank image [modified]memberRandall Stephens16 Oct '06 - 6:13 
GeneralRe: Fixed blank image [modified]memberNutSoft16 Nov '06 - 1:37 
GeneralBlank Imagemembersides_dale8 Sep '06 - 16:32 
It seems the blank image problem revolves around pages that have iframes embedded in the html. For an example: try to run the program against http://www.microsoft.com you will get a perfect picture.
 
The only iframes in the page are created with javascript. This is created in lines 126 thru 128
<script type="text/javascript">var AdHtml='<iframe frameborder="0" scrolling="no" marginheight="0px" marginwidth="0px" allowtransparency="true" style="background:#F1F1F1" width="120" height="240" src="http://rad.microsoft.com/ADSAdClient31.dll?GetAd=&PG=CMSIE4&SC=F3&AP=1164"><'+'/iframe>';document.writeln(AdHtml);</script>

 
Now look at http://msdn.microsoft.com. You get a blank image and the difference is that there are embedded iframes in the html, that are not created with javascript. Look at lines 717 thru 719

<iframe frameborder="0" scrolling="no" marginheight="0px" marginwidth="0px" width="120" height="240" id="rad_CMSAD2F3" src="http://rad.microsoft.com/ADSAdClient31.dll?GetAd=&PG=CMSAD2&SC=F3&AP=1164"></iframe>

 
and lines 1090 thru 1092
 
<iframe frameborder="0" scrolling="no" marginheight="0px" marginwidth="0px" width="120" height="90" id="rad_CMSAD1F2" src="http://rad.microsoft.com/ADSAdClient31.dll?GetAd=&PG=CMSAD1&SC=F2&AP=1027"></iframe>

 
Not sure why this would cause a blank image because stepping through the code and it gets to the event handler for webBrowser1_DocumentCompleted you can do a ?webBrowser1.DocumentText and retrieve the text for the page, which means the complete page is retrieved, meaning that the page should have been rendered. So your guess is as good as mine on why it is not rendered to the bitmap.Confused | :confused:
GeneralRe: Blank Imagememberdooskoobi9 Sep '06 - 12:23 
GeneralRe: Blank ImagememberNoah Nadeau4 Apr '08 - 5:51 
GeneralRe: re "I can write history:"memberBillWoodruff26 Aug '06 - 0:59 
GeneralNice findmemberSimone Busoli23 Aug '06 - 6:58 
GeneralRe: Nice findmemberdooskoobi24 Aug '06 - 8:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 17 Aug 2006
Article Copyright 2006 by dooskoobi
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid