Foros del Web » Programando para Internet » PHP »

Redimencionamiento proporcional

Estas en el tema de Redimencionamiento proporcional en el foro de PHP en Foros del Web. Hola tengo un sistema echo con una clase pero esa le digo el ancho y el alto pero hay imagenes que son verticales por ejemplo ...
  #1 (permalink)  
Antiguo 14/05/2008, 15:10
Avatar de marweb  
Fecha de Ingreso: marzo-2007
Ubicación: Ciudad de Panama
Mensajes: 125
Antigüedad: 17 años
Puntos: 1
Pregunta Redimencionamiento proporcional

Hola tengo un sistema echo con una clase pero esa le digo el ancho y el alto pero hay imagenes que son verticales por ejemplo (PRINCIPALMENTE SON FOTOS DE PROPIEDADES) asi que se me descuadra todo. a ver que puedo hacer que quede cuadrada ya que el diseño esta echo para fotos cuadradas no verticales.

que podria hacer hay alguna clase echa o alguna funcion que me puedan ayuda?

gracias
__________________
Mario Rios - Webmaster
Diseño web en panama / Real Estate / Abogados de Panama
  #2 (permalink)  
Antiguo 14/05/2008, 15:18
 
Fecha de Ingreso: febrero-2006
Mensajes: 858
Antigüedad: 18 años, 2 meses
Puntos: 4
Re: Redimencionamiento proporcional

pon tu codigo!
__________________
*La amistad se multiplica cuando se divide*
  #3 (permalink)  
Antiguo 14/05/2008, 15:22
Avatar de marweb  
Fecha de Ingreso: marzo-2007
Ubicación: Ciudad de Panama
Mensajes: 125
Antigüedad: 17 años
Puntos: 1
De acuerdo Re: Redimencionamiento proporcional

la clase

Código PHP:
?
##############################################
# Shiege Iseng Resize Class
# 11 March 2005
# shiegegeATyahoo.com
# http://shiege.com/scripts/thumbnail/
/*############################################
Sample :
$thumb=new thumbnail("./shiegege.jpg");            // generate image_file, set filename to resize/resample
$thumb->size_width(100);                        // set width for thumbnail, or
$thumb->size_height(300);                        // set height for thumbnail, or
$thumb->size_auto(200);                            // set the biggest width or height for thumbnail
$thumb->jpeg_quality(75);                        // [OPTIONAL] set quality for jpeg only (0 - 100) (worst - best), default = 75
$thumb->show();                                    // show your thumbnail
$thumb->save("./huhu.jpg");                        // save your thumbnail to file
----------------------------------------------
Note :
- GD must Enabled
- Autodetect file extension (.jpg/jpeg, .png, .gif, .wbmp)
  but some server can't generate .gif / .wbmp file types
- If your GD not support 'ImageCreateTrueColor' function,
  change one line from 'ImageCreateTrueColor' to 'ImageCreate'
  (the position in 'show' and 'save' function)
- If your GD not support 'ImageCopyResampled' function,
  change 'ImageCopyResampled' to 'ImageCopyResize'
*/############################################


class thumbnail
{
    var 
$img;

    function 
thumbnail($imgfile)
    {
        
//detect image format
        
$this->img["format"]=ereg_replace(".*\.(.*)$","\\1",$imgfile);
        
$this->img["format"]=strtoupper($this->img["format"]);
        if (
$this->img["format"]=="JPG" || $this->img["format"]=="JPEG") {
            
//JPEG
            
$this->img["format"]="JPEG";
            
$this->img["src"] = ImageCreateFromJPEG ($imgfile);
        } elseif (
$this->img["format"]=="PNG") {
            
//PNG
            
$this->img["format"]="PNG";
            
$this->img["src"] = ImageCreateFromPNG ($imgfile);
        } elseif (
$this->img["format"]=="GIF") {
            
//GIF
            
$this->img["format"]="GIF";
            
$this->img["src"] = ImageCreateFromGIF ($imgfile);
        } elseif (
$this->img["format"]=="WBMP") {
            
//WBMP
            
$this->img["format"]="WBMP";
            
$this->img["src"] = ImageCreateFromWBMP ($imgfile);
        } else {
            
//DEFAULT
            
echo "Not Supported File";
            exit();
        }
        @
$this->img["lebar"] = imagesx($this->img["src"]);
        @
$this->img["tinggi"] = imagesy($this->img["src"]);
        
//default quality jpeg
        
$this->img["quality"]=75;
    }

