Ti posto il codice della pagina resize.aspx.
Io lavoro prevalentemente con asp classico, quindi non sono molto esperto di .net.
Questa pagina l'ho creata basandomi su script esistenti e adattandoli alle mie necessità, quindi se vedi qualche cosa ottimizzabile dimmi pure.
Codice PHP:
<%@ Import Namespace="System.Drawing"%>
<%@ Import Namespace="System.Drawing.Imaging"%>
<SCRIPT RUNAT="SERVER">
Sub Page_Load()
System.Web.HttpContext.Current.Response.ContentType = "image/JPEG; filename=" & Request("img")
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "inline; filename="&Request("img"))
Dim width as Integer = 0
Dim height as Integer = 0
try
if not Request.QueryString("imgwidth") is Nothing and Request.QueryString("imgwidth")<>"" Then
width = Int32.Parse(Request.QueryString("imgwidth"))
End if
if not Request.QueryString("imgheight") is Nothing and Request.QueryString("imgheight")<>"" Then
height = Int32.Parse(Request.QueryString("imgheight"))
End if
catch ex as Exception
End Try
Dim immagine as String = Server.MapPath(Request("img"))
call ImgRedim(immagine, width, height)
Response.End()
End Sub
Public Sub ImgRedim(immagine as String, width as Integer, height as Integer)
Dim bmp as System.Drawing.Bitmap = CType(System.Drawing.Image.FromFile(immagine), System.Drawing.Bitmap)
dim g as graphics
if width>0 or height>0 then
if height = 0 Then
height = Convert.ToInt32(width / bmp.Width * bmp.Height)
End if
if width = 0 Then
width = Convert.ToInt32(height / bmp.Height * bmp.Width)
End if
Dim miniaturabmp as New System.Drawing.Bitmap(bmp, width, height)
g = graphics.fromimage(miniaturabmp)
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality
g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality
miniaturabmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
miniaturabmp.Dispose()
else
bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
end if
bmp.Dispose()
End Sub
</SCRIPT>