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

View file

@ -708,6 +708,7 @@ VALUES ('1', 'gif', ''),
('1', 'jpg', ''), ('1', 'jpg', ''),
('1', 'tif', ''), ('1', 'tif', ''),
('1', 'tga', ''), ('1', 'tga', ''),
('1', 'webp', ''),
('2', 'gtar', ''), ('2', 'gtar', ''),
('2', 'gz', ''), ('2', 'gz', ''),
('2', 'tar', ''), ('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'; ALTER TABLE `bb_bt_tracker` CHANGE `complete` `complete` TINYINT(1) NOT NULL DEFAULT '0';
// 2.4.0-beta3 // 2.4.0-beta3
INSERT INTO `bb_extensions` VALUES ('1', 'webp', '');
INSERT INTO `bb_extensions` VALUES ('2', '7z', ''); INSERT INTO `bb_extensions` VALUES ('2', '7z', '');

View file

@ -70,7 +70,6 @@ function image_getdimension($file)
$error = false; $error = false;
// BMP - IMAGE // BMP - IMAGE
$tmp_str = fread($fp, 2); $tmp_str = fread($fp, 2);
if ($tmp_str == 'BM') { if ($tmp_str == 'BM') {
$length = read_longint($fp); $length = read_longint($fp);
@ -120,13 +119,10 @@ function image_getdimension($file)
fclose($fp); fclose($fp);
// GIF - IMAGE // GIF - IMAGE
$fp = @fopen($file, 'rb'); $fp = @fopen($file, 'rb');
$tmp_str = fread($fp, 3); $tmp_str = fread($fp, 3);
if ($tmp_str == 'GIF') { if ($tmp_str == 'GIF') {
$tmp_str = fread($fp, 3);
$width = read_word($fp); $width = read_word($fp);
$height = read_word($fp); $height = read_word($fp);
@ -159,8 +155,6 @@ function image_getdimension($file)
// JPG - IMAGE // JPG - IMAGE
$fp = @fopen($file, 'rb'); $fp = @fopen($file, 'rb');
$tmp_str = fread($fp, 4);
$w1 = read_word($fp); $w1 = read_word($fp);
if ((int)$w1 < 16) { if ((int)$w1 < 16) {
@ -176,7 +170,6 @@ function image_getdimension($file)
} }
if (!$error) { if (!$error) {
$str = fread($fp, 2);
$b = read_byte($fp); $b = read_byte($fp);
if ($b != 0 && $b != 1 && $b != 2) { if ($b != 0 && $b != 1 && $b != 2) {
@ -210,9 +203,7 @@ function image_getdimension($file)
fclose($fp); fclose($fp);
// PCX - IMAGE // PCX - IMAGE
$fp = @fopen($file, 'rb'); $fp = @fopen($file, 'rb');
$tmp_str = fread($fp, 3); $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)) { 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); $ymin = read_word($fp);
$xmax = read_word($fp); $xmax = read_word($fp);
$ymax = read_word($fp); $ymax = read_word($fp);
$tmp_str = fread($fp, 52);
$b = fread($fp, 1); $b = fread($fp, 1);
if ($b != 0) { if ($b != 0) {

View file

@ -54,42 +54,49 @@ function is_imagick()
*/ */
function get_supported_image_types($type) function get_supported_image_types($type)
{ {
if (@extension_loaded('gd')) { // Check GD extension installed
$format = imagetypes(); if (!extension_loaded('gd')) {
$new_type = 0; return ['gd' => false];
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
];
} }
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 * Create thumbnail
* @throws Exception
*/ */
function create_thumbnail($source, $new_file, $mimetype) function create_thumbnail($source, $new_file, $mimetype)
{ {
@ -138,6 +145,11 @@ function create_thumbnail($source, $new_file, $mimetype)
case IMG_WBMP: case IMG_WBMP:
$image = imagecreatefromwbmp($source); $image = imagecreatefromwbmp($source);
break; 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']) { if ($type['version'] == 1 || !$attach_config['use_gd2']) {
@ -161,6 +173,11 @@ function create_thumbnail($source, $new_file, $mimetype)
case IMG_WBMP: case IMG_WBMP:
imagewbmp($new_image, $new_file); imagewbmp($new_image, $new_file);
break; break;
case IMG_WEBP:
imagewebp($new_image, $new_file);
break;
default:
throw new Exception('Unknown file format: ' . $type['format']);
} }
imagedestroy($new_image); 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; // количество групп на одной странице $bb_cfg['group_members_per_page'] = 50; // количество групп на одной странице
// Tidy // Tidy
$bb_cfg['tidy_post'] = in_array('tidy', get_loaded_extensions(), true); $bb_cfg['tidy_post'] = extension_loaded('tidy');
// Misc // Misc
$bb_cfg['mem_on_start'] = memory_get_usage(); $bb_cfg['mem_on_start'] = memory_get_usage();

View file

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

View file

@ -76,7 +76,7 @@ class BBCode
private function init_replacements(): void private function init_replacements(): void
{ {
$tpl = $this->tpl; $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]+'; $email_exp = '[a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+';
$this->preg = [ $this->preg = [

View file

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