|
From: Florin C B. <ory...@us...> - 2011-01-07 17:14:14
|
Update of /cvsroot/mxbb/mx_smartor/album_mod/modules In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv7864/modules Modified Files: album_pic.php album_picm.php album_thumbnail.php Log Message: fixed old readfile by replacing with full GD functions Index: album_pic.php =================================================================== RCS file: /cvsroot/mxbb/mx_smartor/album_mod/modules/album_pic.php,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** album_pic.php 23 Jul 2010 12:19:18 -0000 1.5 --- album_pic.php 7 Jan 2011 17:14:06 -0000 1.6 *************** *** 69,72 **** --- 69,74 ---- } + @define('ALBUM_NOPIC_PATH', $module_root_path . 'album_mod/'); + // Mighty Gorgon: this code is reserved for generating extra thumbnail size on the fly... $req_thumb_size = $mx_request_vars->request('thumbnail_size', MX_TYPE_NO_TAGS, $album_config['thumbnail_size']); *************** *** 79,86 **** $pic_filetype = strtolower(substr($pic_filename, strlen($pic_filename) - 4, 4)); $pic_fullpath = ALBUM_UPLOAD_PATH . $pic_filename; $pic_wm_fullpath = ALBUM_WM_CACHE_PATH . 'full_' . $pic_filename; // Mighty Gorgon: this prefix is needed to not overwrite standard thumbnails with the ones generated with the extra size... $pic_wm_prefix = 'mid_' . (($req_thumb_size != $album_config['thumbnail_size']) ? ($req_thumb_size . '_') : '') . md5($pic_id); ! $pic_ext_array = array('gif', 'jpg', 'png'); $pic_title = $thispic['pic_title']; $pic_title_reg = ereg_replace("[^A-Za-z0-9]", "_", $pic_title); --- 81,89 ---- $pic_filetype = strtolower(substr($pic_filename, strlen($pic_filename) - 4, 4)); $pic_fullpath = ALBUM_UPLOAD_PATH . $pic_filename; + $pic_nopic_fullpath = ALBUM_NOPIC_PATH . 'nopicture.jpg'; $pic_wm_fullpath = ALBUM_WM_CACHE_PATH . 'full_' . $pic_filename; // Mighty Gorgon: this prefix is needed to not overwrite standard thumbnails with the ones generated with the extra size... $pic_wm_prefix = 'mid_' . (($req_thumb_size != $album_config['thumbnail_size']) ? ($req_thumb_size . '_') : '') . md5($pic_id); ! $pic_ext_array = array('gif', 'jpg', 'jpeg', 'png'); $pic_title = $thispic['pic_title']; $pic_title_reg = ereg_replace("[^A-Za-z0-9]", "_", $pic_title); *************** *** 240,267 **** // Okay, now we can send image to the browser // ------------------------------------ ! switch ($pic_filetype) ! { ! case '.gif': ! $file_header = 'Content-type: image/gif'; ! break; ! case '.jpg': ! $file_header = 'Content-type: image/jpeg'; ! break; ! case '.png': ! $file_header = 'Content-type: image/png'; ! break; ! default: ! header('Content-type: image/jpeg'); ! header('Content-Disposition: filename=' . $pic_title_reg . $pic_filetype); ! readfile($images['no_thumbnail']); ! exit; ! break; } if ( (($pic_filetype == '.jpg') || ($pic_filetype == '.png')) && ($apply_wm == false) ) { header($file_header); header('Content-Disposition: filename=' .$pic_title_reg . $pic_filetype); ! readfile($pic_fullpath); exit; } --- 243,293 ---- // Okay, now we can send image to the browser // ------------------------------------ ! switch ($pic_filetype) ! { ! case '.gif': ! $file_header = 'Content-type: image/gif'; ! $read_function = 'imagecreatefromgif'; ! break; ! case '.jpeg': ! case '.jpg': ! case '.pjpeg': ! $file_header = 'Content-type: image/jpeg'; ! $read_function = 'imagecreatefromjpeg'; ! break; ! case '.png': ! $file_header = 'Content-type: image/png'; ! $read_function = 'imagecreatefrompng'; ! break; ! default: ! header('Content-type: image/jpeg'); ! $file_header = 'Content-type: image/jpeg'; ! $read_function = 'imagecreatefromjpeg'; ! } ! ! if (!@file_exists($pic_fullpath)) ! { ! mx_message_die(GENERAL_ERROR, 'error: image file does not exists', '', __LINE__, __FILE__, $pic_fullpath); ! $pic_fullpath = $pic_nopic_fullpath; //!empty($images['no_thumbnail']) ? $images['no_thumbnail'] : $module_root_path . 'templates/'. $theme['template_name'] . '/images/nothumbnail.jpg'; } + $pic_size = @getimagesize($pic_fullpath); + $pic_width = $pic_size[0]; + $pic_height = $pic_size[1]; + + $thumbnail_width = $pic_width; + $thumbnail_height = $pic_height; + + //$thumbnail = @imagecreatetruecolor($thumbnail_width, $thumbnail_height); + $thumbnail = ($album_config['gd_version'] == 1) ? @imagecreate($thumbnail_width, $thumbnail_height) : @imagecreatetruecolor($thumbnail_width, $thumbnail_height); + + //$resize_function = 'imagecopyresampled'; + $resize_function = ($album_config['gd_version'] == 1) ? 'imagecopyresized' : 'imagecopyresampled'; + + /* if ( (($pic_filetype == '.jpg') || ($pic_filetype == '.png')) && ($apply_wm == false) ) { header($file_header); header('Content-Disposition: filename=' .$pic_title_reg . $pic_filetype); ! readfile($pic_fullpath); exit; } *************** *** 282,285 **** --- 308,336 ---- exit; } + */ + + header($file_header); + + @$resize_function($thumbnail, $read_function($pic_fullpath), 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $pic_width, $pic_height); + + + switch ( $pic_filetype ) + { + case '.gif': + imagegif($thumbnail); + break; + case '.jpeg': + case '.jpg': + case '.pjpeg': + imagejpeg($thumbnail); + break; + case '.png': + imagepng($thumbnail); + break; + default: + return false; + } + + imagedestroy($thumbnail); // Old Thumbnails - BEGIN Index: album_thumbnail.php =================================================================== RCS file: /cvsroot/mxbb/mx_smartor/album_mod/modules/album_thumbnail.php,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** album_thumbnail.php 23 Jul 2010 12:19:18 -0000 1.7 --- album_thumbnail.php 7 Jan 2011 17:14:06 -0000 1.8 *************** *** 69,72 **** --- 69,73 ---- } } + @define('ALBUM_NOPIC_PATH', $module_root_path . 'album_mod/'); // Mighty Gorgon: this code is reserved for generating extra thumbnail size on the fly... *************** *** 85,88 **** --- 86,90 ---- $pic_thumbnail = ($thispic['pic_thumbnail'] == '') ? $pic_thumbnail_new : $thispic['pic_thumbnail']; //$pic_thumbnail = ( $thispic['pic_thumbnail'] == '' ) ? $pic_filename : $thispic['pic_thumbnail']; + $pic_nopic_fullpath = ALBUM_NOPIC_PATH . 'nothumbnail.jpg';; $pic_thumbnail_fullpath = ALBUM_CACHE_PATH . $pic_thumbnail; $pic_thumbnail_new_fullpath = ALBUM_CACHE_PATH . $pic_thumbnail_new; *************** *** 101,117 **** if($pic_size == false) { ! if(empty($images['no_thumbnail']) || file_exists($module_root_path. 'album_mod/nothumbnail.jpg')) ! { ! header('Content-type: image/jpeg'); ! header('Content-Disposition: filename=thumb_' . $pic_title_reg . '.' . $pic_filetype); ! readfile($module_root_path. 'album_mod/nothumbnail.jpg'); ! } ! else ! { ! header('Content-type: image/jpeg'); ! header('Content-Disposition: filename=thumb_' . $pic_title_reg . '.' . $pic_filetype); ! readfile($images['no_thumbnail']); ! } ! exit; } /* --- 103,108 ---- if($pic_size == false) { ! $pic_fullpath = $pic_nopic_fullpath; ! $pic_size = @getimagesize($pic_fullpath); } /* *************** *** 125,136 **** */ } - /* - else - { - $pic_title = substr($pic_filename, 0, strlen($pic_filename) - strlen($pic_filetype) - 1); - $pic_title_reg = ereg_replace("[^A-Za-z0-9]", '_', $pic_title); - $pic_thumbnail = $pic_thumbnail_prefix . '_' . $pic_filename; - } - */ $pic_thumbnail_fullpath = ALBUM_CACHE_PATH . $pic_thumbnail; --- 116,119 ---- *************** *** 252,278 **** switch ($pic_filetype) { ! case '.gif': ! $file_header = 'Content-type: image/gif'; ! break; ! case '.jpg': ! $file_header = 'Content-type: image/jpeg'; ! break; ! case '.png': ! $file_header = 'Content-type: image/png'; ! break; default: ! header('Content-type: image/jpeg'); ! header("Content-Disposition: filename=thumb_" . $pic_title_reg . $pic_filetype); ! readfile(!empty($images['no_thumbnail']) ? $images['no_thumbnail'] : $module_root_path . 'templates/'. $theme['template_name'] . '/images/nothumbnail.jpg'); ! exit; ! break; } ! if( ($album_config['thumbnail_cache'] == true) && file_exists($pic_thumbnail_fullpath) ) ! { ! header($file_header); ! header("Content-Disposition: filename=thumb_" .$pic_title_reg . $pic_filetype); ! readfile($pic_thumbnail_fullpath); ! exit; } --- 235,263 ---- switch ($pic_filetype) { ! case '.gif': ! $file_header = 'Content-type: image/gif'; ! $read_function = 'imagecreatefromgif'; ! break; ! case '.jpeg': ! case '.jpg': ! case '.pjpeg': ! $file_header = 'Content-type: image/jpeg'; ! $read_function = 'imagecreatefromjpeg'; ! break; ! case '.png': ! $file_header = 'Content-type: image/png'; ! $read_function = 'imagecreatefrompng'; ! break; default: ! header('Content-type: image/jpeg'); ! $file_header = 'Content-type: image/jpeg'; ! $read_function = 'imagecreatefromjpeg'; ! //readfile(!empty($images['no_thumbnail']) ? $images['no_thumbnail'] : $module_root_path . 'templates/'. $theme['template_name'] . '/images/nothumbnail.jpg'); } ! if (!@file_exists($pic_fullpath)) ! { ! //mx_message_die(GENERAL_ERROR, 'error: image file does not exists', '', __LINE__, __FILE__, $pic_fullpath); ! $pic_fullpath = $pic_nopic_fullpath; //!empty($images['no_thumbnail']) ? $images['no_thumbnail'] : $module_root_path . 'templates/'. $theme['template_name'] . '/images/nothumbnail.jpg'; } *************** *** 281,291 **** $pic_height = $pic_size[1]; if( ($pic_width < $album_config['thumbnail_size']) && ($pic_height < $album_config['thumbnail_size']) ) { ! header($file_header); ! header("Content-Disposition: filename=thumb_" .$pic_title_reg . $pic_filetype); ! readfile($pic_fullpath); ! exit; } else { --- 266,322 ---- $pic_height = $pic_size[1]; + if ($pic_width > $pic_height) + { + $thumbnail_width = $album_config['thumbnail_size']; + $thumbnail_height = $album_config['thumbnail_size'] * ($pic_height / $pic_width); + } + else + { + $thumbnail_height = $album_config['thumbnail_size']; + $thumbnail_width = $album_config['thumbnail_size'] * ($pic_width / $pic_height); + } + + header($file_header); + + //$thumbnail = @imagecreatetruecolor($thumbnail_width, $thumbnail_height); + $thumbnail = ($album_config['gd_version'] == 1) ? @imagecreate($thumbnail_width, $thumbnail_height) : @imagecreatetruecolor($thumbnail_width, $thumbnail_height); + + //$resize_function = 'imagecopyresampled'; + $resize_function = ($album_config['gd_version'] == 1) ? 'imagecopyresized' : 'imagecopyresampled'; + + $source = false; + + if( ($album_config['thumbnail_cache'] == true) && file_exists($pic_thumbnail_fullpath) ) + { + $source = $read_function($pic_thumbnail_fullpath); + } + if( ($pic_width < $album_config['thumbnail_size']) && ($pic_height < $album_config['thumbnail_size']) ) { ! $source = $read_function($pic_fullpath); } + + if( @file_exists($source) ) + { + @$resize_function($thumbnail, $source, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $pic_width, $pic_height); + + switch ($pic_filetype) + { + case '.gif': + imagegif($thumbnail); + break; + case '.jpeg': + case '.jpg': + case '.pjpeg': + imagejpeg($thumbnail); + break; + case '.png': + imagepng($thumbnail); + break; + default: + return false; + } + imagedestroy($thumbnail); + } else { *************** *** 314,318 **** header('Content-type: image/jpeg'); header("Content-Disposition: filename=thumb_" . $pic_title_reg . $pic_filetype); ! readfile(!empty($images['no_thumbnail']) ? $images['no_thumbnail'] : $mx_module_path . 'templates/'. $theme['template_name'] . '/images/nothumbnail.jpg'); exit; break; --- 345,349 ---- header('Content-type: image/jpeg'); header("Content-Disposition: filename=thumb_" . $pic_title_reg . $pic_filetype); ! readfile($pic_nopic_fullpath); exit; break; *************** *** 375,379 **** header('Content-type: image/jpeg'); header("Content-Disposition: filename=thumb_" . $pic_title_reg . $pic_filetype); ! readfile(!empty($images['no_thumbnail']) ? $images['no_thumbnail'] : $mx_module_path . 'templates/'. $theme['template_name'] . '/images/nothumbnail.jpg'); break; } --- 406,410 ---- header('Content-type: image/jpeg'); header("Content-Disposition: filename=thumb_" . $pic_title_reg . $pic_filetype); ! readfile($pic_nopic_fullpath); break; } *************** *** 406,413 **** --- 437,446 ---- { $Image->SendToFileJPG($pic_thumbnail_new_fullpath, $album_config['thumbnail_quality']); + @chmod($pic_thumbnail_new_fullpath, 0777); } else { $Image->SendToFile($pic_thumbnail_new_fullpath, $album_config['thumbnail_quality']); + @chmod($pic_thumbnail_new_fullpath, 0777); } //$Image->SendToFile($pic_thumbnail_fullpath, $album_config['thumbnail_quality']); *************** *** 442,446 **** header('Content-type: image/jpeg'); header("Content-Disposition: filename=thumb_" . $pic_title_reg . $pic_filetype); ! readfile(!empty($images['no_thumbnail']) ? $images['no_thumbnail'] : $module_root_path . 'templates/'. $theme['template_name'] . '/images/nothumbnail.jpg'); exit; } --- 475,483 ---- header('Content-type: image/jpeg'); header("Content-Disposition: filename=thumb_" . $pic_title_reg . $pic_filetype); ! if ( @readfile($pic_nopic_fullpath) == false ) ! { ! $thumbnail = ($album_config['gd_version'] == 1) ? @imagecreate($thumbnail_width, $thumbnail_height) : @imagecreatetruecolor($thumbnail_width, $thumbnail_height); ! @imagejpeg($thumbnail, $pic_nopic_fullpath, $album_config['thumbnail_quality']); ! } exit; } Index: album_picm.php =================================================================== RCS file: /cvsroot/mxbb/mx_smartor/album_mod/modules/album_picm.php,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** album_picm.php 8 Jan 2009 20:43:41 -0000 1.5 --- album_picm.php 7 Jan 2011 17:14:06 -0000 1.6 *************** *** 66,69 **** --- 66,70 ---- } + @define('ALBUM_NOPIC_PATH', $module_root_path . 'album_mod/'); $cat_id = $thispic['pic_cat_id']; $user_id = $thispic['pic_user_id']; *************** *** 75,78 **** --- 76,80 ---- $pic_filetype = strtolower(substr($pic_filename, strlen($pic_filename) - 4, 4)); $pic_fullpath = ALBUM_UPLOAD_PATH . $pic_filename; + $pic_nopic_fullpath = ALBUM_NOPIC_PATH . 'nopicture.jpg'; $pic_wm_fullpath = ALBUM_WM_CACHE_PATH . 'full_' . $pic_filename; $pic_med_fullpath = ALBUM_MED_CACHE_PATH . $pic_thumbnail; *************** *** 224,254 **** } - header($file_header); - $pic_size = @getimagesize($pic_fullpath); $pic_width = $pic_size[0]; $pic_height = $pic_size[1]; ! ! if ($pic_width > $pic_height) { ! $thumbnail_width = $thumbnail_size; ! $thumbnail_height = $thumbnail_size * ($pic_height / $pic_width); } else { ! $thumbnail_height = $thumbnail_size; ! $thumbnail_width = $thumbnail_size * ($pic_width / $pic_height); ! } ! ! $thumbnail = @imagecreatetruecolor($thumbnail_width, $thumbnail_height); $resize_function = 'imagecopyresampled'; ! $source = $read_function($pic_fullpath); ! @$resize_function($thumbnail, $source, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $pic_width, $pic_height); ! ! switch ($pic_filetype) { --- 226,255 ---- } $pic_size = @getimagesize($pic_fullpath); $pic_width = $pic_size[0]; $pic_height = $pic_size[1]; ! if ($pic_width > $pic_height) { ! $thumbnail_width = $album_sp_config['midthumb_width']; ! $thumbnail_height = $album_sp_config['midthumb_width'] * ($pic_height/$pic_width); } else { ! $thumbnail_height = $album_sp_config['midthumb_height']; ! $thumbnail_width = $album_sp_config['midthumb_height'] * ($pic_width/$pic_height); ! } + header($file_header); + + //$thumbnail = @imagecreatetruecolor($thumbnail_width, $thumbnail_height); + $thumbnail = ($album_config['gd_version'] == 1) ? @imagecreate($thumbnail_width, $thumbnail_height) : @imagecreatetruecolor($thumbnail_width, $thumbnail_height); + $resize_function = 'imagecopyresampled'; ! $source = $read_function($pic_fullpath); ! @$resize_function($thumbnail, $source, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $pic_width, $pic_height); ! switch ($pic_filetype) { *************** *** 272,277 **** } ! header('Content-type: image/jpeg'); ! readfile($images['no_thumbnail']); exit; } --- 273,278 ---- } ! //header('Content-type: image/jpeg'); ! //readfile($images['no_thumbnail']); exit; } *************** *** 286,323 **** switch ($pic_filetype) { ! case '.gif': ! $file_header = 'Content-type: image/gif'; ! break; ! case '.jpg': ! $file_header = 'Content-type: image/jpeg'; ! break; ! case '.png': ! $file_header = 'Content-type: image/png'; ! break; default: ! header('Content-type: image/jpeg'); ! header('Content-Disposition: filename=' . $pic_title_reg . $pic_filetype); ! readfile($images['no_thumbnail']); ! exit; ! break; } if ( (($pic_filetype == '.jpg') || ($pic_filetype == '.png')) && ($apply_wm == false) ) { ! header($file_header); ! header('Content-Disposition: filename=' .$pic_title_reg . $pic_filetype); ! readfile($pic_med_fullpath); ! exit; } if ( $pic_filetype == '.gif' ) { ! header($file_header); ! header('Content-Disposition: filename=' . $pic_title_reg . $pic_filetype); ! readfile($pic_med_fullpath); ! exit; } ! readfile($pic_med_fullpath); exit; } --- 287,380 ---- switch ($pic_filetype) { ! case '.gif': ! $file_header = 'Content-type: image/gif'; ! $read_function = 'imagecreatefromgif'; ! break; ! case '.jpeg': ! case '.jpg': ! case '.pjpeg': ! $file_header = 'Content-type: image/jpeg'; ! $read_function = 'imagecreatefromjpeg'; ! break; ! case '.png': ! $file_header = 'Content-type: image/png'; ! $read_function = 'imagecreatefrompng'; ! break; default: ! header('Content-type: image/jpeg'); ! $file_header = 'Content-type: image/jpeg'; ! $read_function = 'imagecreatefromjpeg'; ! //readfile(!empty($images['no_thumbnail']) ? $images['no_thumbnail'] : $module_root_path . 'templates/'. $theme['template_name'] . '/images/nothumbnail.jpg'); ! } ! ! $pic_fullpath = ALBUM_UPLOAD_PATH . $pic_filename; ! ! if (!@file_exists($pic_fullpath)) ! { ! //mx_message_die(GENERAL_ERROR, 'error: image file does not exists', '', __LINE__, __FILE__, $pic_fullpath); ! $pic_fullpath = !empty($images['no_thumbnail']) ? $images['no_thumbnail'] : $module_root_path . 'templates/'. $theme['template_name'] . '/images/nothumbnail.jpg'; } + header($file_header); + + // -------------------------------- + // Try to read pic size from uloaded file! + // -------------------------------- + $pic_size = @getimagesize($pic_fullpath); + $pic_width = $pic_size[0]; + $pic_height = $pic_size[1]; + + if ($pic_width > $pic_height) + { + $thumbnail_width = $album_sp_config['midthumb_width']; + $thumbnail_height = $album_sp_config['midthumb_width'] * ($pic_height/$pic_width); + } + else + { + $thumbnail_height = $album_sp_config['midthumb_height']; + $thumbnail_width = $album_sp_config['midthumb_height'] * ($pic_width/$pic_height); + } + + //$thumbnail = @imagecreatetruecolor($thumbnail_width, $thumbnail_height); + $thumbnail = ($album_config['gd_version'] == 1) ? @imagecreate($thumbnail_width, $thumbnail_height) : @imagecreatetruecolor($thumbnail_width, $thumbnail_height); + + //$resize_function = 'imagecopyresampled'; + $resize_function = ($album_config['gd_version'] == 1) ? 'imagecopyresized' : 'imagecopyresampled'; + + $source = false; + + /* if ( (($pic_filetype == '.jpg') || ($pic_filetype == '.png')) && ($apply_wm == false) ) { ! $source = $read_function($pic_med_fullpath); } if ( $pic_filetype == '.gif' ) { ! $source = $read_function($pic_med_fullpath); } + */ + + $source = $read_function($pic_med_fullpath); ! @$resize_function($thumbnail, $source, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $pic_width, $pic_height); ! ! switch ($pic_filetype) ! { ! case '.gif': ! imagegif($thumbnail); ! break; ! case '.jpeg': ! case '.jpg': ! case '.pjpeg': ! imagejpeg($thumbnail); ! break; ! case '.png': ! imagepng($thumbnail); ! break; ! default: ! return false; ! } ! imagedestroy($thumbnail); exit; } *************** *** 327,334 **** // Hmm, cache is empty. Try to re-generate! // -------------------------------- - $pic_size = @getimagesize(ALBUM_UPLOAD_PATH . $pic_filename); $pic_width = $pic_size[0]; ! $pic_height = $pic_size[1]; $gd_errored = FALSE; --- 384,390 ---- // Hmm, cache is empty. Try to re-generate! // -------------------------------- $pic_size = @getimagesize(ALBUM_UPLOAD_PATH . $pic_filename); $pic_width = $pic_size[0]; ! $pic_height = $pic_size[1]; $gd_errored = FALSE; |