Salve a tutta la community
devo sopperire all'assenza delle utili GDLib in quanto mi trovo a sviluppare su una macchina in hosting windows senza le suddette estensioni abilitate. Purtroppo la mia esperienza in ASP è molto limitata visto che sviluppo prevalentemente in PHP.
L'esigenza è quella di generare "al volo" (lato server) delle miniature di immagini di grandi dimensioni.
Dopo vari tentativi, e grazie ad un'esempio trovato in rete, ho creato uno script che svolge egregiamente il proprio dovere. Il problema è questo: l'immagine ridimensionata ha una qualità pessima !
Come poter implementare una modifica sulla qualità dell'immagine JPG creata ?
Allego il codice del file "make_thumb.aspx"
<% ' import all relevant namespaces %>
<%@ import namespace="System" %>
<%@ import namespace="System.Drawing" %>
<%@ import namespace="System.Drawing.Imaging" %>
<%@ import namespace="System.IO" %>
<script runat="server">
Function NewthumbSize(currentwidth, currentheight)
dim tempMultiplier as Double
tempMultiplier = request("width") / currentwidth
dim NewSize as New Size(CInt(currentwidth * tempMultiplier), CInt(currentheight * tempMultiplier))
return NewSize
End Function
Sub sendFile()
dim g as System.Drawing.Image = System.Drawing.Image.FromFile(server.mappath(request.Querystring("src")))
dim thisFormat=g.rawformat
dim thumbSize as New size
thumbSize=NewthumbSize(g.width,g.height)
dim imgOutput as New Bitmap(g, thumbSize.width, thumbSize.height)
if thisformat.equals(system.drawing.imaging.imageformat.Gif) then
response.contenttype="image/gif"
else
response.contenttype="image/jpeg"
end if
imgOutput.save(response.outputstream, thisformat)
g.dispose()
imgOutput.dispose()
end sub
Sub sendError()
dim imgOutput as New bitmap(1, 1, pixelformat.format24bpprgb)
dim g as graphics = graphics.fromimage(imgOutput)
g.clear(color.white)
response.contenttype="image/gif"
imgOutput.save(response.outputstream, imageformat.gif)
g.dispose()
imgOutput.dispose()
end sub
</script>
<%
response.clear
if request("src")="" then
call sendError()
else
if file.exists(server.mappath(request("src"))) then
call sendFile()
else
call sendError()
end if
end if
response.end
%>
Per avere l'immagine ridimensionata faccio una chiamata al file "make_thumb.aspx" passando come parametri "src" che contiene il path all'immagine da ridimensionare e "width" che contiene la nuova larghezza dell'immagine da generare.
Es: <img src='http://www.mioserver.com/make_thumb.aspx?
src=miopercorso/miaimmagine.jpg&
width=120'>
Spero di aver postato nella sezione adatta.
Ringrazio anticipatamente per la collaborazione.
Enrico Calabretta
Modificato da EnryCorser il 10 settembre 2006 18.39 -