What i want is that the thumbnails are generated in another folder than the original picture:
For a pic in "<CPG_Root>/albums/folder_name/some_image.jpg"
to be created in, let's say: "<CPG_Root>/thumbnails/folder_name/thumb_some_image.jpg"
The reason of this is that i have 2 comp, an old one (FreeBSD server, i will name it: F) hosting all services: apache, mysql, etc.
And my main computer for data storage and general use (regular windows, i will name it W).
I don't want thumbnails to be created on W because i sometime view those pictures from W and storing all the pictures on F is not an option since it doesn't have that much diskspace (thumbnails are ok with size of 80px max and compression of 35 i get around 10KB-15KB per picture)
What i'm currently doing is sharing folders on W with read only rights and F mount them in a dedicated place named "<somewhere>/samba/<other_folders>" and i put a symlink in "<CPG_Root>/albums/" to "<somewhere>/samba/" so i can add pictures from the samba folder but i need the thumbnails to be generated somewhere else.
I've searched the forum but didn't find what i wanted (or i haven't well searched -_-) (the FAQ "custom thumnails" isn't what i need)
So i've done some quick (and probabldy dirty) hack (that work) on those files:
in file addpic.php
toward the beggining
<...>
$pic_file = base64_decode($HTTP_GET_VARS['pic_file']);
$dir_name = dirname($pic_file) . "/";
$file_name = basename($pic_file);
// we create other directory that will follow the same structure than the album of original pictures
$dir_check = "thumbnails/albums/" . dirname($pic_file) . "/";
$dir_explode = explode("/", $dir_check);
$new_dir = "./";
foreach($dir_explode as $part_dir)
{
$new_dir = $new_dir . $part_dir ;
if(!is_dir($new_dir))
{
mkdir ($new_dir, 0744);
}
$new_dir = $new_dir . "/";
}
// end of additional lines
<...>
in file "picmgmt.inc.php"
function resize_image
<...>
function resize_image($src_file, $dest_file, $new_size, $method, $thumb_use)
{
global $CONFIG, $ERROR;
global $lang_errors;
$dest_file = "thumbnails/" . $dest_file; // Changing the destination so it goes in our folder
<...>
and
<...>
case "im" :
if (preg_match("#[A-Z]:|\\\\#Ai", __FILE__)) {
// get the basedir, remove '/include'
$cur_dir = substr(dirname(__FILE__), 0, -8);
$src_file = '"' . $cur_dir . '\\' . strtr($src_file, '/', '\\') . '"';
$im_dest_file = str_replace('%', '%%', ('"thumbnails\\' . $cur_dir . '\\' . strtr($dest_file, '/', '\\') . '"')); // added the wanted destination folder, haven't run in it yet, but it's just a hunch
} else {
$src_file = escapeshellarg($src_file);
$im_dest_file = str_replace('%', '%%', escapeshellarg($dest_file));
}
<...>
in file "function.inc.php"
function display_thumbnails
<...>
if (count($pic_data) > 0) {
foreach ($pic_data as $key => $row) {
$i++;
$pic_title =$lang_display_thumbnails['filename'].$row['filename']."\n".
$lang_display_thumbnails['filesize'].($row['filesize'] >> 10).$lang_byte_units[1]."\n".
$lang_display_thumbnails['dimensions'].$row['pwidth']."x".$row['pheight']."\n".
$lang_display_thumbnails['date_added'].localised_date($row['ctime'], $album_date_fmt);
$pic_url = "thumbnails/" . get_pic_url($row, 'thumb'); // added the wanted destination folder
if (!is_image($row['filename'])) {
<...>
function "display_film_strip"
<...>
if (count($pic_data) > 0) {
foreach ($pic_data as $key => $row) {
$hi =(($pos==($i + $lower_limit)) ? '1': '');
$i++;
$pic_title =$lang_display_thumbnails['filename'].$row['filename']."\n".
$lang_display_thumbnails['filesize'].($row['filesize'] >> 10).$lang_byte_units[1]."\n".
$lang_display_thumbnails['dimensions'].$row['pwidth']."x".$row['pheight']."\n".
$lang_display_thumbnails['date_added'].localised_date($row['ctime'], $album_date_fmt);
$pic_url = "thumbnails/" . get_pic_url($row, 'thumb'); // added the wanted destination folder
if (!is_image($row['filename'])) {
$image_info = getimagesize($pic_url);
<...>
in file "index.php"
function list_albums
<...>
if ($count > 0) {
if ($alb_thumb['filename']) {
$picture = &$alb_thumb;
} else {
$sql = "SELECT filepath, filename, url_prefix, pwidth, pheight ".
"FROM {$CONFIG['TABLE_PICTURES']} ".
"WHERE pid='{$alb_stat['last_pid']}'";
$result = db_query($sql);
$picture = mysql_fetch_array($result);
mysql_free_result($result);
}
$pic_url = "thumbnails/". get_pic_url($picture, 'thumb'); // added the wanted destination folder
if (!is_image($picture['filename'])) {
$image_info = getimagesize($pic_url);
<...>
in file "editpics.php"
function form_pic_info
<...>
if (UPLOAD_APPROVAL_MODE) {
// Commented out by Omni; Duplicate of above
//$pic_info = $CURRENT_PIC['pwidth'].' × '.$CURRENT_PIC['pheight'].' - '.($CURRENT_PIC['filesize'] >> 10).$lang_byte_units[1];
if($CURRENT_PIC['owner_name']){
$pic_info .= ' - <a href ="profile.php?uid='.$CURRENT_PIC['owner_id'].'" target="_blank">'.$CURRENT_PIC['owner_name'].'</a>';
}
}
$thumb_url = "thumbnails/" . get_pic_url($CURRENT_PIC, 'thumb'); // added the wanted destination folder
$thumb_link = 'displayimage.php?&pos='.(-$CURRENT_PIC['pid']);
$filename = htmlspecialchars($CURRENT_PIC['filename']);
<...>
in file "delete.php"
function delete_picture
$aid = $pic['aid'];
$dir = $CONFIG['fullpath'] . $pic['filepath'];
$dir_thumb = "thumbnails/" . $CONFIG['fullpath'] . $pic['filepath']; // Our thumbnail is in another directory
$file = $pic['filename'];
if (!is_writable($dir)) cpg_die(CRITICAL_ERROR, sprintf($lang_errors['directory_ro'], htmlspecialchars($dir)), __FILE__, __LINE__);
echo "<td class=\"tableb\">" . htmlspecialchars($file) . "</td>";
$files = array($dir . $file, $dir . $CONFIG['normal_pfx'] . $file, [b]$dir_thumb [/b]. $CONFIG['thumb_pfx'] . $file); // and we put it in the list
foreach ($files as $currFile) {
echo "<td class=\"tableb\" align=\"center\">";
if (is_file($currFile)) {
I haven't tested the functions in other modes; but for what i need, it works, no change of the databse structure, nor major change of the core. It could be easily (i think) implemented if other people find some use of it, otherwise, i'll just do change myself on future version for personal use. <_<
(and i hope i haven't forgot to mention other modification i have made...)
I thought i could change the "get_pic_url", but it behave in a weird way, like showing the full pic and not the thumbnail, or showing thumbnail and not the full pic... Maybe i'll dig in some more if i have some spare time...