Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Image manipulation
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Image manipulation

 Post Reply Post Reply Page  12>
Author
Mattblack View Drop Down
Groupie
Groupie
Avatar

Joined: 21 January 2003
Location: United Kingdom
Status: Offline
Points: 139
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mattblack Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
dpyers View Drop Down
Senior Member
Senior Member


Joined: 12 May 2003
Status: Offline
Points: 3937
Post Options Post Options   Thanks (0) Thanks(0)   Quote dpyers Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Mattblack View Drop Down
Groupie
Groupie
Avatar

Joined: 21 January 2003
Location: United Kingdom
Status: Offline
Points: 139
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mattblack Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
Mattblack View Drop Down
Groupie
Groupie
Avatar

Joined: 21 January 2003
Location: United Kingdom
Status: Offline
Points: 139
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mattblack Quote  Post ReplyReply Direct Link To This Post 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!

Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post 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]
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.