| Author |
Topic Search Topic Options
|
Mattblack
Groupie
Joined: 21 January 2003
Location: United Kingdom
Status: Offline
Points: 139
|
Post Options
Thanks(0)
Quote Reply
Topic: Image manipulation Posted: 13 November 2004 at 7:37pm |
hi all, im back again!
How do i create a thumbnail of a picture dynamically? Do, say i have a directory of images, and each one needs to be displayed as a small thumbnail which can be clicked on to open the full picture.
The thumbnail would need to be small in size aswell as filesize as there will be loads on 1 page.
I dont have access to the server to install scripts.
Thanks
|
 |
dpyers
Senior Member
Joined: 12 May 2003
Status: Offline
Points: 3937
|
Post Options
Thanks(0)
Quote Reply
Posted: 13 November 2004 at 10:32pm |
Well, if you can't install an asp script, you're hosed. There's no way to create thumbnails server-side without scripting and a 3rd party component like aspjpeg.
You can resize the the original image using html height and width, but it still uses the original large file.
Autocreating thumbnails doesn't work very well anyway if the original pics don't have the same hxw ration as the thumbnails. Even then, image quality usually suffers. You're better off to create the thumbnails in some offline paint program if you need quality thumbnails.
|
Lead me not into temptation... I know the short cut, follow me.
|
 |
Mart
Senior Member
Joined: 30 November 2002
Status: Offline
Points: 2304
|
Post Options
Thanks(0)
Quote Reply
Posted: 14 November 2004 at 4:33am |
If you have ASP.NET just save this code as thumbnail.aspx and then just
point the image to thumbnail.aspx?source=images/mypicture.jpg
<%@ Page Language="vb" %>
<%@ Import Namespace="System.Drawing" %>
<script runat="server">
Public Sub Page_Load
Response.ContentType = "Image/Jpeg"
Dim SourceImage As New Bitmap(Server.MapPath(Request.QueryString("source"))
Dim NewWidth As Integer = SourceImage.Width
Dim NewHeight As Integer = SourceImage.Height
Do Until NewWidth < 100 And NewHeight < 100 NewWidth = NewWidth / 2 NewHeight = NewHeight / 2
Loop
Dim SourceImage As Bitmap = b.GetThumbnailImage(NewWidth, NewHeight, Nothing, IntPtr.Zero)
Thumbnail.Save(Response.OutputStream, ImageFormat.Jpeg)
Thumbnail.Dispose()
SourceImage.Dispose()
End Sub
</script>
|
Edited by Mart
|
 |
Mattblack
Groupie
Joined: 21 January 2003
Location: United Kingdom
Status: Offline
Points: 139
|
Post Options
Thanks(0)
Quote Reply
Posted: 14 November 2004 at 8:10am |
hi all, thanks for that.
Dpyers, it must be "on the fly" as these images will be uploaded by visitors (motorbike sales/wanteds)
Mart, thanks for that. Yes i do have .Net, just dont have experience with it. Code looks good though, will try it now,
Thanks to you both
|
 |
Mattblack
Groupie
Joined: 21 January 2003
Location: United Kingdom
Status: Offline
Points: 139
|
Post Options
Thanks(0)
Quote Reply
Posted: 14 November 2004 at 8:16am |
cant get it to work mate, just get the little red cross in box.
Tried all options with the source, as virtual and physical paths. In quotes and without.
eeeek!
|
 |
Mart
Senior Member
Joined: 30 November 2002
Status: Offline
Points: 2304
|
Post Options
Thanks(0)
Quote Reply
Posted: 14 November 2004 at 8:57am |
|
Ok, go to the image resizer in your browser (i.e. yoursite.com/thumbnail.aspx?source=motorbike1.jpg)
and there should be an error showing, paste it in here
|
 |
Mart
Senior Member
Joined: 30 November 2002
Status: Offline
Points: 2304
|
Post Options
Thanks(0)
Quote Reply
Posted: 14 November 2004 at 10:12am |
actually I can see the error, this should work:
<%@ Page Language="vb" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<script runat="server">
Public Sub Page_Load
Response.ContentType = "Image/Jpeg"
Dim SourceImage As New Bitmap(Server.MapPath(Request.QueryString("source")))
Dim NewWidth As Integer = SourceImage.Width
Dim NewHeight As Integer = SourceImage.Height
Do Until NewWidth < 100 And NewHeight < 100
NewWidth = NewWidth / 2
NewHeight = NewHeight / 2
Loop
Dim Thumbnail As Bitmap = SourceImage.GetThumbnailImage(NewWidth, NewHeight, Nothing, IntPtr.Zero)
Thumbnail.Save(Response.OutputStream, ImageFormat.Jpeg)
Thumbnail.Dispose()
SourceImage.Dispose()
End Sub
</script>
|
Edited by Mart
|
 |
Mart
Senior Member
Joined: 30 November 2002
Status: Offline
Points: 2304
|
Post Options
Thanks(0)
Quote Reply
Posted: 14 November 2004 at 10:19am |
|
p.s. that script will scale the image down until it is smaller than
100px by 100px, if you want the thumbnail bigger or smaller just edit
line 13:
Do Until NewWidth < [smller than width] And NewHeight < [smaller than height]
|
 |