Foros del Web » Programando para Internet » ASP Clásico »

Cómo saber alto y ancho de un fichero gráfico (gif o jpeg) en ASP

Estas en el tema de Cómo saber alto y ancho de un fichero gráfico (gif o jpeg) en ASP en el foro de ASP Clásico en Foros del Web. Saludos de nuevo: A ver tengo una duda existencial y quiero hacerlo en ASP Lo que quiero conseguir es subir un fichero gráfico a un ...
  #1 (permalink)  
Antiguo 23/07/2004, 09:27
 
Fecha de Ingreso: junio-2003
Ubicación: Santiago de Compostela
Mensajes: 603
Antigüedad: 21 años, 10 meses
Puntos: 0
Cómo saber alto y ancho de un fichero gráfico (gif o jpeg) en ASP

Saludos de nuevo:
A ver tengo una duda existencial y quiero hacerlo en ASP
Lo que quiero conseguir es subir un fichero gráfico a un ftp desde un formulario (para lo que no hay ningun problema) y que al mismo tiempo que se sube el fichero al ftp me cubra automáticamente los campos nombre, alto y ancho del fichero en ese mismo formulario. Obviamente todos esos datos pasarán a ingresarse en una DB.
Pero no encuentro ninguna forma de que me proporcione el alto y el ancho de la foto.
Por si no me entienden es lo mismo que cuando en dreamweaver se inserta un fichero gráfico, automaticamente en las propiedades ya aparecen reflejadas las medidas del fichero.
Gracias.

Última edición por ciberpata; 23/07/2004 a las 12:06
  #2 (permalink)  
Antiguo 23/07/2004, 11:39
Avatar de Phoncadiz  
Fecha de Ingreso: mayo-2004
Ubicación: Cádiz City
Mensajes: 232
Antigüedad: 20 años, 11 meses
Puntos: 1
Lo puedes hacer mediantes un script.

Echa un vistazo a este enlace:

http://www.javascripts.astalaweb.com...e%20imagen.htm

Saludos!!!
__________________
Tantas horas delante de una pantalla servirá para algo....
[Phoncadiz; mínimo 8 h. al día con el PC] :stress:
  #3 (permalink)  
Antiguo 26/07/2004, 08:51
 
Fecha de Ingreso: junio-2003
Ubicación: Santiago de Compostela
Mensajes: 603
Antigüedad: 21 años, 10 meses
Puntos: 0
Gracias, pero quiero hacerlo en ASP
  #4 (permalink)  
Antiguo 27/07/2004, 02:18
Avatar de ElAprendiz  
Fecha de Ingreso: enero-2002
Ubicación: Maipu, Chile
Mensajes: 3.706
Antigüedad: 23 años, 3 meses
Puntos: 2
esta funcion te servira aunque es un poco lenta si lo utilizas con muchos archivos (galeria). el codigo lo iba a mostrar pronto. pero no habia tenido tiempo.

lo utilizas asi
ruta = "../img/demo.jpg"

If gfxSpex(Server.Mappath(ruta), w, h) then
'es una imagen valida (GIF o JPG)
response.write "Width = " & w
response.write "<br>Height = " & h
End If



Código PHP:
'------------------------------------------------------------


  '
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  
':::                                                             :::
  '
:::  This routine will attempt to identify any filespec passed  :::
  
':::  as a graphic file (regardless of the extension). This will :::
  '
:::  work with GIF or JPG files.                            :::
  
':::                                                             :::
  '
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  
':::          Based on ideas presented by David Crowell          :::
  '
:::                   (credit where due)                        :::
  
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  '
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  '
::: blah blah blah blah blah blah blah blah blah blah blah blah :::
  
'::: blah blah blah blah blah blah blah blah blah blah blah blah :::
  '
::: blah blah     Copyright *cMM,  Mike Shaffer     blah blah :::
  
'::: blah blah      ALL RIGHTS RESERVED WORLDWIDE      blah blah :::
  '
