Web Wiz - Green Windows Web Hosting

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

Image resizing

 Post Reply Post Reply
Author
ultramods View Drop Down
Groupie
Groupie
Avatar

Joined: 08 January 2003
Location: Scotland
Status: Offline
Points: 146
Post Options Post Options   Thanks (0) Thanks(0)   Quote ultramods Quote  Post ReplyReply Direct Link To This Post 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()

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: 18 November 2003 at 10:30am
Yes it will work, it uses standard system.drawing namespaces.
Back to Top
ultramods View Drop Down
Groupie
Groupie
Avatar

Joined: 08 January 2003
Location: Scotland
Status: Offline
Points: 146
Post Options Post Options   Thanks (0) Thanks(0)   Quote ultramods Quote  Post ReplyReply Direct Link To This Post Posted: 18 November 2003 at 12:30pm
Ok, thanks for that Mart.
Back to Top
Diam View Drop Down
Newbie
Newbie


Joined: 27 November 2003
Location: Belgium
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote Diam Quote  Post ReplyReply Direct Link To This Post 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 !

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: 27 November 2003 at 9:23am
Use the code posted above!
Back to Top
Diam View Drop Down
Newbie
Newbie


Joined: 27 November 2003
Location: Belgium
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote Diam Quote  Post ReplyReply Direct Link To This Post 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 !

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: 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)
Back to Top
Diep-Vriezer View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 August 2003
Location: Netherlands
Status: Offline
Points: 831
Post Options Post Options   Thanks (0) Thanks(0)   Quote Diep-Vriezer Quote  Post ReplyReply Direct Link To This Post Posted: 27 November 2003 at 3:35pm
Originally posted by Diam 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..
Back to Top
 Post Reply Post Reply

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.