Ver Mensaje Individual
  #108 (permalink)  
Antiguo 07/09/2011, 10:09
Avatar de iviamontes
iviamontes
 
Fecha de Ingreso: enero-2011
Ubicación: $cubano->Arg->Mendoza
Mensajes: 1.184
Antigüedad: 15 años, 9 meses
Puntos: 209
Respuesta: [APORTE] Subir y redimensionar imagenes

por si le sirve a aguien


Código PHP:
    public function crop($width, $height, $margins = false) {

        
$newImage = imagecreatetruecolor($width, $height);
        
        
$ratioW = $width / $this->getWidth();
        
$ratioH = $height / $this->getHeight();
        
$ratio = ($margins === false) ? max($ratioW, $ratioH) : min($ratioW, $ratioH);
        
$newW = floor($this->getWidth() * $ratio);
        
$newH = floor($this->getHeight() * $ratio);
 
        
$this->resize($newW, $newH);
        
        
$x = $y = 0;
        
        if ( 
$this->getHeight() > $this->getWidth() ){
            
$y = ($this->getHeight() - $height) / 2;
        }

        else if (
$this->getHeight() < $this->getWidth()){
            
$x = ($this->getWidth() - $width) / 2;
        }

        
imagecopy($newImage, $this->_image, 0, 0, $x, $y, $width, $height);
        
$this->_image = $newImage;
       
        }