Ver Mensaje Individual
  #3 (permalink)  
Antiguo 17/12/2003, 12:41
Surt
 
Fecha de Ingreso: junio-2003
Mensajes: 33
Antigüedad: 20 años, 10 meses
Puntos: 0
bien, veamos... parte del codigo, la que hace eso precisamente:

************************************************** **
function createThumbnail($orgimg, $thumbnailwidth, $thumbnailquality) {
global $path;
$thumbpath = "{$path}thumbs/{$orgimg}";
$orgimg = "{$path}{$orgimg}";
$error = 0;
if (function_exists('imagecreate') && function_exists('imagecopyresized')) {
// Check if thumbnail directory exists. If not try to create it.
if (!is_dir("{$path}thumbs")) {
$oldumask = umask(0);
if (@!mkdir("{$path}thumbs", 0777)) {
$error = "Thumbnail directory could not be created.";
}
umask($oldumask);
}
// Get file size and file type.
if ($error == 0) {
if (!$size = @getimagesize($orgimg)) {
$error = "Size of original image could not be calculated.";
}
}
// Create link to old image.
if ($error == 0) {
switch ($size[2]) {
case 1 :
if (function_exists('imagecreatefromgif')) {
$img = @imagecreatefromgif($orgimg);
if ($img == "") {
$error = "Could not open link to original image.";
}
} else {
$error = "Could not open link to original image.";
}
break;
case 2 :
if (function_exists('imagecreatefromjpeg')) {
$img = @imagecreatefromjpeg($orgimg);
if ($img == "") {
$error = "Could not open link to original image.";
}
} else {
$error = "Could not open link to original image.";
}
break;
case 3 :
if (function_exists('imagecreatefrompng')) {
$img = @imagecreatefrompng($orgimg);
if ($img == "") {
$error = "Could not open link to original image.";
}
} else {
$error = "Could not open link to original image.";
}
break;
default :
$error = "Cannot create thumbnail. Original image is of an unsupported type.";
break;
}
}
// Calculate the dimensions of the new image.
if ($error == 0) {
if (!strstr($thumbnailwidth, "%")) {
if($size[0] > $size[1]) {
$ratio = $size[0]/$thumbnailwidth;
$height = $size[1]/$ratio;
$height = round($height);
$width = $size[0]/$ratio;
} else {
$ratio = $size[1]/$thumbnailwidth;
$width = $size[0]/$ratio;
$width = round($width);
$height = $size[1]/$ratio;
}
} else {
$ratio = str_replace("%", "", $thumbnailwidth)/100;
$width = round($size[0]*$ratio);
$height = round($size[1]*$ratio);
}
}
// Create new image (true colour if available).
if ($error == 0) {
if (function_exists('imagecreatetruecolor')) {
$newimg = imagecreatetruecolor($width, $height);
} else {
$newimg = imagecreate($width, $height);
}
}
// Resample old image over new image.
if ($error == 0) {
if(!function_exists('imagecopyresampled') || !function_exists('imagecreatetruecolor')) {
if (!@imagecopyresized($newimg, $img, 0, 0, 0, 0, $width, $height, $size[0], $size[1])) {
$error = "Could not resize image.";
}
} else {
if (!@imagecopyresampled($newimg, $img, 0, 0, 0, 0, $width, $height, $size[0], $size[1])) {
$error = "Could not resample image.";
}
}
}
// Make the thumbnails, and save files.
if ($error == 0) {
switch ($size[2]) {
case 1:
if (!@imagegif($newimg, $thumbpath)) {
$error = "Could not save thumbnail.";
}
break;
case 2:
if (!@imagejpeg($newimg, $thumbpath, $thumbnailquality)) {
$error = "Could not save thumbnail.";
}
break;
case 3:
if (!@imagepng($newimg, $thumbpath)) {
$error = "Could not save thumbnail.";
}
break;
default :
$error = "Could not create thumbnail. Image type not supported.";
}
}
// Destroy image both links.
@imagedestroy($newimg);
@imagedestroy($img);
} else {
$error = "Image functions not available for thumbnail.";
}
return $error;
}


************************************************** **
Como podras ver el autor cubre muchas opciones, por eso no me puse a desarrollar uno, sino que cogi ese y lo modifique. Esa funcion y ninguna relacionada estan modificadas.

Por cierto cluster, gracias a tus muchisimas aportaciones al foro he podido hacer esto:
http://www.patriciafernandez.net/enlaces.php
sin preguntar ni una sola vez :D GRACIAS

Última edición por Surt; 17/12/2003 a las 12:52