Tengo el siguiente codigo:
Código PHP:
function Redimensionar($imagem, $largura){
$img_type = strstr($imagem, '.');
switch($img_type) {
case '.jpg':
$img = @imagecreatefromjpeg($imagem);;
break;
case '.png':
$img = @imagecreatefrompng($imagem);
break;
case '.gif':
$img = @imagecreatefromgif($imagem);
break;
case '.JPG':
$img = @imagecreatefromjpeg($imagem);;
break;
case '.JPEG':
$img = @imagecreatefromjpeg($imagem);;
break;
case '.jpeg':
$img = @imagecreatefromjpeg($imagem);;
break;
case '.PNG':
$img = @imagecreatefrompng($imagem);
break;
case '.GIF':
$img = @imagecreatefromgif($imagem);
break;
default:
echo("Error Invalid Image Type");
die;
break;
}
$x = imagesx($img);
$y = imagesy($img);
$altura = ($largura * $y)/$x;
$nova = imagecreatetruecolor(100, 100);
imagecopyresampled($nova, $img, 0, 0, 0, 0, 102, 102, $x, $y);
imagejpeg($nova, "$imagem");
imagedestroy($img);
imagedestroy($nova);
}
function Redimensionarbig($imagemm){
$img_typee = strstr($imagemm, '.');
switch($img_typee) {
case '.jpg':
$imgg = @imagecreatefromjpeg($imagemm);;
break;
case '.png':
$imgg = @imagecreatefrompng($imagemm);
break;
case '.gif':
$imgg = @imagecreatefromgif($imagemm);
break;
case '.JPG':
$imgg = @imagecreatefromjpeg($imagemm);;
break;
case '.PNG':
$imgg = @imagecreatefrompng($imagemm);
break;
case '.GIF':
$imgg = @imagecreatefromgif($imagemm);
break;
default:
echo("Error Invalid Image Type");
die;
break;
}
$xx = imagesx($imgg);
$yy = imagesy($imgg);
echo $xx.$yy;
if($xx < $yy){
//Cuadrado alto
$ratio = $yy/$xx;
$altox='600';
$anchoy=$altox*$ratio;
}
elseif($xx > $yy){
//Cuadrado ancho
$ratio = $xx/$yy;
$anchox='600';
$altoy=$altox*$ratio;
}
elseif($xx == $yy){
//Cuadrado
$ratio = 1;
$altoy='600';
$anchox='600';
}
else{
$altoy=$yy;
$anchox=$xx;
}
$novaa = imagecreatetruecolor($anchox, $altoy);
imagecopyresampled($novaa, $imgg, 0, 0, 0, 0, $anchox, $altoy, $xx, $yy);
imagejpeg($novaa, "$imagemm");
imagedestroy($imgg);
imagedestroy($novaa);
}
////FIN FUNCION REDIMENSIONAR////
$tempFile = $_FILES['Filedata']['tmp_name'];
//
if($_GET['clave']){
$nombre_escuela = $_GET['clave'];
}
$targetPath = $_SERVER['DOCUMENT_ROOT']."/imagenes_escuelas/".$nombre_escuela."/";
$targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
// $fileTypes = str_replace('*.','',$_REQUEST['fileext']);
// $fileTypes = str_replace(';','|',$fileTypes);
// $typesArray = split('\|',$fileTypes);
// $fileParts = pathinfo($_FILES['Filedata']['name']);
// if (in_array($fileParts['extension'],$typesArray)) {
// Uncomment the following line if you want to make the directory if it doesn't exist
mkdir(str_replace('//','/',$targetPath), 0755, true);
//copia el thum
mkdir($targetPath."thum", 0755, true);
$destino=$targetPath."thum/".$_FILES['Filedata']['name'];
copy($tempFile,$destino);
//copia el archivo grande desde temp a targetfile
move_uploaded_file($tempFile,$targetFile);
//aqui podria modifcar el targetfile para redimensionar la
Redimensionarbig($targetFile);
//redimensiona la thum
Redimensionar($destino,102);
El problema esta en la funcion "Redimensionarbig" lo que hace es verificar si la imagen que no es el thum, si es cuadrado alto o cuadrado ancho o cuadrado, de esta manera le doy un ancho o un alto de 600 y su alto o ancho relativo, pero no se porque motivo nunca se ejecuta el if y la imagen se salta ese filtro, no me puedo dar cuenta en que me estoy equivocando... Ademas como esto trabajar con el plug in ulploadify que es en flash no logro hacer un debug para comprobar que cada variable tenga datos.
Espero alguien pueda ayudarme ya que me estoy volviendo loco redimensionando las imagenes a mano jeje.,
Desde ya muchas gracias!!
Un saludo! :)