Resizing Images on the fly from another server

Last post 05-28-2006 12:18 PM by geedubb. 2 replies.

Sort Posts:

  • Resizing Images on the fly from another server

    05-22-2006, 12:48 PM
    • Participant
      1,446 point Participant
    • gp_330
    • Member since 05-07-2003, 6:31 AM
    • Posts 301
    Hi guys,  I have a resizing page that I use to resize all of the images on my local server.  However now, I want to be able to read files from another website using the full URL, and resize them on the fly.  However the code that I have only works with local files.  I was wondering if anyone could point me in the right direction with this issue.  I am sure that I have use the Stream Reader in some way, I just can't figure it out.  Any help would be really appreciated!

    Thanks

    <code>
    Sub Page_load(ByVal sender As Object, ByVal e As EventArgs)
                Try
                    Dim objImage, objThumbnail As System.Drawing.Image
                    Dim strServerPath, strFilename As String
                    Dim shtWidth, shtHeight As Short
                    strServerPath = Server.MapPath("")
                    strFilename = httpcontext.current.Request.QueryString("filename")
                   
                    Try                   
                        objImage = objImage.FromFile(Server.MapPath(strFileName))
                    Catch
                        objImage = objImage.FromFile(StrServerPath &"\"&"images\noimage.jpg")
                    End Try
                   
                    If Request.QueryString("width") = Nothing Then
                        shtWidth = objImage.Width
                    ElseIf Request.QueryString("width") < 1 Then
                        shtWidth = 100
                    Else
                        shtWidth = Request.QueryString("width")
                    End If
                   
                    shtHeight = objImage.Height / (objImage.Width / shtWidth)
                    objThumbnail = objImage.GetThumbnailImage(shtWidth, shtHeight, Nothing, System.IntPtr.Zero)
                   
                    Response.ContentType = "image/jpeg"
                    objThumbnail.Save(Response.OutputStream, Imaging.ImageFormat.Jpeg)
                    objImage.Dispose()
                    objThumbnail.Dispose()
                   
                Catch ex as exception
               
                    response.write(ex.tostring &"<br/>")
               
                End try
                end sub
    </code>
  • Re: Resizing Images on the fly from another server

    05-28-2006, 12:14 PM
    • Member
      202 point Member
    • geedubb
    • Member since 05-28-2004, 5:00 AM
    • Edinburgh, Scotland
    • Posts 44
    I'm not sure that you can pass a URI into the constructor for Image.FromFile(). You might want to try using a WebRequest object, then creating a streamreader from that and passing it into the Image constructor. Also have you tried removing the try...catch blocks from your code? You may be swallowing a useful exception here.

    HTH
  • Re: Resizing Images on the fly from another server

    05-28-2006, 12:18 PM
    Answer
    • Member
      202 point Member
    • geedubb
    • Member since 05-28-2004, 5:00 AM
    • Edinburgh, Scotland
    • Posts 44
    Just found this:

    http://forums.asp.net/thread/1280870.aspx

    Look at the second answer - he gives you some c# code for using the webrequest method. I'm sure it's easily converted to VB
Page 1 of 1 (3 items)