    function 
size_height($size=100)
    {
        
//height
        
$this->img["tinggi_thumb"]=$size;
        @
$this->img["lebar_thumb"] = ($this->img["tinggi_thumb"]/$this->img["tinggi"])*$this->img["lebar"];
    }

    function 
size_width($size=100)
    {
        
//width
        
$this->img["lebar_thumb"]=$size;
        @
$this->img["tinggi_thumb"] = ($this->img["lebar_thumb"]/$this->img["lebar"])*$this->img["tinggi"];
    }

    function 
size_auto($size=100)
    {
        
//size
        
if ($this->img["lebar"]>=$this->img["tinggi"]) {
            
$this->img["lebar_thumb"]=$size;
            @
$this->img["tinggi_thumb"] = ($this->img["lebar_thumb"]/$this->img["lebar"])*$this->img["tinggi"];
        } else {
            
$this->img["tinggi_thumb"]=$size;
            @
$this->img["lebar_thumb"] = ($this->img["tinggi_thumb"]/$this->img["tinggi"])*$this->img["lebar"];
         }
    }

    function 
jpeg_quality($quality=75)
    {
        
//jpeg quality
        
$this->img["quality"]=$quality;
    }

    function 
show()
    {
        
//show thumb
        
@Header("Content-Type: image/".$this->img["format"]);

        
/* change ImageCreateTrueColor to ImageCreate if your GD not supported ImageCreateTrueColor function*/
        
$this->img["des"] = ImageCreateTrueColor($this->img["lebar_thumb"],$this->img["tinggi_thumb"]);
            @
imagecopyresampled ($this->img["des"], $this->img["src"], 0000$this->img["lebar_thumb"], $this->img["tinggi_thumb"], $this->img["lebar"], $this->img["tinggi"]);

        if (
$this->img["format"]=="JPG" || $this->img["format"]=="JPEG") {
            
//JPEG
            
imageJPEG($this->img["des"],"",$this->img["quality"]);
        } elseif (
$this->img["format"]=="PNG") {
            
//PNG
            
imagePNG($this->img["des"]);
        } elseif (
$this->img["format"]=="GIF") {
            
//GIF
            
imageGIF($this->img["des"]);
        } elseif (
$this->img["format"]=="WBMP") {
            
//WBMP
            
imageWBMP($this->img["des"]);
        }
    }

    function 
save($save="")
    {
        
//save thumb
        
if (empty($save)) $save=strtolower("./thumb.".$this->img["format"]);
        
/* change ImageCreateTrueColor to ImageCreate if your GD not supported ImageCreateTrueColor function*/
        
$this->img["des"] = ImageCreateTrueColor($this->img["lebar_thumb"],$this->img["tinggi_thumb"]);
            @
imagecopyresampled ($this->img["des"], $this->img["src"], 0000$this->img["lebar_thumb"], $this->img["tinggi_thumb"], $this->img["lebar"], $this->img["tinggi"]);

        if (
$this->img["format"]=="JPG" || $this->img["format"]=="JPEG") {
            
//JPEG
            
imageJPEG($this->img["des"],"$save",$this->img["quality"]);
        } elseif (
$this->img["format"]=="PNG") {
            
//PNG
            
imagePNG($this->img["des"],"$save");
        } elseif (
$this->img["format"]=="GIF") {
            
//GIF
            
imageGIF($this->img["des"],"$save");
        } elseif (
$this->img["format"]=="WBMP") {
            
//WBMP
            
imageWBMP($this->img["des"],"$save");
        }
    }
}
?> 

llamando la clase
Código PHP:
// Includes
include("plugins/thumbnail.php"); 

utilizando la clase

Código PHP:
$thumb1=new thumbnail($targetFile);
$thumb1->size_width(350);
$thumb1->size_height(330);
$thumb1->jpeg_quality(100);
$thumb1->save($targetFile); 
__________________
Mario Rios - Webmaster
Diseño web en panama / Real Estate / Abogados de Panama
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 13:54.