############################################################## ## MOD Title: GIF Support for web servers with GD >= 2.0.28 ## MOD Author: kegobeer < webmaster@kazebeer.com > (Dave Kazebeer) http://www.kazebeer.com ## MOD Description: This mod enables Coppermine to handle non-animated GIF images ## MOD Version: 1.0.0 ## ## Installation Level: (Easy) ## Installation Time: 10 Minutes ## Files To Edit: include/picmgmt.inc.php, showthumb.php, upload.php, xp_publish.php, db_input.php ## Included Files: (n/a) ############################################################## ## Author Notes: ## ############################################################## ## MOD History: ## ## 2004-08-28 - Version 1.0.0 ## ############################################################## ## Before Adding This MOD To Coppermine, You Should Back Up All Files Related To This MOD ############################################################## # #-----[ OPEN ]------------------------------------------ # include/picmgmt.inc.php # #-----[ FIND ]------------------------------------------ # function resize_image($src_file, $dest_file, $new_size, $method, $thumb_use) { global $CONFIG, $ERROR; global $lang_errors; $imginfo = getimagesize($src_file); if ($imginfo == null) return false; // GD can only handle JPG & PNG images if ($imginfo[2] != GIS_JPG && $imginfo[2] != GIS_PNG && ($method == 'gd1' || $method == 'gd2')) { $ERROR = $lang_errors['gd_file_type_err']; return false; } # #-----[ REPLACE WITH ]------------------------------------------ # function resize_image($src_file, $dest_file, $new_size, $method, $thumb_use) { global $CONFIG, $ERROR; global $lang_errors; $imginfo = getimagesize($src_file); if ($imginfo == null) return false; // Check for GIF create support >= GD v2.0.28 $gifsupport = 0; if ($method == 'gd2') { $gdinfo = gd_info(); $gifsupport = $gdinfo["GIF Create Support"]; } // GD can only handle JPG & PNG images if ($imginfo[2] != GIS_JPG && $imginfo[2] != GIS_PNG && ($method == 'gd1' || ($method == 'gd2' && !$gifsupport))) { $ERROR = $lang_errors['gd_file_type_err']; return false; } # #-----[ FIND ]------------------------------------------ # case "gd2" : if (!function_exists('imagecreatefromjpeg')) { cpg_die(CRITICAL_ERROR, 'PHP running on your server does not support the GD image library, check with your webhost if ImageMagick is installed', __FILE__, __LINE__); } if (!function_exists('imagecreatetruecolor')) { cpg_die(CRITICAL_ERROR, 'PHP running on your server does not support GD version 2.x, please switch to GD version 1.x on the config page', __FILE__, __LINE__); } if ($imginfo[2] == GIS_JPG) $src_img = imagecreatefromjpeg($src_file); else $src_img = imagecreatefrompng($src_file); if (!$src_img) { $ERROR = $lang_errors['invalid_image']; return false; } # #-----[ REPLACE WITH ]------------------------------------------ # case "gd2" : if (!function_exists('imagecreatefromjpeg')) { cpg_die(CRITICAL_ERROR, 'PHP running on your server does not support the GD image library, check with your webhost if ImageMagick is installed', __FILE__, __LINE__); } if (!function_exists('imagecreatetruecolor')) { cpg_die(CRITICAL_ERROR, 'PHP running on your server does not support GD version 2.x, please switch to GD version 1.x on the config page', __FILE__, __LINE__); } if ($imginfo[2] == GIS_JPG) $src_img = imagecreatefromjpeg($src_file); else if ($imginfo[2] == GIS_GIF && $gifsupport) $src_img = imagecreatefromgif($src_file); else $src_img = imagecreatefrompng($src_file); if (!$src_img) { $ERROR = $lang_errors['invalid_image']; return false; } # #-----[ OPEN ]------------------------------------------ # showthumb.php # #-----[ FIND ]------------------------------------------ # function makethumbnail($src_file, $newSize, $method) { global $CONFIG; $content_type = array( GIS_GIF => 'gif', GIS_JPG => 'jpeg', GIS_PNG => 'png' ); // Checks that file exists and is readable if (!filesize($src_file) || !is_readable($src_file)) { header("Content-type: image/gif"); fpassthru(fopen(READ_ERROR_ICON, 'rb')); exit; } // find the image size, no size => unknow type $imginfo = getimagesize($src_file); if ($imginfo == null) { header("Content-type: image/gif"); fpassthru(fopen(UNKNOW_ICON, 'rb')); exit; } // GD can't handle gif images if ($imginfo[2] == GIS_GIF && ($method == 'gd1' || $method == 'gd2')) { header("Content-type: image/gif"); fpassthru(fopen(GIF_ICON, 'rb')); exit; } # #-----[ REPLACE WITH ]------------------------------------------ # function makethumbnail($src_file, $newSize, $method) { global $CONFIG; $content_type = array( GIS_GIF => 'gif', GIS_JPG => 'jpeg', GIS_PNG => 'png' ); // Checks that file exists and is readable if (!filesize($src_file) || !is_readable($src_file)) { header("Content-type: image/gif"); fpassthru(fopen(READ_ERROR_ICON, 'rb')); exit; } // find the image size, no size => unknow type $imginfo = getimagesize($src_file); if ($imginfo == null) { header("Content-type: image/gif"); fpassthru(fopen(UNKNOW_ICON, 'rb')); exit; } // Check for GIF create support >= GD v2.0.28 $gifsupport = 0; if ($method == 'gd2') { $gdinfo = gd_info(); $gifsupport = $gdinfo["GIF Create Support"]; } // GD can't handle gif images if ($imginfo[2] == GIS_GIF && ($method == 'gd1' || ($method == 'gd2' && !$gifsupport))) { header("Content-type: image/gif"); fpassthru(fopen(GIF_ICON, 'rb')); exit; } # #-----[ FIND ]------------------------------------------ # case "gd2" : if ($imginfo[2] == GIS_JPG) $src_img = imagecreatefromjpeg($src_file); else $src_img = imagecreatefrompng($src_file); # #-----[ REPLACE WITH ]------------------------------------------ # case "gd2" : if ($imginfo[2] == GIS_JPG) $src_img = imagecreatefromjpeg($src_file); else if ($imginfo[2] == GIS_GIF && $gifsupport) $src_img = imagecreatefromgif($src_file); else $src_img = imagecreatefrompng($src_file); # #-----[ OPEN ]------------------------------------------ # upload.php # #-----[ FIND ]------------------------------------------ # // Globalize $CONFIG. global $CONFIG, $lang_upload_php, $user_form, $max_file_size; # #-----[ AFTER, ADD ]------------------------------------------ # // Check for GIF create support >= GD v2.0.28 $gifsupport = 0; if ($CONFIG['thumb_method'] == 'gd2') { $gdinfo = gd_info(); $gifsupport = $gdinfo["GIF Create Support"]; } # #-----[ FIND ]------------------------------------------ # // JPEG and PNG only are allowed with GD. If the image is not allowed for GD,delete it. } elseif ($imginfo[2] != GIS_JPG && $imginfo[2] != GIS_PNG && ($CONFIG['thumb_method'] == 'gd1' || $CONFIG['thumb_method'] == 'gd2')) { # #-----[ REPLACE WITH ]------------------------------------------ # // JPEG and PNG only are allowed with GD. If the image is not allowed for GD,delete it. } elseif ($imginfo[2] != GIS_JPG && $imginfo[2] != GIS_PNG && ($CONFIG['thumb_method'] == 'gd1' || ($CONFIG['thumb_method'] == 'gd2' && !$gifsupport))) { # #-----[ FIND ]------------------------------------------ # // JPEG and PNG only are allowed with GD. If the image is not allowed for GD,delete it. } elseif ($imginfo[2] != GIS_JPG && $imginfo[2] != GIS_PNG && ($CONFIG['thumb_method'] == 'gd1' || $CONFIG['thumb_method'] == 'gd2')) { # #-----[ REPLACE WITH ]------------------------------------------ # // JPEG and PNG only are allowed with GD. If the image is not allowed for GD,delete it. } elseif ($imginfo[2] != GIS_JPG && $imginfo[2] != GIS_PNG && ($CONFIG['thumb_method'] == 'gd1' || ($CONFIG['thumb_method'] == 'gd2' && !$gifsupport))) { # #-----[ OPEN ]------------------------------------------ # xp_publish.php # #-----[ FIND ]------------------------------------------ # function process_picture() { global $HTTP_POST_VARS, $HTTP_GET_VARS, $HTTP_POST_FILES, $CONFIG, $IMG_TYPES; global $lang_db_input_php, $lang_errors; # #-----[ AFTER, ADD ]------------------------------------------ # // Check for GIF create support >= GD v2.0.28 $gifsupport = 0; if ($CONFIG['thumb_method'] == 'gd2') { $gdinfo = gd_info(); $gifsupport = $gdinfo["GIF Create Support"]; } # #-----[ FIND ]------------------------------------------ # // JPEG and PNG only are allowed with GD if ($imginfo[2] != GIS_JPG && $imginfo[2] != GIS_PNG && ($CONFIG['thumb_method'] == 'gd1' || $CONFIG['thumb_method'] == 'gd2')) { # #-----[ REPLACE WITH ]------------------------------------------ # // JPEG and PNG only are allowed with GD if ($imginfo[2] != GIS_JPG && $imginfo[2] != GIS_PNG && ($CONFIG['thumb_method'] == 'gd1' || ($CONFIG['thumb_method'] == 'gd2' && !$gifsupport))) { # #-----[ OPEN ]------------------------------------------ # db_input.php # #-----[ FIND ]------------------------------------------ # global $CONFIG, $lang_bad_words, $queries; # #-----[ AFTER, ADD ]------------------------------------------ # // Check for GIF create support >= GD v2.0.28 $gifsupport = 0; if ($CONFIG['thumb_method'] == 'gd2') { $gdinfo = gd_info(); $gifsupport = $gdinfo["GIF Create Support"]; } # #-----[ FIND ]------------------------------------------ # // JPEG and PNG only are allowed with GD } elseif ($imginfo[2] != GIS_JPG && $imginfo[2] != GIS_PNG && ($CONFIG['thumb_method'] == 'gd1' || $CONFIG['thumb_method'] == 'gd2')) { # #-----[ REPLACE WITH ]------------------------------------------ # // JPEG and PNG only are allowed with GD } elseif ($imginfo[2] != GIS_JPG && $imginfo[2] != GIS_PNG && ($CONFIG['thumb_method'] == 'gd1' || ($CONFIG['thumb_method'] == 'gd2' && !$gifsupport))) { # #-----[ SAVE/CLOSE ALL FILES ]------------------------------------------ # # EoM