Hola quiero redimencionar una imagen al subirla.. este codigo k les muestro aca funciona muy bien.. sube la imagen original y hasta crea "thumb".. todo bien hasta ahi.. lo que quiero esque me genere el "thumb" pero k la imagen original me la suba a por lomenos 600x800 que no me la suba tal y como es.. pok no quiero imagenes de 2,3 o 4 MB en mi servidor.. aca les dejo el codigo ojala me puedan ayudar..
este es el archivo subir.php
Código PHP:
<?
require dirname(__FILE__).'/imagen_editor.php';
$thumb_width = 100;
$thumb_height = 100;
$process = $_SESSION['thumbs'];
$thumb_ratio = round($thumb_width/$thumb_height, 2);
$folder = $_POST['folder'];
$name = $_POST['name'];
for($x=1; $x<=2; $x++){
if ($_FILES["file$x"]["size"] > 0) {
$imgSource = $_FILES["file$x"]["tmp_name"];
$dir = realpath("$folder");
$pic = urldecode(basename($_FILES["file$x"]["name"]));
$pic = str_replace(" ", "_", $pic);
if(move_uploaded_file( $imgSource, "$dir/$name")){
list($width, $height, $type, $attr) = getimagesize("$dir/$name");
$ratio = round($width/$height, 2);
if ($process == "crop"){
if($ratio > $thumb_ratio){
$new_width = ceil(($width*$thumb_width)/$height);
$new_height = $thumb_height;
$crop_x = (round($new_width/2))-(round($thumb_width/2));
$crop_y = 0;
} elseif($ratio < $thumb_ratio){
$new_width = $thumb_width;
$new_height = ceil(($height*$thumb_height)/$width);
$crop_x = 0;
$crop_y = (round($new_height/2))-(round($thumb_height/2));
} else {
$new_width = $thumb_width;
$new_height = $thumb_height;
$crop_x = 0;
$crop_y = 0;
}
$imageEditor = new ImageEditor($name, $dir . "/");
$imageEditor->resize($new_width, $new_height);
$imageEditor->crop($crop_x, $crop_y, $thumb_width, $thumb_height);
$imageEditor->outputFile($name, $dir . "/thumbs/");
} else {
if($ratio > $thumb_ratio){
$new_width = $thumb_width;
$new_height = ceil(($thumb_width*$height)/$width);
} elseif($ratio < $thumb_ratio){
$new_width = ceil(($thumb_height*$width)/$height);
$new_height = $thumb_height;
} else {
$new_width = $thumb_width;
$new_height = $thumb_height;
}
$imageEditor = new ImageEditor($name, $dir . "/");
$imageEditor->resize($new_width, $new_height);
$imageEditor->outputFile($name, $dir . "/thumbs/");
}
}
}
}
?>