mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-21 13:54:02 -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
|
@ -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