Custom thubmanil image type (extension)

This commit is contained in:
Savetheinternet 2011-04-13 04:08:59 +10:00
parent 4c6c5b906e
commit 971e72000a
3 changed files with 40 additions and 15 deletions

View File

@ -153,6 +153,12 @@
$config['thumb_width'] = 255; $config['thumb_width'] = 255;
$config['thumb_height'] = 255; $config['thumb_height'] = 255;
// Thumbnail extension, empty for inherited (png recommended)
$config['thumb_ext'] = '';
// Thumbnail quality (compression level), from 0 to 9
$config['thumb_quality'] = 7;
// When a thumbnailed image is going to be the same (in dimension), just copy the entire file and use that as a thumbnail instead of resizing/redrawing // When a thumbnailed image is going to be the same (in dimension), just copy the entire file and use that as a thumbnail instead of resizing/redrawing
$config['minimum_copy_resize'] = true; $config['minimum_copy_resize'] = true;
@ -205,8 +211,8 @@
// These can be URLs OR base64 (data URI scheme) // These can be URLs OR base64 (data URI scheme)
//$config['image_sticky'] = $config['dir']['static'] . 'sticky.gif'; //$config['image_sticky'] = $config['dir']['static'] . 'sticky.gif';
//$config['image_locked'] = $config['dir']['static'] . 'locked.gif'; //$config['image_locked'] = $config['dir']['static'] . 'locked.gif';
//$config['image_deleted'] = $config['dir']['static'] . 'deleted.png'; //$config['image_deleted'] = $config['dir']['static'] . 'deleted.';
//$config['image_zip'] = $config['dir']['static'] . 'zip.png'; //$config['image_zip'] = $config['dir']['static'] . 'zip.';
// If you want to put images and other dynamic-static stuff on another (preferably cookieless) domain, you can use this: // If you want to put images and other dynamic-static stuff on another (preferably cookieless) domain, you can use this:
@ -511,7 +517,7 @@
$config['ie_mime_type_detection'] = '/<(?:body|head|html|img|plaintext|pre|script|table|title|a href|channel|scriptlet)/'; $config['ie_mime_type_detection'] = '/<(?:body|head|html|img|plaintext|pre|script|table|title|a href|channel|scriptlet)/';
// Allowed file extensions // Allowed file extensions
$config['allowed_ext'] = Array('jpg', 'jpeg', 'bmp', 'gif', 'png'); $config['allowed_ext'] = Array('jpg', 'jpeg', 'bmp', 'gif', '');
// The names on the post buttons. (On most imageboards, these are both "Post".) // The names on the post buttons. (On most imageboards, these are both "Post".)
$config['button_newtopic'] = 'New Topic'; $config['button_newtopic'] = 'New Topic';

View File

@ -1361,7 +1361,7 @@
return $image; return $image;
} }
function resize($src, $width, $height, $destination_pic, $max_width, $max_height) { function resize($src, $width, $height, $destination_pic, $max_width, $max_height, $ext) {
$return = Array(); $return = Array();
$x_ratio = $max_width / $width; $x_ratio = $max_width / $width;
@ -1382,13 +1382,34 @@
$return['height'] = $tn_height; $return['height'] = $tn_height;
$tmp = imagecreatetruecolor($tn_width, $tn_height); $tmp = imagecreatetruecolor($tn_width, $tn_height);
imagecolortransparent($tmp, imagecolorallocatealpha($tmp, 0, 0, 0, 0));
imagealphablending($tmp, false); if($ext == 'png' || $ext == 'gif') {
imagesavealpha($tmp, true); imagecolortransparent($tmp, imagecolorallocatealpha($tmp, 0, 0, 0, 0));
imagesavealpha($tmp, true);
}
if($ext == 'png')
imagealphablending($tmp, false);
imagecopyresampled($tmp, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height); imagecopyresampled($tmp, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
imagepng($tmp, $destination_pic, 4); switch($ext) {
case 'jpg':
case 'jpeg':
imagejpeg($tmp, $destination_pic);
break;
case 'png':
imagepng($tmp, $destination_pic, $config['thumb_quality']);
break;
case 'gif':
imagegif($tmp, $destination_pic);
break;
case 'bmp':
imagebmp($tmp, $destination_pic);
break;
default:
error('Unknwon file extension.');
}
imagedestroy($src); imagedestroy($src);
imagedestroy($tmp); imagedestroy($tmp);

View File

@ -280,7 +280,7 @@
$post['extension'] = strtolower(substr($post['filename'], strrpos($post['filename'], '.') + 1)); $post['extension'] = strtolower(substr($post['filename'], strrpos($post['filename'], '.') + 1));
$post['file_id'] = time() . rand(100, 999); $post['file_id'] = time() . rand(100, 999);
$post['file'] = $board['dir'] . $config['dir']['img'] . $post['file_id'] . '.' . $post['extension']; $post['file'] = $board['dir'] . $config['dir']['img'] . $post['file_id'] . '.' . $post['extension'];
$post['thumb'] = $board['dir'] . $config['dir']['thumb'] . $post['file_id'] . '.png'; $post['thumb'] = $board['dir'] . $config['dir']['thumb'] . $post['file_id'] . '.' . ($config['thumb_ext'] ? $config['thumb_ext'] : $post['extension']);
} }
// Check string lengths // Check string lengths
@ -414,9 +414,7 @@
$post['filehash'] = $config['file_hash']($post['file']); $post['filehash'] = $config['file_hash']($post['file']);
$post['filesize'] = filesize($post['file']); $post['filesize'] = filesize($post['file']);
if($config['minimum_copy_resize'] && $post['width'] <= $config['thumb_width'] && $post['height'] <= $config['thumb_height'] && $post['extension'] == ($config['thumb_ext'] ? $config['thumb_ext'] : $post['extension'])) {
if($config['minimum_copy_resize'] && $post['width'] <= $config['thumb_width'] && $post['height'] <= $config['thumb_height']) {
// Copy, because there's nothing to resize // Copy, because there's nothing to resize
copy($post['file'], $post['thumb']); copy($post['file'], $post['thumb']);
@ -426,7 +424,7 @@
$image = createimage($post['extension'], $post['file']); $image = createimage($post['extension'], $post['file']);
// Create a thumbnail // Create a thumbnail
$thumb = resize($image, $post['width'], $post['height'], $post['thumb'], $config['thumb_width'], $config['thumb_height']); $thumb = resize($image, $post['width'], $post['height'], $post['thumb'], $config['thumb_width'], $config['thumb_height'], ($config['thumb_ext'] ? $config['thumb_ext'] : $post['extension']));
$post['thumbwidth'] = $thumb['width']; $post['thumbwidth'] = $thumb['width'];
$post['thumbheight'] = $thumb['height']; $post['thumbheight'] = $thumb['height'];