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:
Roman Kelesidis 2023-10-02 01:04:29 +07:00 committed by GitHub
commit 5272d7e00b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 57 additions and 48 deletions

View file

@ -291,7 +291,7 @@ if ($mode == 'cats') {
$use_gd2_no = ($new_attach['use_gd2'] == '0') ? 'checked' : '';
// Check Thumbnail Support
if (!is_imagick() && !@extension_loaded('gd')) {
if (!is_imagick() && !extension_loaded('gd')) {
$new_attach['img_create_thumbnail'] = '0';
} else {
$template->assign_block_vars('switch_thumbnail_support', []);

View file

@ -708,6 +708,7 @@ VALUES ('1', 'gif', ''),
('1', 'jpg', ''),
('1', 'tif', ''),
('1', 'tga', ''),
('1', 'webp', ''),
('2', 'gtar', ''),
('2', 'gz', ''),
('2', 'tar', ''),

View file

@ -72,4 +72,5 @@ ALTER TABLE `bb_bt_tracker_snap` ADD COLUMN `completed` INT(10) NOT NULL DEFAULT
ALTER TABLE `bb_bt_tracker` CHANGE `complete` `complete` TINYINT(1) NOT NULL DEFAULT '0';
// 2.4.0-beta3
INSERT INTO `bb_extensions` VALUES ('1', 'webp', '');
INSERT INTO `bb_extensions` VALUES ('2', '7z', '');

View file

@ -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) {

View file

@ -54,7 +54,11 @@ function is_imagick()
*/
function get_supported_image_types($type)
{
if (@extension_loaded('gd')) {
// Check GD extension installed
if (!extension_loaded('gd')) {
return ['gd' => false];
}
$format = imagetypes();
$new_type = 0;
@ -70,12 +74,17 @@ function get_supported_image_types($type)
$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 [
@ -85,11 +94,9 @@ function get_supported_image_types($type)
];
}
return ['gd' => false];
}
/**
* 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);

View file

@ -508,7 +508,7 @@ $bb_cfg['user_not_active_days_keep'] = 180; // inactive users but only with no p
$bb_cfg['group_members_per_page'] = 50; // количество групп на одной странице
// Tidy
$bb_cfg['tidy_post'] = in_array('tidy', get_loaded_extensions(), true);
$bb_cfg['tidy_post'] = extension_loaded('tidy');
// Misc
$bb_cfg['mem_on_start'] = memory_get_usage();

View file

@ -19,10 +19,10 @@ define('CHECK_REQIREMENTS', [
'php_min_version' => '8.1.0',
'ext_list' => [
'json',
'gd',
'zlib',
// 'gd', (optional)
// 'zlib', (optional)
'curl',
'tidy',
// 'tidy', (optional)
'mysqli',
'bcmath',
'mbstring',

View file

@ -76,7 +76,7 @@ class BBCode
private function init_replacements(): void
{
$tpl = $this->tpl;
$img_exp = '(https?:)?//[^\s\?&;=\#\"<>]+?\.(jpg|jpeg|gif|png|bmp)([a-z0-9/?&%;][^\[\]]*)?';
$img_exp = '(https?:)?//[^\s\?&;=\#\"<>]+?\.(jpg|jpeg|gif|png|bmp|webp)([a-z0-9/?&%;][^\[\]]*)?';
$email_exp = '[a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+';
$this->preg = [

View file

@ -374,8 +374,8 @@ var TPL = {
reg: {
num : /^\d+$/,
URL : /^https?:\/\/[\w\#$%&~/.\-;:=?@\[\]+]+$/i,
img : /^https?:\/\/[^\s\?&;:=\#\"<>]+\.(jpg|jpeg|gif|png|bmp)$/i,
img_tag : /(https?:\/\/[^\s\?&;:=\#\"<>]+\.(jpg|jpeg|gif|png|bmp)(?!\[|\]|\.))/ig
img : /^https?:\/\/[^\s\?&;:=\#\"<>]+\.(jpg|jpeg|gif|png|bmp|webp)$/i,
img_tag : /(https?:\/\/[^\s\?&;:=\#\"<>]+\.(jpg|jpeg|gif|png|bmp|webp)(?!\[|\]|\.))/ig
},
// построение сообщения на основе данных из формы