![Antiguo](http://static.forosdelweb.com/fdwtheme/images/statusicon/post_old.gif)
16/02/2006, 03:44
|
![Avatar de kazafun](http://static.forosdelweb.com/customavatars/avatar51348_1.gif) | | | Fecha de Ingreso: diciembre-2003 Ubicación: Elda
Mensajes: 843
Antigüedad: 21 años, 1 mes Puntos: 13 | |
Las imagenes no las almaceno en una BD, sino en una carpeta, en la BD almaceno la ruta.
La funcion es esta, la encontre en internet, la modifique un poco, aunque sigue siendo un poco caotica:
Código:
<?php
/*
This script will create a thumbnail from $_GET[i] (image url), using
$_GET[w] (width), $_GET[h] (height), and $_GET[adjust] (The last one only if
both width and height are specified).
*/
//Check it's only used for local images
if(strstr($_GET['ruta'], "http://")) {
die;
}
//Setup header
header("Content-Type: image/jpeg");
//Open Image according to file extension
$ext = substr($_GET['ruta'], -3); //get extension
/* Check image is in an allowed format and load it */
if(strtolower($ext) == "gif") {
if (!$src = imagecreatefromgif($_GET['ruta'])) {
echo "Error opening $_GET[ruta]!"; exit;
}
} else if(strtolower($ext) == "jpg") {
if (!$src = imagecreatefromjpeg($_GET['ruta'])) {
echo "Error opening $_GET[ruta]!"; exit;
}
} else if(strtolower($ext) == "png") {
if (!$src = imagecreatefrompng($_GET['ruta'])) {
echo "Error opening $_GET[ruta]!"; exit;
}
} else {
die;
}
//$sw=1;
$h = $_GET['alto'];
$w = $_GET['ancho'];
$size = getimagesize($_GET['ruta']);
//Transform image as needed
if($_GET[ancho] && !$_GET[alto]) {
//Setup image height
$h = $size[1]/($size[0]/$w);
//Create new image
$image = imagecreatetruecolor($w, $h);
//Resize image
imagecopyresampled($image, $src, 0, 0, 0, 0, $w, $h, $size[0],
$size[1]);
} else if($_GET[alto] && !$_GET[ancho]) {
//Setup image width
$w = $size[0]/($size[1]/$h);
//Create new image
$image = imagecreatetruecolor($w, $h);
//Resize image
imagecopyresampled($image, $src, 0, 0, 0, 0, $w, $h, $size[0],
$size[1]);
} else if($_GET['ancho'] && $_GET['alto']) {
//Create new image using desired values
$image = imagecreatetruecolor($w, $h);
//Set white background
$white = imagecolorallocate($image, 186, 188, 213);
imagefill($image, 0, 0, $white);
$imgAncho = imagesx ($src);
$imgAlto =imagesy($src);
if($imgAlto < $imgAncho)
{
//Setup image height
$newh = $size[1]/($size[0]/$w);
//Setup $y
$y = ($h-$newh)/2;
//Resize image
imagecopyresampled($image, $src, 0, $y, 0, 0, $w, $newh, $size[0],
$size[1]);
}
else
{
//Setup image width
$neww = $size[0]/($size[1]/$h);
//Setup $x
$x = ($w-$neww)/2;
//Resize image
imagecopyresampled($image, $src, $x, 0, 0, 0, $neww, $h, $size[0],
$size[1]);
}
}
//Output resampled image
imagejpeg($image, "", 90);
imagedestroy($image);
imagedestroy($src);
?>
|