::: blah blah  Permission is granted to use this code blah blah :::
  
'::: blah blah   in your projects, as long as this     blah blah :::
  '
::: blah blah      copyright notice is included       blah blah :::
  
'::: blah blah blah blah blah blah blah blah blah blah blah blah :::
  '
::: blah blah blah blah blah blah blah blah blah blah blah blah :::
  
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

  '
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  
':::                                                             :::
  '
:::  This function gets a specified number of bytes from any    :::
  
':::  file, starting at the offset (base 1)                      :::
  '
:::                                                             :::
  
':::  Passed:                                                    :::
  '
:::       sFileName        => Filespec of file to read          :::
  
':::       offset      => Offset at which to start reading       :::
  '
:::       bytes       => How many bytes to read                 :::
  
':::                                                             :::
  '
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  function 
GetBytes(sFileNameoffsetbytes)

     
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(sFileName)
     lngSize = objFTemp.Size
     set objFTemp = nothing

     fsoForReading = 1
     Set objTextStream = objFSO.OpenTextFile(sFileName, 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


  '
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  
':::                                                             :::
  '
:::  Functions to convert two bytes to a numeric value (long)   :::
  
':::  (both little-endian and big-endian)                        :::
  '
:::                                                             :::
  
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  function lngConvert(strTemp)
     lngConvert = clng(asc(left(strTemp, 1)) + ((asc(right(strTemp, 1)) * 256)))
  end function

  function lngConvert2(strTemp)
     lngConvert2 = clng(asc(right(strTemp, 1)) + ((asc(left(strTemp, 1)) * 256)))
  end function

  
  '
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  
':::                                                             :::
  '
:::  This function does most of the real workIt will attempt  :::
  
':::  to read any file, regardless of the extension, and will    :::
  '
:::  identify if it is a graphical image.                       :::
  
':::                                                             :::
  '
:::  Passed:                                                    :::
  
':::       sFileName        => Filespec of file to read          :::
  '
:::       width       => width of image                         :::
  
':::       height      => height of image                        :::
  '
:::                                                             :::
  
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  function gfxSpex(sFileName, width, height)
      '
get the width and height of the passed file
      
'can only be a GIF or JPG

     dim strGIF
     dim strType
     strType = ""
     strImageType = "(unknown)"

     gfxSpex = False
     
     strGIF = "GIF"

     strType = GetBytes(sFileName, 0, 3)

     if strType = strGIF then                ' 
is GIF

        strImageType 
"GIF"
        
Width lngConvert(GetBytes(sFileName72))
        
Height lngConvert(GetBytes(sFileName92))
        
gfxSpex True

     
else

        
strBuff GetBytes(sFileName0, -1)         Get all bytes from file
        lngSize 
len(strBuff)
        
flgFound 0

        strTarget 
chr(255) & chr(216) & chr(255)
        
flgFound instr(strBuffstrTarget)

        if 
flgFound 0 then
           
exit function
        
end if

        
strImageType "JPG"
        
lngPos flgFound 2
        ExitLoop 
false

        
do while ExitLoop False and lngPos lngSize

           
do while asc(mid(strBufflngPos1)) = 255 and lngPos lngSize
              lngPos 
lngPos 1
           loop

           
if asc(mid(strBufflngPos1)) < 192 or asc(mid(strBufflngPos1)) > 195 then
              lngMarkerSize 
lngConvert2(mid(strBufflngPos 12))
              
lngPos lngPos lngMarkerSize  1
           
else
              
ExitLoop True
           end 
if

       
loop

       
if ExitLoop False then

          Width 
= -1
          Height 
= -1

       
else

          
Height lngConvert2(mid(strBufflngPos 42))
          
Width lngConvert2(mid(strBufflngPos 62))
          
gfxSpex True

       end 
if
                   
     
end if

  
end function 

Un Saludo
__________________
Manual de ASP Avanzado ;-)
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 10:32.