Thumbnails en PHP
| From: | axier_ddk at terra dot es | Date: | Mon, 17 Dec 2001 16:09:33 +0000 |
| Subject: | Thumbnails en PHP | ||
| Groups: | php.general.es | ||
| Request: | Send a blank email to general-es+get-16789@lists.php.net to get a copy of this message | ||
Aupa!
Despues de convencerme para no guardar las imagenes en BDs tengo otra
duda sobre esto.
La cosa es que quiero que una pagina me haga las miniaturas
automaticamente para que solo tenga que copiarlas al directorio donde
las voy a guardar. Segun lo he hecho las cambia de tamaño perfectamente
pero en todas pierde todo el color, no hay manera de que haga una
copia exacta(o con algo menos de calidad) sin que pierda el color???
Utilizo algo asi:
<?
function thumbnail($path) {
if (is_readable($path)) {
$hw = GetImageSize($path);
$x = 135;
$y = 90;
$src = imagecreatefrom($path);
$new = imagecreate($x, $y);
imagecopyresized($new, $src, 0, 0, 0, 0, $x, $y, $hw[0], $hw[1]);
imagejpeg($new,$path,80);
}
}
function imagecreatefrom($tmpfile) {
$type = imagetype(join("",file($tmpfile)));
switch ($type) {
case "gif":
$new_img = imagecreatefromgif($tmpfile);
break;
case "png":
$new_img = imagecreatefrompng($tmpfile);
break;
case "jpeg":
default:
$new_img = imagecreatefromjpeg($tmpfile);
}
return $new_img;
}
function imagetype($data) {
$sub = substr($data, 0, 20);
if (preg_match("/GIF/",$sub)) {
$str = "gif";
}
if (preg_match("/JFIF/",$sub)) {
$str = "jpeg";
}
if (preg_match("/Exif/",$sub)) {
$str = "jpeg";
}
if (preg_match("/PNG/", $sub)) {
$str = "png";
}
return $str;
}
?>
--
Best regards,
axier mailto:axier_ddk@terra.es