| Author |
Topic Search Topic Options
|
ultramods
Groupie
Joined: 08 January 2003
Location: Scotland
Status: Offline
Points: 146
|
Post Options
Thanks(0)
Quote Reply
Topic: Image resizing Posted: 18 November 2003 at 4:46am |
I have currently been using asp jpeg to resize images to create thumbnails. However i wish to use some .net enabled hosting which doesnt use this component. I have never used .net before but have found this script for resizing images and would just like to know if this script would actually work before I buy the .net space. Thanks for any help given on this.
' Initialize objects Dim objImage, objThumbnail As System.Drawing.Image Dim strServerPath, strFilename As String Dim shtWidth, shtHeight As Short ' Get image folder path on server - use "\" string if root strServerPath = Server.MapPath("WebAppImageFolder\") ' Retrieve name of file to resize from query string strFilename = strServerPath & Request.QueryString("filename") ' Retrieve file, or error.gif if not available Try objImage = objImage.FromFile(strFilename) Catch objImage = objImage.FromFile(strServerPath & "error.gif") End Try ' Retrieve width from query string If Request.QueryString("width") = Nothing Then shtWidth = objImage.Width ElseIf Request.QueryString("width") < 1 Then shtWidth = 100 Else shtWidth = Request.QueryString("width") End If ' Work out a proportionate height from width shtHeight = objImage.Height / (objImage.Width / shtWidth) ' Create thumbnail objThumbnail = objImage.GetThumbnailImage(shtWidth, _ shtHeight, Nothing, System.IntPtr.Zero) ' Send down to client Response.ContentType = "image/jpeg" objThumbnail.Save(Response.OutputStream, Imaging.ImageFormat.Jpeg) ' Tidy up objImage.Dispose() objThumbnail.Dispose()
|
 |
Mart
Senior Member
Joined: 30 November 2002
Status: Offline
Points: 2304
|
Post Options
Thanks(0)
Quote Reply
Posted: 18 November 2003 at 10:30am |
|
Yes it will work, it uses standard system.drawing namespaces.
|
 |
ultramods
Groupie
Joined: 08 January 2003
Location: Scotland
Status: Offline
Points: 146
|
Post Options
Thanks(0)
Quote Reply
Posted: 18 November 2003 at 12:30pm |
|
Ok, thanks for that Mart.
|
 |
Diam
Newbie
Joined: 27 November 2003
Location: Belgium
Status: Offline
Points: 2
|
Post Options
Thanks(0)
Quote Reply
Posted: 27 November 2003 at 3:35am |
Hello everybody,
I need your help for something similar.
I would like generate a thumbnail of a picture (.jpg) located on the webserver, but unfortunately my hosting do not allow me to register any component.
It seems it's not possible to do that only with ASP (without component), but only with ASP.Net, but unfortunately, I'm not able to write any line with ASP.Net by myself.
What I could to, it's save the image to resize on a specific folder, call an ASP.Net page with few parameters : the path of the image, a return code (if error ?), the max size (width, height), ... and an URL where to go after the operation is complete).
It could be also very good to allow to know the size (width, height) of a picture with another page (and return it in a parameter)...
What do you think about that ? Anyone who could help me to do that ?
Thanks a lot for your help !
|
 |
Mart
Senior Member
Joined: 30 November 2002
Status: Offline
Points: 2304
|
Post Options
Thanks(0)
Quote Reply
Posted: 27 November 2003 at 9:23am |
|
Use the code posted above!
|
 |
Diam
Newbie
Joined: 27 November 2003
Location: Belgium
Status: Offline
Points: 2
|
Post Options
Thanks(0)
Quote Reply
Posted: 27 November 2003 at 12:18pm |
But, this page generate a thumbnail and send it to the client... what I would like, if it's possible, it's to write it on the webserver... (I don't want the webserver need to generate the thumbnail everytime someone want view it...)
For exemple...
- Form1.asp (a form where it's possible to post a picture).. submited to "saveImage.asp"
- saveImage.asp, a page which make the upload, save the pic on the webserver... then, at the end, response.redirect "generateThumb.aspx?imgsrc=image.jpg&gotoURL=displayMess age.asp" for exemple
- generateThumb.aspx, a ASP.Net page, who generate the thumbnail "image_tn.jpg" and save it on the webserver... then, redirect to "displayMessage.asp"
- displayMessage.asp, display a message, for exemple, "Image successfully saved..."
I admit I'm not able to write ASP.Net pages, sorry... 
Thanks for your help !
|
 |
Mart
Senior Member
Joined: 30 November 2002
Status: Offline
Points: 2304
|
Post Options
Thanks(0)
Quote Reply
Posted: 27 November 2003 at 1:47pm |
|
Change the line
objThumbnail.Save(Response.OutputStream, Imaging.ImageFormat.Jpeg)
to
objThumbnail.Save(server.MapPath("test.jpg"), Imaging.ImageFormat.Jpeg)
|
 |
Diep-Vriezer
Senior Member
Joined: 06 August 2003
Location: Netherlands
Status: Offline
Points: 831
|
Post Options
Thanks(0)
Quote Reply
Posted: 27 November 2003 at 3:35pm |
Diam wrote:
But, this page generate a thumbnail and send it to the client... what I would like, if it's possible, it's to write it on the webserver... (I don't want the webserver need to generate the thumbnail everytime someone want view it...)
For exemple...
- Form1.asp (a form where it's possible to post a picture).. submited to "saveImage.asp"
- saveImage.asp, a page which make the upload, save the pic on the webserver... then, at the end, response.redirect "generateThumb.aspx?imgsrc=image.jpg&gotoURL=displayMess age.asp" for exemple
- generateThumb.aspx, a ASP.Net page, who generate the thumbnail "image_tn.jpg" and save it on the webserver... then, redirect to "displayMessage.asp"
- displayMessage.asp, display a message, for exemple, "Image successfully saved..."
I admit I'm not able to write ASP.Net pages, sorry... 
Thanks for your help !
|
Why don't you use .NET for all of this? The pages are all quite simular. You can actually create the images at runtime, but the image url whould have to be set to Image.aspx?Mode=Thumb&ID=838-394. This will generate a thumbnail at the servers cache, and return it to the user. The ID represends the image name, not included the .JPG tag. The mode can be set to anything you'd like.
That's how I would do this thing.
Edited by Diep-Vriezer
|
|
Gone..
|
 |