Ver Mensaje Individual
  #3 (permalink)  
Antiguo 11/02/2005, 02:51
Avatar de illman
illman
 
Fecha de Ingreso: mayo-2001
Mensajes: 115
Antigüedad: 23 años
Puntos: 0
Pues tienes razón, aquí va:

<?
//"UPLOAD DE LA IMAGEN";
$nuevo=1; //"UNA SECUENCIA ÚNICA"
$tipo_archivo = $HTTP_POST_FILES['archivo']['type'];
$nombre_upload = $HTTP_POST_FILES['archivo']['name'];
//$nombre_archivo_bd= $nombre_upload;
$laextension=explode(".",$nombre_upload);
$extension=$laextension[1];
$tamano_archivo = $HTTP_POST_FILES['archivo']['size'];
$nombre_archivo_bd = "PAUTA".$nuevo;



if ($tamano_archivo < 10000000 and ($extension=="jpg" or $extension=="JPG")) { // Imagen JPG
$nombre_archivo_bd.=".jpg";
$nombre_archivo = "DIRECTORIO/".$nombre_archivo_bd;

if (move_uploaded_file($HTTP_POST_FILES['archivo']['tmp_name'], $nombre_archivo)) {
// Nombre del archivo => $nombre_archivo
$max_width=800; // Anchura máxima
$max_height=800; // Altura máxima
$size = getimagesize ($nombre_archivo); //datos de la imagen

// Cambiar medidas
$x_ratio = $max_width / $size[0];
$y_ratio = $max_height / $size[1];
if ( ($size[0] <= $max_width) && ($size[1] <= $max_height) ) {
$tn_width = $size[0];
$tn_height = $size[1];
} else if (($x_ratio * $size[1]) < $max_height) {
$tn_height = ceil($x_ratio * $size[1]);
$tn_width = $max_width;
} else {
$tn_width = ceil($y_ratio * $size[0]);
$tn_height = $max_height;
}

$im=@imagecreatefromjpeg($nombre_archivo);
$small = imagecreatetruecolor($tn_width,$tn_height); // new image
imagecopyresampled($small, $im, 0, 0, 0, 0, $tn_width, $tn_height, $size[0], $size[1]);
imagedestroy($im); // liberar memoria
if (imagejpeg($small,$nombre_archivo,75)) { $carga=1; } else { $carga=2; } // guarda imagen

$max_width=150; // maximum width
$max_height=150; // maximum height

$nombre_archivo; // name of file - must be jpg
$size = getimagesize ($nombre_archivo); // params of image

$x_ratio = $max_width / $size[0];
$y_ratio = $max_height / $size[1];

// Cambiar medidas
if ( ($size[0] <= $max_width) && ($size[1] <= $max_height) ) {
$tn_width = $size[0];
$tn_height = $size[1];
} elseif (($x_ratio * $size[1]) < $max_height) {
$tn_height = ceil($x_ratio * $size[1]);
$tn_width = $max_width;
} else {
$tn_width = ceil($y_ratio * $size[0]);
$tn_height = $max_height;
}
$im=@imagecreatefromjpeg($nombre_archivo); // path to your gallery
$small = imagecreatetruecolor($tn_width,$tn_height); // new image
imagecopyresampled($small, $im, 0, 0, 0, 0, $tn_width, $tn_height, $size[0], $size[1]);
// below is main function resampling image

ImageDestroy($im); // free memory
$path="DIRECTORIO/p_".$nombre_archivo_bd;
if (imagejpeg($small,$path,75)) { $carga=1; } else { $carga=2; }


} else { $carga=0; }

?>

Esta es la parte del código que copia y redimensiona la image