Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 12

Discussione: Compressione Foto

  1. #1

    Compressione Foto

    Ciao a tutti...

    volevo sapere se è possibile comprimere una foto non quando viene caricata ma quano viene visualizzata a video...

    io così stampo la foto a video...
    codice:
    [img]<%=(lista_foto.Fields.Item([/img]" height="100" />
    ma come posso fare per evitare che la foto sia + grande di 100 px in altezza o 100px in larghezza?

    cioè, la foto non deve essere più grande di 100x100... il lato più lungo deve essere al massimo 100px...

    è una cosa reale?

    grazie a tutti per l'attenzione.. ciao

  2. #2

  3. #3

  4. #4
    Vai qui e guarda il codice per recupere le dimensioni delle immagini (che devono essere sul tuo server).

    Poi quando recuperi le dimensioni del'immagine, che dovrai chiamare ImgHeight e ImgWidth, applica questo codice che ti restituisce le nuove dimensioni da dare alle immagini.

    codice:
    <%
    if ImgHeight>100 or ImgWidth>100 then			    
    	if ImgHeight>ImgWidth then
    		'calcolo proporzione di riduzione
    		Prop=100*100/ImgHeight
    		'Nuovo valore max di ImgHeight
    		ImgHeight=100
    		'Nuovo valore max di ImgWidth
    		ImgWidth=Cint(ImgWidth*Prop/100)
    	end if
    	if ImgWidth>ImgHeight then
    		'calcolo proporzione di riduzione
    		Prop=100*100/ImgWidth
    		'Nuovo valore max di ImgHeight
    		ImgWidth=100
    		'Nuovo valore max di ImgWidth
    		ImgHeight=Cint(ImgHeight*Prop/100)
    	end if
    end if
    %>
    
    [img]indirizzoimmagine.jpg[/img]" height="<%=ImgHeight%>" alt="immagine">

    ciao

  5. #5
    ti ringrazio per la puntuale risposta... ma non riesco a capire come far funzionare la cosa...

    ti ringrazio per la pazienza

  6. #6
    fatti una copia del file che stai andando a modificare

    scrica la classe trovi lo zip nell'indirizzo che ho postato prima e copiala in una cartella, che chiamerai classi, sotto il tuo sito.

    Nella pagina dove ti serve includi il file della classe


    a questo punto se hai un ciclo per la gestione delle immagini fai cosi

    codice:
    'creo l'istanza della classe
    set objImageSize= new ImageSize
    do while not lista_foto.EOF
    
      With objImageSize
            nomeFile=lista_foto.Fields.Item("SourceFileName").Value
    	.ImageFile = Server.MapPath(PathSmall & nomeFile)
    	 'Controllo se il file è una immagine		  
    	 If .IsImage Then
    			  
    	    ImgWidth  = .ImageWidth 
    	    ImgHeight = .ImageHeight
    
                if ImgHeight>100 or ImgWidth>100 then			    
        	      if ImgHeight>ImgWidth then
    		'calcolo proporzione di riduzione
    		Prop=100*100/ImgHeight
    		'Nuovo valore max di ImgHeight
    		ImgHeight=100
    		'Nuovo valore max di ImgWidth
    		ImgWidth=Cint(ImgWidth*Prop/100)
    	       end if
    	       if ImgWidth>ImgHeight then
    		 'calcolo proporzione di riduzione
    		 Prop=100*100/ImgWidth
    		 'Nuovo valore max di ImgHeight
    		 ImgWidth=100
    		 'Nuovo valore max di ImgWidth
    		 ImgHeight=Cint(ImgHeight*Prop/100)
    	      end if
              end if
            %>
             [img]<%=nomeFile%>[/img]" height="<%=ImgHeight%>" alt="immagine">
    
            <%
    
    	 end if		    
    		
      End With
      lista_foto.movenext
    loop
    'distruggo l'istanza della classe
    set objImageSize= nothing

  7. #7
    ora ho questo codice:

    codice:
    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    
    <%
    Dim lista_foto
    Dim lista_foto_numRows
    
    Set lista_foto = Server.CreateObject("ADODB.Recordset")
    lista_foto.ActiveConnection = MM_connessione_foto_STRING
    lista_foto.Source = "SELECT * FROM ListFiles"
    lista_foto.CursorType = 0
    lista_foto.CursorLocation = 2
    lista_foto.LockType = 1
    lista_foto.Open()
    
    lista_foto_numRows = 0
    %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Documento senza titolo</title>
    </head>
    
    <body>
    <%
    'creo l'istanza della classe
    set objImageSize= new ImageSize
    do while not lista_foto.EOF
    
      With objImageSize
            nomeFile=lista_foto.Fields.Item("SourceFileName").Value
    	.ImageFile = Server.MapPath(PathSmall & nomeFile)
    	 'Controllo se il file è una immagine		  
    	 If .IsImage Then
    			  
    	    ImgWidth  = .ImageWidth 
    	    ImgHeight = .ImageHeight
    
                if ImgHeight>100 or ImgWidth>100 then			    
        	      if ImgHeight>ImgWidth then
    		'calcolo proporzione di riduzione
    		Prop=100*100/ImgHeight
    		'Nuovo valore max di ImgHeight
    		ImgHeight=100
    		'Nuovo valore max di ImgWidth
    		ImgWidth=Cint(ImgWidth*Prop/100)
    	       end if
    	       if ImgWidth>ImgHeight then
    		 'calcolo proporzione di riduzione
    		 Prop=100*100/ImgWidth
    		 'Nuovo valore max di ImgHeight
    		 ImgWidth=100
    		 'Nuovo valore max di ImgWidth
    		 ImgHeight=Cint(ImgHeight*Prop/100)
    	      end if
              end if
            %>
             [img]<%=nomeFile%>[/img]" height="<%=ImgHeight%>" alt="immagine">
             <%
    
    	 end if		    
    		
      End With
      lista_foto.movenext
    loop
    'distruggo l'istanza della classe
    set objImageSize= nothing
    %>
    </body>
    </html>
    <%
    lista_foto.Close()
    Set lista_foto = Nothing
    %>
    il file incluso è:

    codice:
    <%
    '******************************************************************
    ' Classe ImageSize
    ' Data una immagine restituisce le dimensioni X,Y e numero di
    ' colori
    '
    ' ImageFile = path fisico completo dell'immagine
    ' ImageName = restituisce il nome del file
    ' ImageType = restituisce il tipo di immagine
    ' ImageWidth = restituisce la larghezza in pixel dell'immagine
    ' ImageHeight = restituisce l'altezza in pixel dell'immagine
    ' ImageDepth = restituisce il numero di colori dell'immagine
    ' IsImage = restituisce TRUE se il file è una immagine
    '
    ' Author:
    ' 2002 Luciani Massimiliano
    ' http://www.byluciani.com
    ' webmaster@byluciani.com
    '
    ' Original code:
    ' http://www.4guysfromrolla.com/webtech/011201-1.shtml
    ' Author: Mike Shaffer - mshaffer@nkn.net
    '
    ' This script is FREEWARE
    '******************************************************************
    
    Class ImageSize
    
    Public Dimensioni(2)
    Public bolIsImage, strPathFile, strImageType
    
    Private Sub Class_Initialize()
    
    End Sub
    
    Private Sub Class_Terminate()
    
    End Sub
    
    Public Property Get ImageName
    ImageName = doName(ImageFile)
    End Property
    
    Public Property Get ImageFile
    ImageFile = strPathFile
    End Property
    
    Public Property Let ImageFile(strImageFile)
    strPathFile = strImageFile
    gfxSpex(strPathFile)
    End Property
    
    Public Property Get ImageWidth
    ImageWidth = Dimensioni(1)
    End Property
    
    Public Property Get ImageHeight
    ImageHeight = Dimensioni(0)
    End Property
    
    Public Property Get ImageDepth
    ImageDepth = Dimensioni(2)
    End Property 
    
    Public Property Get ImageType
    ImageType = strImageType
    End Property 
    
    Public Property Get IsImage
    IsImage = bolIsImage
    End Property 
    
    Public Function GetBytes(flnm, offset, bytes)
    Dim objFSO
    Dim objFTemp
    Dim objTextStream
    Dim lngSize
    
    on error resume next
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    ' First, we get the filesize
    Set objFTemp = objFSO.GetFile(flnm)
    lngSize = objFTemp.Size
    set objFTemp = nothing
    
    fsoForReading = 1
    Set objTextStream = objFSO.OpenTextFile(flnm, fsoForReading)
    
    if offset > 0 then
    strBuff = objTextStream.Read(offset - 1)
    end if
    
    if bytes = -1 then ' Get All!
    GetBytes = objTextStream.Read(lngSize) 'ReadAll
    else
    GetBytes = objTextStream.Read(bytes)
    end if
    
    objTextStream.Close
    set objTextStream = nothing
    set objFSO = nothing
    end function
    
    Public function lngConvert(strTemp)
    lngConvert=clng(asc(left(strTemp,1))+((asc(right(strTemp,1))*256)))
    end function
    
    Public function lngConvert2(strTemp)
    lngConvert2=clng(asc(right(strTemp,1))+((asc(left(strTemp,1))*256)))
    end function
    
    Public Sub gfxSpex(flnm)
    
    dim strPNG 
    dim strGIF
    dim strBMP
    dim strType
    strType = ""
    strImageType = "(unknown)"
    
    bolIsImage = False
    
    strPNG = chr(137) & chr(80) & chr(78)
    strGIF = "GIF"
    strBMP = chr(66) & chr(77)
    
    strType = GetBytes(flnm, 0, 3)
    
    if strType = strGIF then ' is GIF
    
    strImageType = "GIF"
    lngWidth = lngConvert(GetBytes(flnm, 7, 2))
    lngHeight = lngConvert(GetBytes(flnm, 9, 2))
    lngDepth = 2 ^ ((asc(GetBytes(flnm, 11, 1)) and 7) + 1)
    bolIsImage = True
    
    elseif left(strType, 2) = strBMP then ' is BMP
    
    strImageType = "BMP"
    lngWidth = lngConvert(GetBytes(flnm, 19, 2))
    lngHeight = lngConvert(GetBytes(flnm, 23, 2))
    lngDepth = 2 ^ (asc(GetBytes(flnm, 29, 1)))
    bolIsImage = True
    
    elseif strType = strPNG then ' Is PNG
    
    strImageType = "PNG"
    lngWidth = lngConvert2(GetBytes(flnm, 19, 2))
    lngHeight = lngConvert2(GetBytes(flnm, 23, 2))
    lngDepth = getBytes(flnm, 25, 2)
    
    select case asc(right(lngDepth,1))
    case 0
    lngDepth = 2 ^ (asc(left(lngDepth, 1)))
    bolIsImage = True
    case 2
    lngDepth = 2 ^ (asc(left(lngDepth, 1)) * 3)
    bolIsImage = True
    case 3
    lngDepth = 2 ^ (asc(left(lngDepth, 1))) '8
    bolIsImage = True
    case 4
    lngDepth = 2 ^ (asc(left(lngDepth, 1)) * 2)
    bolIsImage = True
    case 6
    lngDepth = 2 ^ (asc(left(lngDepth, 1)) * 4)
    bolIsImage = True
    case else
    lngDepth = -1
    end select
    
    else
    
    strBuff = GetBytes(flnm, 0, -1) ' Get all bytes from file
    lngSize = len(strBuff)
    flgFound = 0
    
    strTarget = chr(255) & chr(216) & chr(255)
    flgFound = instr(strBuff, strTarget)
    
    if flgFound = 0 then exit sub
    end if
    
    strImageType = "JPG"
    lngPos = flgFound + 2
    ExitLoop = false
    
    do while ExitLoop = False and lngPos < lngSize
    
    do while asc(mid(strBuff,lngPos,1))=255 and lngPos<lngSize
    lngPos = lngPos + 1
    loop
    
    if asc(mid(strBuff,lngPos,1))<192 or asc(mid(strBuff,lngPos,1))>195 then
    lngMarkerSize = lngConvert2(mid(strBuff, lngPos + 1, 2))
    lngPos = lngPos + lngMarkerSize + 1
    else
    ExitLoop = True
    end if
    
    loop
    
    if ExitLoop = False then
    
    lngWidth = -1
    lngHeight = -1
    lngDepth = -1
    
    else
    
    lngHeight = lngConvert2(mid(strBuff, lngPos + 4, 2))
    lngWidth = lngConvert2(mid(strBuff, lngPos + 6, 2))
    lngDepth = 2 ^ (asc(mid(strBuff, lngPos + 8, 1)) * 8)
    bolIsImage = True
    
    end if
    
    Dimensioni(0) = lngHeight
    Dimensioni(1) = lngWidth
    Dimensioni(2) = lngDepth
    end Sub 
    
    Public Function doName(strPath)
    Dim arrSplit
    arrSplit = Split(strPath, "\")
    doName = arrSplit(UBound(arrSplit))
    End Function
    
    End Class
    %>
    come faccio per settare la cartella nella quale trovare le immagini.. così comè le immagini devono essere sullo stesso livello dello script...

    ti ringrazio pr la collaborazione

  8. #8
    cosa ti restituisce l'istruzione
    nomeFile=lista_foto.Fields.Item("SourceFileName"). Value

  9. #9
    il nome della foto...

    ad esempio... foto.jpg

  10. #10
    senza percorso?

    non puoi aggiungere te il percorso?

    Cosa vuoi ottenere? una galleria di immagini?

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 © 2026 vBulletin Solutions, Inc. All rights reserved.