Ver Mensaje Individual
  #13 (permalink)  
Antiguo 01/10/2013, 13:55
tuuutooo
 
Fecha de Ingreso: septiembre-2008
Mensajes: 72
Antigüedad: 15 años, 8 meses
Puntos: 0
Respuesta: php que muestre imagen

Es la clase que uso

Código PHP:
Ver original
  1. class ImageAIT{
  2.     //  VARIABLES DE x-y CROP
  3.     var $xCrop;
  4.     var $yCrop;
  5.     //  VARIABLES DE w-h CROP
  6.     var $wCrop;
  7.     var $hCrop;
  8.    
  9.     /*****************************************************************
  10.     **      FUNCIONES DE REDIMENCIONAMIENTO
  11.     *****************************************************************/ 
  12.     //  FUNCION QUE REDIMENCIONA LA IMAGEN (PRIVADA)
  13.     private function doThumbnail($aux2,$image,$width,$height){
  14.         $th_t = imagecreatefromstring($image);
  15.         $thumb = imagecreatetruecolor($width,$height);
  16.         imagecopyresampled($thumb,$th_t,0,0,0,0,$width,$height,imagesx($th_t),imagesy($th_t));
  17.         ob_start();
  18.         imagejpeg( $thumb, NULL, 90 );
  19.         $thumbData = ob_get_contents();
  20.         ob_end_clean();
  21.         imagedestroy($th_t);
  22.         imagedestroy($thumb);
  23.         return $thumbData;
  24.     }
  25.     //  CREA LAS DIMENCIONES DE LA NUEVA IMAGEN RESPETANDO LOS TAMAÑOS MAXIMOS
  26.     function ReSize($img, $fbin1, $xRe, $yRe, $tp){
  27.         $infoImg=getimagesize($img);       
  28.         $ancho=$infoImg[0];
  29.         $altura=$infoImg[1];
  30.                    
  31.         $rtarget = $xRe/$yRe;
  32.         if (($ancho/$altura) > $rtarget){
  33.             $xdest = $xRe;
  34.             $ydest = round($altura/$ancho*$xRe);
  35.         }else{
  36.             $ydest = $yRe;
  37.             $xdest = round($ancho/$altura*$yRe);
  38.         }
  39.         if($tp==1){
  40.             $this->CenterImage(($xdest/2), ($ydest/2));
  41.         }
  42.         return $imagen1 = $this->doThumbnail($img,$fbin1,$xdest,$ydest);
  43.     }
  44.    
  45.     function ReSizeXY($fbin1, $xRe, $yRe, $tp, $x, $y){    
  46.         $ancho=$x;
  47.         $altura=$y;
  48.                    
  49.         $rtarget = $xRe/$yRe;
  50.         if (($ancho/$altura) > $rtarget){
  51.             $xdest = $xRe;
  52.             $ydest = round($altura/$ancho*$xRe);
  53.         }else{
  54.             $ydest = $yRe;
  55.             $xdest = round($ancho/$altura*$yRe);
  56.         }
  57.         if($tp==1){
  58.             $this->CenterImage(($xdest/2), ($ydest/2));
  59.         }
  60.         return $imagen1 = $this->doThumbnail($img,$fbin1,$xdest,$ydest);
  61.     }
  62.     /*****************************************************************
  63.     **      FUNCIONES DE CROP
  64.     *****************************************************************/     
  65.     //  SETEO DE VARS
  66.     function setXcrop($stx){
  67.         if(is_numeric($stx)){
  68.             $this->xCrop=$stx;
  69.         }
  70.     }  
  71.     function setYcrop($sty){
  72.         if(is_numeric($sty)){
  73.             $this->yCrop=$sty;
  74.         }
  75.     }
  76.     function setWcrop($stw){
  77.         if(is_numeric($stw)){
  78.             $this->wCrop=$stw;
  79.         }
  80.     }
  81.     function setHcrop($sth){
  82.         if(is_numeric($sth)){
  83.             $this->hCrop=$sth;
  84.         }
  85.     }
  86.     //  GETEO DE VARS
  87.     function getXcrop(){
  88.         return $this->xCrop;       
  89.     }      
  90.     function getYcrop(){
  91.         return $this->yCrop;       
  92.     }
  93.     function getWcrop(){
  94.         return $this->wCrop;       
  95.     }
  96.     function getHcrop(){
  97.         return $this->hCrop;       
  98.     }
  99.     //  OBTIENE EL CENTRO DE LA IMAGEN
  100.     private function CenterImage($auxX, $auxY){
  101.         $wAux=($this->wCrop/2);
  102.         $hAux=($this->hCrop/2);
  103.         $this->setXcrop($auxX-$wAux);
  104.         $this->setYcrop($auxY-$hAux);
  105.     }
  106.     //  CORTA UN TRAMO DEL CENTRO DE LA IMAGEN
  107.     function CropImageC($img, $image, $tpCrop){
  108.         if($tpCrop==0){
  109.             $infoImg=getimagesize($img);
  110.             $this->CenterImage(($infoImg[0]/2), ($infoImg[1]/2));
  111.         }
  112.         $src = imagecreatefromstring($image);
  113.         $dest = imagecreatetruecolor($this->wCrop, $this->hCrop);
  114.         imagecopy($dest, $src, 0, 0, $this->xCrop, $this->yCrop, $this->wCrop, $this->hCrop);
  115.         ob_start();
  116.         imagejpeg( $dest, NULL, 90 );
  117.         $thumbData = ob_get_contents();
  118.         ob_end_clean();
  119.         imagedestroy($dest);
  120.         imagedestroy($src);
  121.         return $thumbData;
  122.     }
  123.     //  CORTA UN TRAMO DEL LA IMAGEN POR LA POSICION X Y
  124.     function CropImageXY($image, $xRe, $yRe){
  125.         $src = imagecreatefromstring($image);
  126.         $dest = imagecreatetruecolor($this->wCrop, $this->hCrop);
  127.         imagecopy($dest, $src, 0, 0, $xRe, $yRe, $this->wCrop, $this->hCrop);
  128.         ob_start();
  129.         imagejpeg( $dest, NULL, 90 );
  130.         $thumbData = ob_get_contents();
  131.         ob_end_clean();
  132.         imagedestroy($dest);
  133.         imagedestroy($src);
  134.         return $thumbData;
  135.     }  
  136. }