ASP.NET images: Thumbnails
page 1 of 1
Published: 24 Mar 2004
Unedited - Community Contributed
Abstract
In previous parts to this tutorial I showed you how we can use the system.drawing namespaces to build images on the fly, load and modify images and return them to the user. This article shows the algorithm for resizing an image while keeping its aspect ratio.
by Chris Garrett
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 14317/ 34

ASP.NET images: Thumbnails

In previous parts to this tutorial I showed you how we can use the system.drawing namespaces to build images on the fly, load and modify images and return them to the user. This article shows the algorithm for resizing an image while keeping its aspect ratio.

The script returns an image which will fit into a thumbnail size I chose at random of 200x200 pixels.

View the sourcecode

In the previous example we specified the size of the image to output on the querystring. This time we call a new function which returns what the size should be, called "NewThumbSize" which returns a "size" object (basically an object containing a height and width).

The "NewThumbSize" function checks to see if the image is portrait or landscape, then works out the multiplier (the division of our arbitrary 200 pixels and the height or width). There is an obvious flaw here that the image could end up bigger than it started, I will leave this as an exercise for the reader ;O)

Once we have the new size using the above multiplier, we return the new size object and use it to set the width and height of the image to output.



User Comments

Title: Want the same code in C#   
Name: sailaja
Date: 2010-10-04 5:25:14 AM
Comment:
Hi sir..
Can you please provide the image viewer code in C#??

Thank in Advanced
Title: Using this resize in a Data   
Name: Brett
Date: 2008-09-09 2:30:26 AM
Comment:
Is it possible to use this code to resize multiple images displayed in a repeater control?

Or does this become alot more complex?
Title: how can i make thumbnail of any image   
Name: suroor
Date: 2008-01-24 7:06:48 AM
Comment:
hi
i want to make thumbnail of jpeg or jpg images in datalist control. plz help me...........
Title: how to change the position of thumbnail.   
Name: mahi
Date: 2007-06-19 6:43:34 AM
Comment:
hi..
i got thumbnail but i dont know to position it..the displayed images is there is the left top corner and i move this to center..
plz help me to change the position..
Title: Image Resize   
Name: ranu
Date: 2006-09-27 3:20:18 AM
Comment:
Hi

I saw ur artile "ASP.NET images: Thumbnails"

Well I was trying to resize image to print them .

I want to print the image in 3X5 ,4X6 , 5X7 with /without aspect ratio

How will I do this ????????

Any clue

Thanks in advance.
Title: Thanks mate   
Name: Bryan
Date: 2006-09-02 6:57:50 AM
Comment:
Thanks for the code mate. handy little snippet
Title: images   
Name: vidyamahajan
Date: 2006-04-07 6:58:50 AM
Comment:
hi chris
i m new in this field, i read ur articles. This article helped me a lot. Thanks for ur contibution.
Title: saving image   
Name: dutt dev
Date: 2005-08-22 3:57:03 AM
Comment:
I want to save thumbnail image in the server directory other than the origional image . how can i do
Title: in vb.net   
Name: jason
Date: 2005-08-02 4:39:40 AM
Comment:
hi.. i am new in .net environment... so now planning to do something like thumbnail in the site..~ could u redirect me to work with it?
thanks..`
Title: Need Fullfilled   
Name: Shawn
Date: 2005-03-23 8:09:49 PM
Comment:
Chris, I'm new to .Net From Classic ASP, I was looking for something like this....thanks!
Title: Just needed the method   
Name: Marc
Date: 2005-03-10 10:29:32 AM
Comment:
Chris, thanks for the example. My interest was to find the way I could shrink images on the fly. I easily pulled this aspx source into my workbench webapp, added a directory with an image, specified the query string value and was presented with a shrunken image.
I was then able to code my functionality for shrinking each image to a workable size for my family's photo viewer.
thanks again for the simple example.
Title: Images positioning   
Name: Chris
Date: 2004-06-14 6:20:06 AM
Comment:
You reference the image as the src of the img tag, position it just like any other image in your html
Title: Images positioning   
Name: M. A.
Date: 2004-06-14 5:42:47 AM
Comment:
is there any way to position this images inside table cells or other containers??

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-10-08 9:01:38 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search