Es la clase que uso
Código PHP:
Ver originalclass ImageAIT{
// VARIABLES DE x-y CROP
var $xCrop;
var $yCrop;
// VARIABLES DE w-h CROP
var $wCrop;
var $hCrop;
/*****************************************************************
** FUNCIONES DE REDIMENCIONAMIENTO
*****************************************************************/
// FUNCION QUE REDIMENCIONA LA IMAGEN (PRIVADA)
private function doThumbnail($aux2,$image,$width,$height){
return $thumbData;
}
// CREA LAS DIMENCIONES DE LA NUEVA IMAGEN RESPETANDO LOS TAMAÑOS MAXIMOS
function ReSize($img, $fbin1, $xRe, $yRe, $tp){
$ancho=$infoImg[0];
$altura=$infoImg[1];
$rtarget = $xRe/$yRe;
if (($ancho/$altura) > $rtarget){
$xdest = $xRe;
$ydest = round($altura/$ancho*$xRe); }else{
$ydest = $yRe;
$xdest = round($ancho/$altura*$yRe); }
if($tp==1){
$this->CenterImage(($xdest/2), ($ydest/2));
}
return $imagen1 = $this->doThumbnail($img,$fbin1,$xdest,$ydest);
}
function ReSizeXY($fbin1, $xRe, $yRe, $tp, $x, $y){
$ancho=$x;
$altura=$y;
$rtarget = $xRe/$yRe;
if (($ancho/$altura) > $rtarget){
$xdest = $xRe;
$ydest = round($altura/$ancho*$xRe); }else{
$ydest = $yRe;
$xdest = round($ancho/$altura*$yRe); }
if($tp==1){
$this->CenterImage(($xdest/2), ($ydest/2));
}
return $imagen1 = $this->doThumbnail($img,$fbin1,$xdest,$ydest);
}
/*****************************************************************
** FUNCIONES DE CROP
*****************************************************************/
// SETEO DE VARS
function setXcrop($stx){
$this->xCrop=$stx;
}
}
function setYcrop($sty){
$this->yCrop=$sty;
}
}
function setWcrop($stw){
$this->wCrop=$stw;
}
}
function setHcrop($sth){
$this->hCrop=$sth;
}
}
// GETEO DE VARS
function getXcrop(){
return $this->xCrop;
}
function getYcrop(){
return $this->yCrop;
}
function getWcrop(){
return $this->wCrop;
}
function getHcrop(){
return $this->hCrop;
}
// OBTIENE EL CENTRO DE LA IMAGEN
private function CenterImage($auxX, $auxY){
$wAux=($this->wCrop/2);
$hAux=($this->hCrop/2);
$this->setXcrop($auxX-$wAux);
$this->setYcrop($auxY-$hAux);
}
// CORTA UN TRAMO DEL CENTRO DE LA IMAGEN
function CropImageC($img, $image, $tpCrop){
if($tpCrop==0){
$this->CenterImage(($infoImg[0]/2), ($infoImg[1]/2));
}
imagecopy($dest, $src, 0, 0, $this->xCrop, $this->yCrop, $this->wCrop, $this->hCrop); return $thumbData;
}
// CORTA UN TRAMO DEL LA IMAGEN POR LA POSICION X Y
function CropImageXY($image, $xRe, $yRe){
imagecopy($dest, $src, 0, 0, $xRe, $yRe, $this->wCrop, $this->hCrop); return $thumbData;
}
}