Ver Mensaje Individual
  #20 (permalink)  
Antiguo 24/08/2006, 15:43
Avatar de chalchis
chalchis
 
Fecha de Ingreso: julio-2003
Mensajes: 1.773
Antigüedad: 20 años, 8 meses
Puntos: 21
archivo llamado prueba2 genera el thumnail

<?php

$width=$_GET['width'];
$height=$_GET['height'];
//$width = 80;
//$height = 80;
$filename=trim($_GET['filename']);//imagen a original
$rfisica=realpath($filename);
//verificamos el tipo de imagen
list($ani, $ali, $tipo, $atr)=getimagesize($filename);

//tipos de archivos que captura la variable $tipo
/*
valor-------tipo de imagen
1 = GIF
2 = JPG
3 = PNG
4 = SWF
5 = PSD
6 = BMP
7 = TIFF(intel byte order)
8 = TIFF(motorola byte order)
9 = JPC
10 = JP2
11 = JPX
12 = JB2
13 = SWC
14 = IFF
15 = WBMP
16 = XBM
*/
//creamos segun sea el tipo de imagen

switch($tipo)
{
case 1://gif
$src_image=imagecreatefromgif($filename);//devuelve un id de la imagen
break;
case 2://jpg
$src_image=imagecreatefromjpeg($filename);//devuelve un id de la imagen
break;
case 3://png
$src_image=imagecreatefrompng($filename);//devuelve un id de la imagen
break;

}

//$crear_imagen=imagecreatefromjpeg(';//devuelve un id de la imagen

//imagen desde el archivo
//$src_image=imagecreatefromjpeg($filename);//devuelve un id de la imagen


//$image = imagecreate($width, $height);
$image=ImageCreateTrueColor($width, $height);//creamos la imagen con color real

//asignamos los colores
$bg = imagecolorallocate($image, 216, 216, 235);//para color de fondo
imagefill($image,0,0,$bg); //rellenamos con el color de fondo

//$bg = imagecolorallocate($image, 216, 216, 216);//para color de fondo
//imagefill($image,0,0,$bg);
//imagecolortransparent($image,$bg);

$verde = imagecolorallocate($image, 96, 7, 143);//para el color de la letra

$margin_x = 10;//margen x
$margin_y = 10;//margen y

$w=$width-2*$margin_x;//100
$h=$height-2*$margin_y;//100

$src_w=imagesx($src_image);//aqui obtenemos la anchura de la imagen original apartir del id generado
$src_h=imagesy($src_image);//aqui obtenemos la altura de la imagen original apartir del id generado
if(($w > $src_w) && ($h > $src_h))
{
$dst_w = $src_w;
$dst_h = $src_h;
}
else
{
//¿o escalamos la imagen de acuerdo a la dimensión horizontal?
if(($w/$h) < ($src_w/$src_h))
{
$dst_w=$w;
$dst_h=$w*$src_h/$src_w;
}
else//¿o la escalamos de acuerdo a la dimensión vertical?
{
$dst_w=$h*$src_w/$src_h;
$dst_h=$h;
}
}
//imagecopyresized($image, $src_image, ($width-$dst_w)/2, ($height-$dst_h)/2,0, 0, $dst_w, $dst_h, $src_w, $src_h);
imagecopyresampled($image, $src_image, ($width-$dst_w)/2, ($height-$dst_h)/2,0, 0, $dst_w, $dst_h, $src_w, $src_h);
//colocamos el texto sobre la imagen
imagestring($image, 0, $margin_x, ($height-$margin_y), $tipo, $verde);

//encabezado correspondiente para los datos de salida
switch($tipo)
{
case 1://gif
header("Content-type: image/gif");
imagegif($image);
break;
case 2://jpg
header("Content-type: image/jpeg");
imagejpeg($image);
break;
case 3://png
header("Content-type: image/png");
imagepng($image);
break;
}
//header("Content-type: image/jpeg");


//generamos la imagen
//imagejpeg($image);

//liberamos la memoria
imagedestroy($image);
?>
__________________
gerardo