xStrongTowerx
Programmer
Dear Forum,
I'm trying to adapt a script I found on 4guysfromrolla.com, but I'm having some trouble. I've tried posting on their own messageboard, but to no avail, so I thought I'd post the question here.
I must confess I'm brand new at ASP.NET, although I've been programming classic ASP for 4 years.
I'm trying to do image resizing as shown in
I've modified the script to use the <img src="ShowImage.aspx?img=RT+Angle.jpg&h=100&w=100"> tag to call ShowImage.aspx, and altered ShowImage.aspx to do a proportional resize as follows:
<%@Import Namespace="System.Drawing.Imaging" %>
<script language="VB" runat="server">
Function ThumbnailCallback() as Boolean
Return False
End Function
Sub Page_Load(sender as Object, e as EventArgs)
'Read in the image filename to create a thumbnail of
Dim imageUrl as String = Request.QueryString("img"
'Read in the width and height
Dim maxHeight as Integer = Request.QueryString("h"
Dim maxWidth as Integer = Request.QueryString("w"
'Make sure that the image URL doesn't contain any /'s or \'s
If imageUrl.IndexOf("/" >= 0 Or imageUrl.IndexOf("\" >= 0 then
'We found a / or \
Response.End()
End If
'Add on the appropriate directory
imageUrl = "/images/" & imageUrl
Dim fullSizeImg as System.Drawing.Image
fullSizeImg = System.Drawing.Image.FromFile(Server.MapPath(imageUrl))
imgHeight = fullSizeImg.Height
imgWidth = fullSizeImg.Width
If imgWidth > maxWidth OR imgHeight > maxHeight then
'Determine what dimension is off by more
Dim deltaWidth as Integer = imgWidth - maxWidth
Dim deltaHeight as Integer = imgHeight - maxHeight
Dim scaleFactor as Double
If deltaHeight > deltaWidth then
'Scale by the height
scaleFactor = maxHeight / imgHeight
Else
'Scale by the Width
scaleFactor = maxWidth / imgWidth
End If
imgWidth *= scaleFactor
imgHeight *= scaleFactor
End If
'Do we need to create a thumbnail?
Response.ContentType = "image/gif"
If imageHeight > 0 and imageWidth > 0 then
Dim dummyCallBack as System.Drawing.Image.GetThumbNailImageAbort
dummyCallBack = New _
System.Drawing.Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback)
Dim thumbNailImg as System.Drawing.Image
thumbNailImg = fullSizeImg.GetThumbnailImage(imageWidth, imageHeight, _
dummyCallBack, IntPtr.Zero)
thumbNailImg.Save(Response.OutputStream, ImageFormat.Gif)
Else
fullSizeImg.Save(Response.OutputStream, ImageFormat.Gif)
End If
End Sub
</script>
Now my problem is that whenever I try to call the script, the browser asks me to enter a username and password. I've tried my ftp user/pass for the Windows 2000 server, but it didn't work. It says I don't have permissions.
What can this mean? Does it mean that I don't have permission to access the System.Drawing.Imaging namespace, or does it mean that I'm screwing up the paths somehow to point to a directory outside my domain?
Thanks for your assistance,
xSTx
I'm trying to adapt a script I found on 4guysfromrolla.com, but I'm having some trouble. I've tried posting on their own messageboard, but to no avail, so I thought I'd post the question here.
I must confess I'm brand new at ASP.NET, although I've been programming classic ASP for 4 years.
I'm trying to do image resizing as shown in
I've modified the script to use the <img src="ShowImage.aspx?img=RT+Angle.jpg&h=100&w=100"> tag to call ShowImage.aspx, and altered ShowImage.aspx to do a proportional resize as follows:
<%@Import Namespace="System.Drawing.Imaging" %>
<script language="VB" runat="server">
Function ThumbnailCallback() as Boolean
Return False
End Function
Sub Page_Load(sender as Object, e as EventArgs)
'Read in the image filename to create a thumbnail of
Dim imageUrl as String = Request.QueryString("img"
'Read in the width and height
Dim maxHeight as Integer = Request.QueryString("h"
Dim maxWidth as Integer = Request.QueryString("w"
'Make sure that the image URL doesn't contain any /'s or \'s
If imageUrl.IndexOf("/" >= 0 Or imageUrl.IndexOf("\" >= 0 then
'We found a / or \
Response.End()
End If
'Add on the appropriate directory
imageUrl = "/images/" & imageUrl
Dim fullSizeImg as System.Drawing.Image
fullSizeImg = System.Drawing.Image.FromFile(Server.MapPath(imageUrl))
imgHeight = fullSizeImg.Height
imgWidth = fullSizeImg.Width
If imgWidth > maxWidth OR imgHeight > maxHeight then
'Determine what dimension is off by more
Dim deltaWidth as Integer = imgWidth - maxWidth
Dim deltaHeight as Integer = imgHeight - maxHeight
Dim scaleFactor as Double
If deltaHeight > deltaWidth then
'Scale by the height
scaleFactor = maxHeight / imgHeight
Else
'Scale by the Width
scaleFactor = maxWidth / imgWidth
End If
imgWidth *= scaleFactor
imgHeight *= scaleFactor
End If
'Do we need to create a thumbnail?
Response.ContentType = "image/gif"
If imageHeight > 0 and imageWidth > 0 then
Dim dummyCallBack as System.Drawing.Image.GetThumbNailImageAbort
dummyCallBack = New _
System.Drawing.Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback)
Dim thumbNailImg as System.Drawing.Image
thumbNailImg = fullSizeImg.GetThumbnailImage(imageWidth, imageHeight, _
dummyCallBack, IntPtr.Zero)
thumbNailImg.Save(Response.OutputStream, ImageFormat.Gif)
Else
fullSizeImg.Save(Response.OutputStream, ImageFormat.Gif)
End If
End Sub
</script>
Now my problem is that whenever I try to call the script, the browser asks me to enter a username and password. I've tried my ftp user/pass for the Windows 2000 server, but it didn't work. It says I don't have permissions.
What can this mean? Does it mean that I don't have permission to access the System.Drawing.Imaging namespace, or does it mean that I'm screwing up the paths somehow to point to a directory outside my domain?
Thanks for your assistance,
xSTx