ciao a tutti

ho sempre uploadato immagini sul server senza modificare la dimensione delle stesse, ora però mi trovo nella necessità, per motivi di spazio, di imporre un resize subito dopo l'upload.

non sono ferrato in .NET e per l'upload utilizzo uno script, ormai rodato, in ASP.

per quanto riguarda il resize ho dovuto ripiegare su .NET; nel forum ho trovato questo codice che funziona molto bene

il mio problema è che non so come fare un redirect che da img.aspx, una volta ridimensionata l'immagine, mi indirizzi su "index.html"

potete aiutarmi?

grazie mille


file img.aspx

Codice PHP:
<%@ Page Language="C#" Debug="true" %> 

<%@ 
import Namespace="System"%> 
<%@ 
import Namespace="System.IO"%> 
<%@ 
import Namespace="System.Drawing" %> 
<%@ 
import Namespace="System.Drawing.Imaging" %> 
<%@ 
import Namespace="System.Text.RegularExpressions" %> 


<
script Language="C#" runat="server"
void Page_Load(Object senderEventArgs e

int ThumbnailWidth 64
int ThumbnailHeight 64
string strFileName ""
string destinazione Server.MapPath("./public/"); 

double orgImgWidth 0.0
double orgImgHeight 0.0
double rThumbnailWidth 0.0
double rThumbnailHeight 0.0

if (
Request.QueryString.Count != 0
  { 
   if (
Request.QueryString["w"] != nullThumbnailWidth Convert.ToInt32(Request.QueryString["w"]); 
   if (
Request.QueryString["h"] != nullThumbnailHeight Convert.ToInt32(Request.QueryString["h"]); 

   if (
Request.QueryString["src"] != null
    { 
     
strFileName Convert.ToString(Request.QueryString["src"]); 

     if (
strFileName != ""
      { 
       try 
        { 
         
using(System.Drawing.Image tmpImage System.Drawing.Image.FromFile(Server.MapPath(strFileName))) 
          { 
           
rThumbnailWidth ThumbnailWidth
           
rThumbnailHeight ThumbnailHeight
           
orgImgWidth tmpImage.Width
           
orgImgHeight tmpImage.Height
            
           
// Se l'immagine è più piccola del Thumbnail forziamo le dimensioni di 
           // quest'ultimo alle dimensioni dell'immagine. 
           
if (orgImgWidth ThumbnailWidthThumbnailWidth tmpImage.Width
           if (
orgImgHeight ThumbnailHeightThumbnailHeight tmpImage.Height
            
           
// Se le dimensioni dell'immagine e del Thumbnail corrispondono non facciamo nulla. 
           // quindi se l'immagine è quadrata... 
            
           
if (tmpImage.Width != tmpImage.Height
            { 
             
// Se l'immagine non è quadrata 
             // continuiamo a fare i nostri controlli per calcolarne le 
             // giuste dimensioni e quindi creare la nostra nuova immagine con 
             // l'aspectratio corretto. 
             // Se l'immagine è più larga che alta 
             
if (tmpImage.Width tmpImage.Height
              { 
               
// L > H => L = tL 
               // La larghezza del TN sarà quella da noi stabilita 
               // quindi dobbiamo solo assegnarla. 
               
rThumbnailWidth ThumbnailWidth
               
// L'altezza del TN invece dovrà essere ricalcolata 
               // in proporzione alla larghezza dell'immagine originale. 
               // L > H => tH = (H * tL)/ L 
               
rThumbnailHeight = (double)((tmpImage.Height ThumbnailWidth) / tmpImage.Width); 
              } 
// if (tmpImage.Width > tmpImage.Height) 
             
else 
              { 
               
// Altrimenti se l'immagine è più alta 
               
if (tmpImage.Width tmpImage.Height
                { 
                 
// L < H => H = tH 
                 // L'altezza del TN sarà quella da noi stabilita 
                 // quindi dobbiamo solo assegnarla. 
                 
rThumbnailHeight ThumbnailHeight
                 
// La larghezza del TN invece dovrà essere ricalcolata 
                 // in proporzione alla altezza dell'immagine originale. 
                 // L < H => tL = (L * tH)/ H 
                 
rThumbnailWidth = (double)((tmpImage.Width ThumbnailHeight) / tmpImage.Height); 
                } 
// if (tmpImage.Width < tmpImage.Height) 
              
// else 
            
// if (tmpImage.Width != tmpImage.Height) 
           
using(Bitmap bitmap = new Bitmap(tmpImage, (int)(rThumbnailWidth), (int)(rThumbnailHeight))) 
            { 
             
Response.ContentType tmpImage.RawFormat.ToString(); 
             
Response.Clear(); 
             
Response.BufferOutput true
             
Response.AddHeader("Content-Disposition""filename=" strFileName); 
             
             
// In questo caso viene creata e salvata la Thumbnail dell'immagine in /thumbs/ 
             
if ((tmpImage.Width ThumbnailWidth) || (tmpImage.Height ThumbnailHeight)) 
              { 
               
bitmap.Save(Response.OutputStreamtmpImage.RawFormat); 
               
bitmap.Save((destinazione strFileName), tmpImage.RawFormat); 
              } 
// if ((tmpImage.Width > ThumbnailWidth) || (tmpImage.Height > ThumbnailHeight)) 
             
else // L'immagine rientra già nella dimensione da noi decisa quindi non serve creargli il Thumbnail. 
              

               
bitmap.Save(Response.OutputStreamtmpImage.RawFormat); 
//               Se vuoi che l'immagine venga comunque salvata nella cartella dei Thumbnails leva "//" dalla riga sottostante. 
               
bitmap.Save(destinazione strFileNametmpImage.RawFormat); 
              } 
// else 
             
Response.Flush(); 
            } 
// using(Bitmap bitmap = new Bitmap(orgImage, (int)(rThumbnailWidth), (int)(rThumbnailHeight))) 
          
// using(System.Drawing.Image tmpImage = System.Drawing.Image.FromFile(Server.MapPath(strFileName))) 
        
// try 
       
catch (Exception ex
        { 
         
Response.Write(ex.Message); 
        } 
// catch (Exception ex) 
       
finally 
        { 
         
Response.Write("\nCoded by R.B. Riddick"); 
        } 
      } 
// if (strFileName != "") 
    
// if (Request.QueryString["src"] != "") 
  
// if (Request.QueryString.Count != 0) 
// void Page_Load(Object sender, EventArgs e) 
</script>