In that code, there is a problem with the local pictures..
¿What will you need?:
- A folder in the root of your web called
tmp (you can change it in the modified file)
- A folder in the root of your web called
fuentes (you can change it in the modified file)
- True type font segoeuib.ttf, in fuentes folder (you can change it in the modified file)
- Icy Phoenix
- These instructions:
Instructions:
#
#-------------[ Begin ]-----------
#
#
#------------[ OPEN ]--------------
#
/image_thumbnail.php
#
#-------------[ FIND]--------------
#
require(ALBUM_MOD_PATH . 'album_image_class.' . PHP_EXT);
#
#-------------[ AFTER ADD ] ----------
#
//Danielc's MOD - Vars Declaration START
$tmppath = $_SERVER['DOCUMENT_ROOT'] . '/tmp/'; // You must have this dir in the root.
$thumbspath = $_SERVER['DOCUMENT_ROOT'] . '/files/thumbs/'; // The thumbs directory
$urltothumbs = 'http://www.danielc.22web.net/files/thumbs/'; // The URL to thumbs directory
//Danielc's MOD - Vars Declaration END
#
#-------------[ FIND]--------------
#
if ($image_processed == false)
{
#
#-------------[ AFTER ADD ] ----------
#
// Danielc's Mod Start
$filename = $pic_thumbnail_prefix . '_' . $pic_filename;
if ($pic_local == true){
copy($pic_fullpath, $tmppath.$filename);
} else {
$grab = curl_init();
curl_setopt($grab, CURLOPT_URL, $pic_fullpath);
curl_setopt($grab, CURLOPT_HEADER, false);
curl_setopt($grab, CURLOPT_RETURNTRANSFER, true);
$grabbed = curl_exec($grab);
curl_close($grab);
//ECHO "<b>DEBUG: Nombre de archivo = $filename</b> </br>";
$file = fopen($tmppath.$filename, 'w');
fwrite($file, $grabbed);
fclose($file);
}
$pic_fullpath = $tmppath . $filename;
$pic_local = true;
//Danielc's Mod END
#
#-------------[ FIND]--------------
#
if ($pic_width > $pic_height)
{
$thumbnail_width = $board_config['thumbnail_size'];
$thumbnail_height = $board_config['thumbnail_size'] * ($pic_height / $pic_width);
}
else
{
$thumbnail_height = $board_config['thumbnail_size'];
$thumbnail_width = $board_config['thumbnail_size'] * ($pic_width / $pic_height);
}
$Image = new ImgObj();
if ($pic_filetype == 'jpg')
{
$Image->ReadSourceFileJPG($pic_fullpath);
}
else
{
$Image->ReadSourceFile($pic_fullpath);
}
$Image->Resize($thumbnail_width, $thumbnail_height);
if( $board_config['show_pic_size_on_thumb'] == 1)
{
$dimension_string = intval($pic_width) . "x" . intval($pic_height) . "(" . intval(filesize($pic_fullpath)/1024) . "KB)";
$Image->Text($dimension_string);
}
if ($board_config['thumbnail_cache'] == true)
{
if ($pic_filetype == 'jpg')
{
$Image->SendToFileJPG($pic_thumbnail_fullpath, $album_config['thumbnail_quality']);
}
else
{
$Image->SendToFile($pic_thumbnail_fullpath, $album_config['thumbnail_quality']);
}
//$Image->SendToFile($pic_thumbnail_fullpath, $board_config['thumbnail_quality']);
//@chmod($pic_thumbnail_fullpath, 0777);
}
if ($pic_filetype == 'jpg')
{
$Image->SendToBrowserJPG($pic_title_reg, $pic_filetype, 'thumb_', '', $board_config['thumbnail_quality']);
}
else
{
$Image->SendToBrowser($pic_title_reg, $pic_filetype, 'thumb_', '', $board_config['thumbnail_quality']);
}
if ($Image == true)
{
$Image->Destroy();
exit;
}
else
{
$Image->Destroy();
header('Content-type: image/jpeg');
header('Content-Disposition: filename=thumb_' . $pic_title_reg . '.' . $pic_filetype);
readfile($images['no_thumbnail']);
exit;
}
#
#-------------[ REPLACE WITH ]--------------
#
//---------------------------------
//Danielc's CURL MOD START
//---------------------------------
$maxsize = $req_thumb_size;
$showoriginalsize = $board_config['show_pic_size_on_thumb'];
$jpgquality = $board_config['thumbnail_quality'];
$filename = $pic_thumbnail_prefix . '_' . $pic_filename;
/*if(file_exists($thumbspath.$filename)){
unlink($thumbspath.$filename);
//ECHO "<b>DEBUG: Existencia de archivo previo. Eliminando.</b> </br>";
}*/
if(file_exists($tmppath.$filename)){
//ECHO "<b>DEBUG: Archivo Subido correctamente a directorio temporal.</b> </br>";
switch ($pic_filetype){
case 'jpg':
$srcimage = imagecreatefromjpeg($tmppath.$filename);
//header("Content-type: image/jpeg");
break;
case 'jpeg':
$srcimage = imagecreatefromjpeg($tmppath.$filename);
//header("Content-type: image/jpeg");
break;
case 'gif':
$srcimage = imagecreatefromgif($tmppath.$filename);
//header("Content-type: image/gif");
break;
case 'png':
$srcimage = imagecreatefrompng($tmppath.$filename);
//header("Content-type: image/png");
break;
default:
$srcimage = imagecreatefromjpeg($tmppath.$filename);
//header("Content-type: image/jpeg");
}
$pic_width = imagesx($srcimage);
$pic_height = imagesy($srcimage);
if($pic_width > $maxsize || $pic_height > $maxsize){
if($pic_width > $pic_height){
$ratio = $maxsize / $pic_width;
} else {
$ratio = $maxsize / $pic_height;
}
//next calculate the size of the thumbnail
$thumbnail_width = $pic_width * $ratio;
$thumbnail_height = $pic_height * $ratio;
} else {
$thumbnail_width = $pic_width;
$thumbnail_height = $pic_height;
}
//ECHO "<b>DEBUG: Las dimensiones calculadas de la miniatura son " . $thumbwidth . "x" . $thumbheight . "</b> </br>";
if($showoriginalsize == 0){
$thumbnail = imagecreatetruecolor($thumbnail_width, $thumbnail_height);
//ECHO "<b>DEBUG: Showoriginalsize deshabilitado</b></br>";
} else {
//ECHO "<b>DEBUG: Showoriginalsize habilitado</b></br>";
$thumbnail = imagecreatetruecolor($thumbnail_width, $thumbnail_height + 20);
$color = ImageColorAllocate($thumbnail, 0, 0, 0);
imagefilledrectangle($thumbnail, 0, $thumbnail_height, $thumbnail_width, $thumbnail_height + 20, $color);
$color_texto = ImageColorAllocate($thumbnail, 255, 255, 255);
$peso = filesize($tmppath.$filename);
$texto = $pic_width . "x" . $pic_height . "px " . round(($peso/1024)) . " KB";
//ECHO "<b>DEBUG: texto = $texto</b></br>";
$fuente = $_SERVER['DOCUMENT_ROOT'] . '/fuentes/segoeuib.ttf';
$bounds[] = array();
$bounds = imageftbbox(10,0,$fuente, $texto);
$x = $bounds[0] + ($thumbnail_width / 2) - ($bounds[4] / 2);
$y = $bounds[1] + (20 / 2) - ($bounds[5] / 2) + $thumbnail_height;
//ECHO "<b>DEBUG: x = $x y = $y </b></br>";
imagettftext($thumbnail, 10, 0, $x, $y, $color_texto, $fuente, $texto);
}
imagecopyresampled($thumbnail, $srcimage, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $pic_width, $pic_height);
switch ($pic_filetype) {
case "jpg":
case "jpeg":
header('Content-type: image/jpeg');
imagejpeg($thumbnail);
imagejpeg($thumbnail, $thumbspath.$filename, $jpgquality);
break;
case "gif":
header('Content-type: image/gif');
imagegif($thumbnail);
imagegif($thumbnail, $thumbspath.$filename);
break;
case "png":
header('Content-type: image/png');
imagepng($thumbnail);
imagepng($thumbnail, $thumbspath.$filename);
break;
default:
header('Content-type: image/jpeg');
imagejpeg($thumbnail);
imagejpeg($thumbnail, $thumbspath.$filename, $jpgquality);
}
@chmod($thumbspath.$filename, 0777);
imagedestroy($thumbnail);
unlink($tmppath.$filename);
}
//---------------------------------
//Danielc's CURL MOD END
//---------------------------------
#
#----------------[ SAVE ] ----------
#
With this, if source picture is in the server, the script will copy the picture to the temporal folder, after it generates the thumbnail and deletes it..