Ver Mensaje Individual
  #5 (permalink)  
Antiguo 11/05/2008, 17:03
layker
 
Fecha de Ingreso: noviembre-2007
Mensajes: 264
Antigüedad: 16 años, 5 meses
Puntos: 0
Re: formatear imagen con php

Porcierto podrias explicar este codigo con mas detalle?? eske no se lo que hace.. lo he colocado en mi pagina y no se k ace... un saludo
Código PHP:
if(isset($_FILES['fichero']['name'])) {  

   if(
is_uploaded_file($_FILES['fichero']['tmp_name'])) {
   
   
   
//empieza la redimension, tomamos la imagen temporal subida
   
$info getimagesize($_FILES['fichero']['tmp_name']); 
   
//segun el caso sera jpg, gif, png
   
switch ($info[2]) {
  case 
1:
    
$imagen imagecreatefromgif($_FILES['fichero'] ['tmp_name']); break;
  case 
2:
    
$imagen imagecreatefromjpeg($_FILES['fichero'] ['tmp_name']); break;
  case 
3:
    
$imagen imagecreatefrompng($_FILES['fichero'] ['tmp_name']); break;
  
// etcétera // 
  
}

$original $imagen;
$original_w imagesx($original);
$original_h imagesy($original);

$max 175;  //AQUI PONES EL TAMAÑO DE LA IMAGEN A LO QUE QUIERAS

if($original_w>$original_h) {
    
$muestra_w $max;
    
$muestra_h intval(($original_h/$original_w)*$max);
    } else {
    
$muestra_w intval(($original_w/$original_h)*$max);
    
$muestra_h $max;
    }

$muestra imagecreatetruecolor($muestra_w,$muestra_h); 

imagecopyresampled($muestra,$original,0,0,0,0$muestra_w,$muestra_h,$original_w,$original_h);
imagedestroy($original); // aqui destruyo el original, pues no hace falta ya