1 ) or ( $ratioHeight > 1 ) ) { if ( $ratioWidth < $ratioHeight) { $destWidth = $srcWidth/$ratioHeight; $destHeight = $newHeight; } else { $destWidth = $newWidth; $destHeight = $srcHeight/$ratioWidth; } } else { $destWidth = $srcWidth; $destHeight = $srcHeight; } // according to the GD version installed on the server if ( $_POST['gd'] == 2 ) { // GD 2.0 or more recent -> good results (but slower) $destImage = imagecreatetruecolor( $destWidth, $destHeight); imagecopyresampled( $destImage, $srcImage, 0, 0, 0, 0, $destWidth,$destHeight,$srcWidth,$srcHeight ); } else { // GD prior to version 2 -> pretty bad results :-/ (but fast) $destImage = imagecreate( $destWidth, $destHeight); imagecopyresized( $destImage, $srcImage, 0, 0, 0, 0, $destWidth,$destHeight,$srcWidth,$srcHeight ); } $tndir = $dirname.'/thumbnail'; if (!is_dir($tndir)) { if (!is_writable($dirname)) { array_push($page['errors'], '['.$dirname.'] : '.$lang['no_write_access']); return false; } umask(0000); mkdir($tndir, 0777); } $dest_file = $tndir.'/'.$conf['prefix_thumbnail']; $dest_file.= get_filename_wo_extension($filename); $dest_file.= '.'.$tn_ext; // creation and backup of final picture if (!is_writable($tndir)) { array_push($page['errors'], '['.$tndir.'] : '.$lang['no_write_access']); return false; } imagejpeg($destImage, $dest_file); // freeing memory ressources imagedestroy( $srcImage ); imagedestroy( $destImage ); list($tn_width, $tn_height) = getimagesize($dest_file); $tn_size = floor(filesize($dest_file) / 1024).' KB'; $info = array( 'path' => $path, 'tn_file' => $dest_file, 'tn_width' => $tn_width, 'tn_height' => $tn_height, 'tn_size' => $tn_size ); return $info; } // error else { echo $lang['tn_no_support']." "; if ( isset( $extenstion ) ) { echo $lang['tn_format'].' '.$extension; } else { echo $lang['tn_thisformat']; } exit(); } } $pictures = array(); $stats = array(); // +-----------------------------------------------------------------------+ // | template initialization | // +-----------------------------------------------------------------------+ $template->set_filenames( array('thumbnail'=>'admin/thumbnail.tpl') ); $template->assign_vars(array( 'L_THUMBNAIL_TITLE'=>$lang['tn_dirs_title'], 'L_UNLINK'=>$lang['tn_no_missing'], 'L_MISSING_THUMBNAILS'=>$lang['tn_dirs_alone'], 'L_RESULTS'=>$lang['tn_results_title'], 'L_PATH'=>$lang['path'], 'L_FILESIZE'=>$lang['filesize'], 'L_WIDTH'=>$lang['tn_width'], 'L_HEIGHT'=>$lang['tn_height'], 'L_GENERATED'=>$lang['tn_results_gen_time'], 'L_THUMBNAIL'=>$lang['thumbnail'], 'L_PARAMS'=>$lang['tn_params_title'], 'L_GD'=>$lang['tn_params_GD'], 'L_CREATE'=>$lang['tn_params_create'], 'L_SUBMIT'=>$lang['submit'], 'L_REMAINING'=>$lang['tn_alone_title'], 'L_TN_STATS'=>$lang['tn_stats'], 'L_TN_NB_STATS'=>$lang['tn_stats_nb'], 'L_TN_TOTAL'=>$lang['tn_stats_total'], 'L_TN_MAX'=>$lang['tn_stats_max'], 'L_TN_MIN'=>$lang['tn_stats_min'], 'L_TN_AVERAGE'=>$lang['tn_stats_mean'], 'L_ALL'=>$lang['tn_all'], 'U_HELP' => PHPWG_ROOT_PATH.'/popuphelp.php?page=thumbnail', 'T_STYLE'=>$user['template'] )); // +-----------------------------------------------------------------------+ // | search pictures without thumbnails | // +-----------------------------------------------------------------------+ $wo_thumbnails = array(); $thumbnalized = array(); // what is the directory to search in ? $query = ' SELECT galleries_url FROM '.SITES_TABLE.' WHERE id = 1 ;'; list($galleries_url) = mysql_fetch_array(pwg_query($query)); $basedir = preg_replace('#/*$#', '', $galleries_url); $fs = get_fs($basedir); // because isset is one hundred time faster than in_array $fs['thumbnails'] = array_flip($fs['thumbnails']); foreach ($fs['elements'] as $path) { // only pictures need thumbnails if (in_array(get_extension($path), $conf['picture_ext'])) { $dirname = dirname($path); $filename = basename($path); // only files matching the authorized filename pattern can be considered // as "without thumbnail" if (!preg_match('/^[a-zA-Z0-9-_.]+$/', $filename)) { continue; } // searching the element $filename_wo_ext = get_filename_wo_extension($filename); $tn_ext = ''; $base_test = $dirname.'/thumbnail/'; $base_test.= $conf['prefix_thumbnail'].$filename_wo_ext.'.'; foreach ($conf['picture_ext'] as $ext) { if (isset($fs['thumbnails'][$base_test.$ext])) { $tn_ext = $ext; break; } } if (empty($tn_ext)) { array_push($wo_thumbnails, $path); } } } // +-----------------------------------------------------------------------+ // | thumbnails creation | // +-----------------------------------------------------------------------+ if (isset($_POST['submit'])) { $times = array(); $infos = array(); // checking criteria if (!ereg('^[0-9]{2,3}$', $_POST['width']) or $_POST['width'] < 10) { array_push($page['errors'], $lang['tn_err_width'].' 10'); } if (!ereg('^[0-9]{2,3}$', $_POST['height']) or $_POST['height'] < 10) { array_push($page['errors'], $lang['tn_err_height'].' 10'); } // picture miniaturization if (count($page['errors']) == 0) { $num = 1; foreach ($wo_thumbnails as $path) { if (is_numeric($_POST['n']) and $num > $_POST['n']) { break; } $starttime = get_moment(); if ($info = RatioResizeImg($path,$_POST['width'],$_POST['height'],'jpg')) { $endtime = get_moment(); $info['time'] = ($endtime - $starttime) * 1000; array_push($infos, $info); array_push($times, $info['time']); array_push($thumbnalized, $path); $num++; } else { break; } } if (count($infos) > 0) { $sum = array_sum($times); $average = $sum / count($times); sort($times, SORT_NUMERIC); $max = array_pop($times); if (count($thumbnalized) == 1) { $min = $max; } else { $min = array_shift($times); } $template->assign_block_vars( 'results', array( 'TN_NB'=>count($infos), 'TN_TOTAL'=>number_format($sum, 2, '.', ' ').' ms', 'TN_MAX'=>number_format($max, 2, '.', ' ').' ms', 'TN_MIN'=>number_format($min, 2, '.', ' ').' ms', 'TN_AVERAGE'=>number_format($average, 2, '.', ' ').' ms' )); foreach ($infos as $i => $info) { if ($info['time'] == $max) { $class = 'worst_gen_time'; } else if ($info['time'] == $min) { $class = 'best_gen_time'; } else { $class = ''; } $template->assign_block_vars( 'results.picture', array( 'PATH'=>$info['path'], 'TN_FILE_IMG'=>$info['tn_file'], 'TN_FILESIZE_IMG'=>$info['tn_size'], 'TN_WIDTH_IMG'=>$info['tn_width'], 'TN_HEIGHT_IMG'=>$info['tn_height'], 'GEN_TIME'=>number_format($info['time'], 2, '.', ' ').' ms', 'T_CLASS'=>$class )); } } } } // +-----------------------------------------------------------------------+ // | form & pictures without thumbnails display | // +-----------------------------------------------------------------------+ $remainings = array_diff($wo_thumbnails, $thumbnalized); if (count($remainings) > 0) { $form_url = PHPWG_ROOT_PATH.'admin.php?page=thumbnail'; $gd = !empty($_POST['gd']) ? $_POST['gd'] : 2; $width = !empty($_POST['width']) ? $_POST['width'] : $conf['tn_width']; $height = !empty($_POST['height']) ? $_POST['height'] : $conf['tn_height']; $n = !empty($_POST['n']) ? $_POST['n'] : 5; $gdlabel = 'GD'.$gd.'_CHECKED'; $nlabel = 'n_'.$n.'_CHECKED'; $template->assign_block_vars( 'params', array( 'F_ACTION'=>add_session_id($form_url), $gdlabel=>'checked="checked"', $nlabel=>'checked="checked"', 'WIDTH_TN'=>$width, 'HEIGHT_TN'=>$height )); $template->assign_block_vars( 'remainings', array('TOTAL_IMG'=>count($remainings))); $num = 1; foreach ($remainings as $path) { $class = ($num % 2) ? 'row1' : 'row2'; list($width, $height) = getimagesize($path); $size = floor(filesize($path) / 1024).' KB'; $template->assign_block_vars( 'remainings.remaining', array( 'NB_IMG'=>($num), 'PATH'=>$path, 'FILESIZE_IMG'=>$size, 'WIDTH_IMG'=>$width, 'HEIGHT_IMG'=>$height, 'T_CLASS'=>$class )); $num++; } } else { $template->assign_block_vars('warning', array()); } // +-----------------------------------------------------------------------+ // | return to admin | // +-----------------------------------------------------------------------+ $template->assign_var_from_handle('ADMIN_CONTENT', 'thumbnail'); ?>