Originariamente inviato da spirit6
Quello che intendevo è che non riesco a creare le TN in una cartella sul server, per cui anche senza commentare quella riga mi vanno sempre On the fly :master:
Effettivamente senza TN la pagina è un po' troppo lenta, quindi sarei interessato a risolvere questo problemino.
Ecco nel dettaglio:
*Sono su un server aruba a base windows.
*Sto provando lo script sul percorso dominio.it/prova/
*L'unica cartella con i permessi di scrittura è dominio.it/public/
Ho provato senza successo a cambiare:
codice:
bitmap.Save(destinazione + "/public/" + strFileName, orgImage.RawFormat);
con:
codice:
bitmap.Save(destinazione + "/../public/" + strFileName, orgImage.RawFormat);
bitmap.Save(destinazione + "../public/" + strFileName, orgImage.RawFormat);
bitmap.Save("/public/" + strFileName, orgImage.RawFormat);
bitmap.Save("public/" + strFileName, orgImage.RawFormat);
Ma non riesco proprio. Mi dai una mano a trovare il percorso giusto? Grazie!
Prova con questo...
codice:
<%@ 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 sender, EventArgs 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;
System.Drawing.Image orgImage;
if (Request.QueryString["w"] != "") ThumbnailWidth = Convert.ToInt32(Request.QueryString["w"]);
if (Request.QueryString["h"] != "") ThumbnailHeight = Convert.ToInt32(Request.QueryString["h"]);
if (Request.QueryString["src"] != "")
{
strFileName = Convert.ToString(Request.QueryString["src"]);
if (strFileName != "")
{
try
{
orgImage = System.Drawing.Image.FromFile(Server.MapPath(strFileName));
using(Bitmap tmpImage = new Bitmap(orgImage))
{
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 < ThumbnailWidth) ThumbnailWidth = tmpImage.Width;
if (orgImgHeight < ThumbnailHeight) ThumbnailHeight = tmpImage.Height;
// Se le dimensioni dell'immagine e del Thumbnail corrispondono non facciamo nulla.
if (tmpImage.Width != tmpImage.Height)
{
// Altrimenti continuiamo a fare i nostri controlli per calcolarne le
// giuste dimensioni e quindi creare la nostra nuova immagine con
// l'aspectratio corretto.
if (tmpImage.Width > tmpImage.Height)
{
// L > H => tH = (H * tL)/ L
rThumbnailWidth = ThumbnailWidth;
rThumbnailHeight = (double)((tmpImage.Height * ThumbnailWidth) / tmpImage.Width);
} // if (tmpImage.Width > tmpImage.Height)
else
{
if (tmpImage.Width < tmpImage.Height)
{
// L < H => tL = (L * tH)/ H
rThumbnailHeight = ThumbnailWidth;
rThumbnailWidth = (double)((tmpImage.Width * ThumbnailHeight) / tmpImage.Height);
} // if (tmpImage.Width < tmpImage.Height)
} // else
} // if (tmpImage.Width != tmpImage.Height)
} // using(Bitmap tmpImage = new Bitmap(orgImage))
using(Bitmap bitmap = new Bitmap(orgImage, (int)(rThumbnailWidth), (int)(rThumbnailHeight)))
{
Response.ContentType = orgImage.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 ((orgImage.Width > ThumbnailWidth) || (orgImage.Height > ThumbnailHeight))
{
bitmap.Save(Response.OutputStream, orgImage.RawFormat);
bitmap.Save((destinazione + strFileName), orgImage.RawFormat);
} // if ((orgImage.Width > ThumbnailWidth) || (orgImage.Height > ThumbnailHeight))
else // L'immagine rientra già nella dimensione da noi decisa quindi non serve creargli il Thumbnail.
{
bitmap.Save(Response.OutputStream, orgImage.RawFormat);
// Se vuoi che l'immagine venga comunque salvata nella cartella dei Thumbnails leva "//" dalla riga sottostante.
// bitmap.Save(destinazione + strFileName, orgImage.RawFormat);
} // else
Response.Flush();
} // using(Bitmap bitmap = new Bitmap(orgImage, (int)(rThumbnailWidth), (int)(rThumbnailHeight)))
} // try
catch (Exception ex)
{
Response.Write(ex.Message);
} // catch (Exception ex)
finally
{
Response.Write("\nRe-Coded by R.B. Riddick");
}
} // if (strFileName != "")
} // if (Request.QueryString["src"] != "")
}
</script>
Fammi sapere...