Visualizzazione dei risultati da 1 a 3 su 3

Discussione: resize img

  1. #1

    resize img

    ciao a tutti,
    non sono un genio nel programmare anche peche non conosco ASP.NET, ma cerco di adattare tutto;
    detto ciò.....uso da parecchio tempo un tool che mi fa il resize delle immagini in una photogallery e mi trovo benissimo...questo tool mi crea un'immagine e mi permette di visualizzarla onfly oppure di salvarla in un path(io ho deciso di salvarla in "/public")

    la mi gallery è formata cosi:
    root
    |-gallery
    ---|
    ---|-anno2010 (foto1.jpg - foto2.jpg -foto3.jpg )
    ---|
    ---|-anno2011 (foto4.jpg - foto5.jpg -foto6.jpg )
    ---|
    ---|-anno2012 (foto7.jpg - foto8.jpg -foto9.jpg )

    e dentro ogni catella ci sono le foto relative all'anno.

    Adesso tutte le foto vengono salvate in un unico path ma mi piacerebbe che al momento del salvataggio venisse creata anche la relativa carella:

    adesso:

    root
    -|-gallery
    -|-public
    ----|preview(miniaturafoto1.jpg - miniaturafoto2.jpg -miniaturafoto3.jpg- miniaturafoto4.jpg - miniaturafoto5.jpg -miniaturafoto6.jpg -miniaturafoto7jpg - miniaturafoto8.jpg -miniaturafoto9.jpg )

    come mi piacerebbe:

    root
    |-gallery
    |-public
    ----|-preview
    ---------|-anno2010 (miniaturafoto1.jpg - miniaturafoto2.jpg -miniaturafoto3.jpg- miniaturafoto4.jpg)
    ---------|-anno2011 (miniaturafoto5.jpg - miniaturafoto6.jpg -miniaturafoto7.jpg- miniaturafoto8.jpg)

    grazie per l'aiuto che mi darete (speriamo!!)


    il tool viene chiamato cosi':
    [/CODE] [img]resizetool.aspx?mode=0&width=50&height=50&path=/"&soggetto&"/"&ShowSub & "/" & ShowPic& "[/img]</a>[/CODE]


    [CODE]<%@ Page Language="VB" %>
    <%@ Import Namespace="System" %>
    <%@ Import Namespace="System.IO" %>
    <%@ Import Namespace="System.Web" %>
    <%@ Import Namespace="System.Drawing" %>

    <script runat="server">
    'Copyright (C) 2007 Daniele Iunco

    'This program is free software; you can redistribute it and/or modify
    'it under the terms of the GNU General Public License as published by
    'the Free Software Foundation; either version 2 of the License, or
    '(at your option) any later version.

    'This program is distributed in the hope that it will be useful,
    'but WITHOUT ANY WARRANTY; without even the implied warranty of
    'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    'GNU General Public License for more details.

    'You should have received a copy of the GNU General Public License along
    'with this program; if not, write to the Free Software Foundation, Inc.,
    '51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

    'resizetool.aspx v1.0
    'Author: Daniele Iunco
    'Date: 9th May 2007

    'Limite massimo per l'altezza in pixel
    Private Const MaxHeightSafe As Integer = 800

    'Limite massimo per la larghezza in pixel
    Private Const MaxWidthSafe As Integer = 800

    'Percorso dell'immagine su cui reindirizzare le richieste non valide
    Private Const ErrorImagePath As String = "/error.jpg"

    'Percorso in cui salvare le copie delle immagini, il percorso indicato deve avere i permessi in scrittura
    Private Const ImageCachePath As String = "/public/"

    'Salva su disco una copia riutilizzabile delle thumbnails create
    Private Const UseCache As Boolean = True

    'Di seguito sono riportati i valori predefiniti che verranno utilizzati quando non vengono specificati parametri
    Private Const DefaultHeight As Integer = 50%
    Private Const DefaultWidth As Integer = 50%
    Private Const DefaultResizeMode As ResizeMode = ResizeMode.AutoResize

    Private Enum ResizeMode
    AutoResize = 0
    ManualResize = 1
    End Enum

    Private ReadOnly Property Mode() As ResizeMode
    Get
    Dim myReqMode As String = Request("mode")
    If myReqMode Is Nothing OrElse Not IsNumeric(myReqMode) Then Return DefaultResizeMode
    If CInt(myReqMode) = 0 Then Return ResizeMode.AutoResize Else Return ResizeMode.ManualResize
    End Get
    End Property

    Private ReadOnly Property MaxHeight() As Integer
    Get
    Dim myValue As String = Request("height")
    If myValue Is Nothing OrElse Not IsNumeric(myValue) Then Return DefaultHeight
    Dim myIntValue As Integer = CInt(myValue)
    If myIntValue < MaxHeightSafe Then
    Return myIntValue
    Else
    Return MaxHeightSafe
    End If
    End Get
    End Property

    Private ReadOnly Property MaxWidth() As Integer
    Get
    Dim myValue As String = Request("width")
    If myValue Is Nothing OrElse Not IsNumeric(myValue) Then Return DefaultWidth
    Dim myIntValue As Integer = CInt(myValue)
    If myIntValue < MaxWidthSafe Then
    Return myIntValue
    Else
    Return MaxWidthSafe
    End If
    End Get
    End Property

    Private _ImagePath As String
    Private ReadOnly Property ImagePath() As String
    Get
    If Not _ImagePath Is Nothing Then Return _ImagePath
    Dim sRequestPath As String = Request.QueryString("path")

    If sRequestPath Is Nothing Then Return Nothing

    'Rimuovo le doppie / e i doppi . con le espressioni regolari
    sRequestPath = Regex.Replace(sRequestPath, "\/{2,}", "/")
    sRequestPath = Regex.Replace(sRequestPath, "\.{2,}", ".")

    If sRequestPath.Substring(0, 1) = "/" Then sRequestPath = sRequestPath.Substring(1)
    _ImagePath = sRequestPath

    Return _ImagePath
    End Get
    End Property

    Sub Page_Load(ByVal Sender As Object, ByVal e As System.EventArgs)
    Dim LocalImageFilePath As String
    Dim LocalThumbnailCacheFilePath As String

    LocalImageFilePath = Server.MapPath("/" & ImagePath)
    If Not File.Exists(LocalImageFilePath) Then
    Response.Redirect(ErrorImagePath)
    Exit Sub
    End If

    Dim TempFilePath As String = Server.MapPath(ImageCachePath)
    LocalThumbnailCacheFilePath = Path.Combine(TempFilePath, ImagePath.Replace("/", "_"))

    Dim mySourceFile As New System.IO.FileInfo(LocalImageFilePath)

    If UseCache Then
    If File.Exists(LocalThumbnailCacheFilePath) Then
    Dim myDestFile As System.IO.FileInfo
    myDestFile = New System.IO.FileInfo(LocalThumbnailCacheFilePath)
    'Se il file della thumbnail è stato modificato dopo il file sorgente
    'allora è valido e uso quello
    If myDestFile.LastWriteTime.CompareTo(mySourceFile.La stWriteTime) = 1 Then
    'Il file esiste e va bene
    Response.ContentType = "image/jpeg"
    Response.WriteFile(myDestFile.FullName)
    Response.End()
    Exit Sub
    Else
    'Il file esiste ma è vecchio e va sostituito
    myDestFile.Delete()
    End If
    End If
    End If

    Dim orginalimg, thumb As System.Drawing.Image

    Try
    orginalimg = System.Drawing.Image.FromFile(mySourceFile.FullNam e)
    Catch
    Response.Redirect(ErrorImagePath)
    Exit Sub
    End Try

    Dim ThumbnailWidth, ThumbnailHeight As Integer
    Select Case Mode
    Case ResizeMode.AutoResize
    ' ResizeMode.AutoResize: Ridimensiona l'immagine per restare nei limiti impostati, mantenendo le proporzioni
    Dim myRatio As Double = orginalimg.Width / orginalimg.Height

    If myRatio > 1 Then 'La larghezza è maggiore dell'altezza, quindi fisso l'altezza e calcolo il resto
    ThumbnailHeight = MaxHeight
    ThumbnailWidth = orginalimg.Width / orginalimg.Height * MaxHeight
    ElseIf myRatio < 1 Then 'L'altezza è maggiore della larghezza, quindi fisso la larghezza e calcolo il resto
    ThumbnailWidth = MaxWidth
    ThumbnailHeight = orginalimg.Height / orginalimg.Width * MaxWidth
    ElseIf myRatio = 1 Then 'Larghezza = Altezza
    ThumbnailWidth = MaxWidth
    ThumbnailHeight = MaxHeight
    End If
    Case ResizeMode.ManualResize
    ' ResizeMode.ManualResize: Ridimensiona con le misure indicate nei parametri
    ThumbnailWidth = MaxWidth
    ThumbnailHeight = MaxHeight
    End Select

    Response.ContentType = "image/jpeg"

    'Creo l'immagine con le misure calcolate, in formato Jpeg
    thumb = orginalimg.GetThumbnailImage(ThumbnailWidth, ThumbnailHeight, Nothing, IntPtr.Zero)

    If UseCache Then
    Dim myS As New IO.FileStream(LocalThumbnailCacheFilePath, IO.FileMode.CreateNew)
    thumb.Save(myS, System.Drawing.Imaging.ImageFormat.Jpeg)
    myS.Close()
    orginalimg.Dispose()
    thumb.Dispose()
    Response.WriteFile(LocalThumbnailCacheFilePath)
    Else
    thumb.Save(Response.OutputStream, Imaging.ImageFormat.Jpeg)
    thumb.Dispose()
    End If
    End Sub
    </script>
    ..: Serie A :..
    ..: FORZA PALERMOOOOoooo.....

  2. #2
    se non metti correttamente il tag "CODE", è difficile leggere e capire cosa fa il codice.

    Detto questo, non ho capito se questo tool agisce nel momento in cui fai un Upload di una immagine, oppure le immagini le carichi tu sul sito da FileSystem o FTP.

  3. #3
    Moderatore di ASP.net L'avatar di djciko
    Registrato dal
    Nov 2002
    Messaggi
    6,887
    Originariamente inviato da Gluck74
    se non metti correttamente il tag "CODE", è difficile leggere e capire cosa fa il codice.
    riapri con il codice --riconoscibile--, grazie

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.