Foros del Web » Programando para Internet » PHP »

Redimensionar imagen antes de subir la a BD

Estas en el tema de Redimensionar imagen antes de subir la a BD en el foro de PHP en Foros del Web. Hola, lo que pretendo es que el que suba la imagen no tenga que hacer transformaciones de tamaño previas en la imagen, pero a la ...
  #1 (permalink)  
Antiguo 19/01/2007, 04:58
Avatar de miminiyo  
Fecha de Ingreso: abril-2006
Mensajes: 35
Antigüedad: 18 años
Puntos: 0
Redimensionar imagen antes de subir la a BD

Hola, lo que pretendo es que el que suba la imagen no tenga que hacer transformaciones de tamaño previas en la imagen, pero a la vez controlar el tamaño de la imagen que se guarda en la BD.

Alguna idea?

Gracias
  #2 (permalink)  
Antiguo 19/01/2007, 07:10
 
Fecha de Ingreso: junio-2005
Mensajes: 146
Antigüedad: 18 años, 10 meses
Puntos: 0
Re: Redimensionar imagen antes de subir la a BD

no crees que es mejor solo guardar en la base de datos el url?? si es asi es mejor
__________________
Edgar Nadal
  #3 (permalink)  
Antiguo 19/01/2007, 07:21
Avatar de miminiyo  
Fecha de Ingreso: abril-2006
Mensajes: 35
Antigüedad: 18 años
Puntos: 0
Re: Redimensionar imagen antes de subir la a BD

Perdón, no me he explicado bien. Si guardo la URL en la base de datos. Lo que quiero es que la imagen que suba a la carpeta se redimensione para poder contrlar el tamaño de las imagenes.
  #4 (permalink)  
Antiguo 19/01/2007, 07:34
 
Fecha de Ingreso: junio-2005
Mensajes: 146
Antigüedad: 18 años, 10 meses
Puntos: 0
Re: Redimensionar imagen antes de subir la a BD

bueno, aqui te va un pequeño script, ojala te funcione, cualquier cosa estamos aqui:
Código PHP:
if (isset($_POST['upForm'])){

       
$file_type $_FILES['imgfile']['type'];
       
$file_name $_FILES['imgfile']['name'];
       
$file_size $_FILES['imgfile']['size'];
       
$file_tmp $_FILES['imgfile']['tmp_name'];

       
//check if you have selected a file.
       
if(!is_uploaded_file($file_tmp)){
          echo 
"Error: Please select a file to upload!. <br>--<a href=\"$_SERVER[PHP_SELF]\">back</a>";
          exit(); 
//exit the script and don't do anything else.
       
}
       
//check file extension
       
$ext strrchr($file_name,'.');
       
$ext strtolower($ext);
       if ((
$extlimit == "yes") && (!in_array($ext,$limitedext))) {
          echo 
"Wrong file extension.  <br>--<a href=\"$_SERVER[PHP_SELF]\">back</a>";
          exit();
       }
       
//get the file extension.
       
$getExt explode ('.'$file_name);
       
$file_ext $getExt[count($getExt)-1];

       
//create a random file name
       
$rand_name md5(time());
       
$rand_namerand(0,999999999);
       
//get the new width variable.
       
$ThumbWidth $img_thumb_width;

       
//keep image type
       
if($file_size){
          if(
$file_type == "image/pjpeg" || $file_type == "image/jpeg"){
               
$new_img imagecreatefromjpeg($file_tmp);
           }elseif(
$file_type == "image/x-png" || $file_type == "image/png"){
               
$new_img imagecreatefrompng($file_tmp);
           }elseif(
$file_type == "image/gif"){
               
$new_img imagecreatefromgif($file_tmp);
           }
           
//list width and height and keep height ratio.
           
list($width$height) = getimagesize($file_tmp);
           
$imgratio=$width/$height;
           if (
$imgratio>1){
              
$newwidth $ThumbWidth;
              
$newheight $ThumbWidth/$imgratio;
           }else{
                 
$newheight $ThumbWidth;
                 
$newwidth $ThumbWidth*$imgratio;
           }
           
//function for resize image.
           
if (function_exists(imagecreatetruecolor)){
           
$resized_img imagecreatetruecolor($newwidth,$newheight);
           }else{
                 die(
"Error: Please make sure you have GD library ver 2+");
           }
           
imagecopyresized($resized_img$new_img0000$newwidth$newheight$width$height);
           
//save image
           
ImageJpeg ($resized_img,"$path_thumbs/$rand_name.$file_ext");
           
ImageDestroy ($resized_img);
           
ImageDestroy ($new_img);
           
//print message
           
echo "<br>Image Thumb: <a href=\"$path_thumbs/$rand_name.$file_ext\">$path_thumbs/$rand_name.$file_ext</a>";
        }

}else{
 
//aqui debes imprimir el formulario
 

__________________
Edgar Nadal
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 02:08.