mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-14 10:37:30 -07:00
Added support for webp images 🌆 (#919)
* 1 * Temp: added webp in bbcode * Update functions_thumbs.php * Update functions_thumbs.php * Updated * Update functions_thumbs.php * Update changes.txt * Update functions_filetypes.php * Update functions_filetypes.php * Update posting_tpl.tpl
This commit is contained in:
parent
e1ff5f9256
commit
5272d7e00b
9 changed files with 57 additions and 48 deletions
|
@ -70,7 +70,6 @@ function image_getdimension($file)
|
|||
$error = false;
|
||||
|
||||
// BMP - IMAGE
|
||||
|
||||
$tmp_str = fread($fp, 2);
|
||||
if ($tmp_str == 'BM') {
|
||||
$length = read_longint($fp);
|
||||
|
@ -120,13 +119,10 @@ function image_getdimension($file)
|
|||
fclose($fp);
|
||||
|
||||
// GIF - IMAGE
|
||||
|
||||
$fp = @fopen($file, 'rb');
|
||||
|
||||
$tmp_str = fread($fp, 3);
|
||||
|
||||
if ($tmp_str == 'GIF') {
|
||||
$tmp_str = fread($fp, 3);
|
||||
$width = read_word($fp);
|
||||
$height = read_word($fp);
|
||||
|
||||
|
@ -159,8 +155,6 @@ function image_getdimension($file)
|
|||
|
||||
// JPG - IMAGE
|
||||
$fp = @fopen($file, 'rb');
|
||||
|
||||
$tmp_str = fread($fp, 4);
|
||||
$w1 = read_word($fp);
|
||||
|
||||
if ((int)$w1 < 16) {
|
||||
|
@ -176,7 +170,6 @@ function image_getdimension($file)
|
|||
}
|
||||
|
||||
if (!$error) {
|
||||
$str = fread($fp, 2);
|
||||
$b = read_byte($fp);
|
||||
|
||||
if ($b != 0 && $b != 1 && $b != 2) {
|
||||
|
@ -210,9 +203,7 @@ function image_getdimension($file)
|
|||
fclose($fp);
|
||||
|
||||
// PCX - IMAGE
|
||||
|
||||
$fp = @fopen($file, 'rb');
|
||||
|
||||
$tmp_str = fread($fp, 3);
|
||||
|
||||
if ((ord($tmp_str[0]) == 10) && (ord($tmp_str[1]) == 0 || ord($tmp_str[1]) == 2 || ord($tmp_str[1]) == 3 || ord($tmp_str[1]) == 4 || ord($tmp_str[1]) == 5) && (ord($tmp_str[2]) == 1)) {
|
||||
|
@ -227,7 +218,6 @@ function image_getdimension($file)
|
|||
$ymin = read_word($fp);
|
||||
$xmax = read_word($fp);
|
||||
$ymax = read_word($fp);
|
||||
$tmp_str = fread($fp, 52);
|
||||
|
||||
$b = fread($fp, 1);
|
||||
if ($b != 0) {
|
||||
|
|
|
@ -54,42 +54,49 @@ function is_imagick()
|
|||
*/
|
||||
function get_supported_image_types($type)
|
||||
{
|
||||
if (@extension_loaded('gd')) {
|
||||
$format = imagetypes();
|
||||
$new_type = 0;
|
||||
|
||||
switch ($type) {
|
||||
case 1:
|
||||
$new_type = ($format & IMG_GIF) ? IMG_GIF : 0;
|
||||
break;
|
||||
case 2:
|
||||
case 9:
|
||||
case 10:
|
||||
case 11:
|
||||
case 12:
|
||||
$new_type = ($format & IMG_JPG) ? IMG_JPG : 0;
|
||||
break;
|
||||
case 3:
|
||||
$new_type = ($format & IMG_PNG) ? IMG_PNG : 0;
|
||||
break;
|
||||
case 6:
|
||||
case 15:
|
||||
$new_type = ($format & IMG_WBMP) ? IMG_WBMP : 0;
|
||||
break;
|
||||
}
|
||||
|
||||
return [
|
||||
'gd' => (bool)$new_type,
|
||||
'format' => $new_type,
|
||||
'version' => (function_exists('imagecreatetruecolor')) ? 2 : 1
|
||||
];
|
||||
// Check GD extension installed
|
||||
if (!extension_loaded('gd')) {
|
||||
return ['gd' => false];
|
||||
}
|
||||
|
||||
return ['gd' => false];
|
||||
$format = imagetypes();
|
||||
$new_type = 0;
|
||||
|
||||
switch ($type) {
|
||||
case 1:
|
||||
$new_type = ($format & IMG_GIF) ? IMG_GIF : 0;
|
||||
break;
|
||||
case 2:
|
||||
case 9:
|
||||
case 10:
|
||||
case 11:
|
||||
case 12:
|
||||
$new_type = ($format & IMG_JPG) ? IMG_JPG : 0;
|
||||
break;
|
||||
case 3:
|
||||
case 4:
|
||||
$new_type = ($format & IMG_PNG) ? IMG_PNG : 0;
|
||||
break;
|
||||
case 6:
|
||||
case 8:
|
||||
case 15:
|
||||
$new_type = ($format & IMG_WBMP) ? IMG_WBMP : 0;
|
||||
break;
|
||||
case 32:
|
||||
$new_type = ($format & IMG_WEBP) ? IMG_WEBP : 0;
|
||||
break;
|
||||
}
|
||||
|
||||
return [
|
||||
'gd' => (bool)$new_type,
|
||||
'format' => $new_type,
|
||||
'version' => (function_exists('imagecreatetruecolor')) ? 2 : 1
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create thumbnail
|
||||
* @throws Exception
|
||||
*/
|
||||
function create_thumbnail($source, $new_file, $mimetype)
|
||||
{
|
||||
|
@ -138,6 +145,11 @@ function create_thumbnail($source, $new_file, $mimetype)
|
|||
case IMG_WBMP:
|
||||
$image = imagecreatefromwbmp($source);
|
||||
break;
|
||||
case IMG_WEBP:
|
||||
$image = imagecreatefromwebp($source);
|
||||
break;
|
||||
default:
|
||||
throw new Exception('Unknown file format: ' . $type['format']);
|
||||
}
|
||||
|
||||
if ($type['version'] == 1 || !$attach_config['use_gd2']) {
|
||||
|
@ -161,6 +173,11 @@ function create_thumbnail($source, $new_file, $mimetype)
|
|||
case IMG_WBMP:
|
||||
imagewbmp($new_image, $new_file);
|
||||
break;
|
||||
case IMG_WEBP:
|
||||
imagewebp($new_image, $new_file);
|
||||
break;
|
||||
default:
|
||||
throw new Exception('Unknown file format: ' . $type['format']);
|
||||
}
|
||||
|
||||
imagedestroy($new_image);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue