Browse Source

Add AVIF support

averageLukas 2 weeks ago
parent
commit
30e33fc5c3
Signed by: averageLukas
GPG Key ID: 1C47C14ABF8A7680
  1. 4
      README.md
  2. 4
      imgboard.php
  3. 10
      inc/functions.php
  4. 4
      inc/html.php
  5. 4
      settings.default.php

4
README.md

@ -50,12 +50,14 @@ support in mind. @@ -50,12 +50,14 @@ support in mind.
## Install
1. Verify the following are installed:
- [PHP 5.5+](https://php.net)
- [PHP 5.5+](https://php.net), or PHP 8.2.0+ for avif support
- [GD Image Processing Library](https://php.net/gd)
- This library is usually installed by default.
- If you plan on disabling image uploads to use TinyIB as a text board only, this library is not required.
- [cURL Library](https://www.php.net/manual/en/book.curl.php)
- This is recommended, but is not strictly required except when `TINYIB_CAPTCHA` is set to `hcaptcha` or `recaptcha`.
- AVIF Library
- Compile PHP using `--with-avif`
2. CD to the directory you wish to install TinyIB.
3. Run the command:
- `git clone https://code.rocketnine.space/tslocum/tinyib.git ./`

4
imgboard.php

@ -462,6 +462,10 @@ if (!isset($_GET['delete']) && !isset($_GET['manage']) && (isset($_POST['name']) @@ -462,6 +462,10 @@ if (!isset($_GET['delete']) && !isset($_GET['manage']) && (isset($_POST['name'])
$post['thumb'] = $temp_file . '.gif';
} else if ($file_mime == "image/png") {
$post['thumb'] = $temp_file . '.png';
} else if ($file_mime == "image/avif") {
$post['thumb'] = $temp_file . '.avif';
} else if ($file_mime == "image/heif") {
$post['thumb'] = $temp_file . '.avif';
} else {
fancyDie(__('Error while processing audio/video.'));
}

10
inc/functions.php

@ -623,6 +623,8 @@ function createThumbnail($file_location, $thumb_location, $new_w, $new_h, $spoil @@ -623,6 +623,8 @@ function createThumbnail($file_location, $thumb_location, $new_w, $new_h, $spoil
$src_img = imagecreatefrompng($file_location);
} else if (preg_match("/gif/", $system[0])) {
$src_img = imagecreatefromgif($file_location);
} else if (preg_match("/avif/", $system[0])) {
$src_img = imagecreatefromavif($file_location);
} else {
return false;
}
@ -663,6 +665,10 @@ function createThumbnail($file_location, $thumb_location, $new_w, $new_h, $spoil @@ -663,6 +665,10 @@ function createThumbnail($file_location, $thumb_location, $new_w, $new_h, $spoil
if (!imagegif($dst_img, $thumb_location)) {
return false;
}
} else if (preg_match("/avif/", $system[0])) {
if (!imageavif($dst_img, $thumb_location)) {
return false;
}
}
imagedestroy($dst_img);
@ -906,7 +912,7 @@ function attachFile($post, $filepath, $filename, $uploaded, $spoiler) { @@ -906,7 +912,7 @@ function attachFile($post, $filepath, $filename, $uploaded, $spoiler) {
$post['file_size_formatted'] = convertBytes($post['file_size']);
checkDuplicateFile($post['file_hex']);
if (in_array($file_mime, array('image/jpeg', 'image/pjpeg', 'image/png', 'image/gif', 'application/x-shockwave-flash'))) {
if (in_array($file_mime, array('image/jpeg', 'image/pjpeg', 'image/png', 'image/gif', 'application/x-shockwave-flash', 'image/avif', 'image/heif'))) {
$file_info = getimagesize($file_src);
$post['image_width'] = $file_info[0] != '' ? $file_info[0] : 0;
$post['image_height'] = $file_info[1] != '' ? $file_info[1] : 0;
@ -922,7 +928,7 @@ function attachFile($post, $filepath, $filename, $uploaded, $spoiler) { @@ -922,7 +928,7 @@ function attachFile($post, $filepath, $filename, $uploaded, $spoiler) {
if ($file_mime == 'application/x-shockwave-flash') {
addVideoOverlay('thumb/' . $post['thumb']);
}
} else if (in_array($file_mime, array('image/jpeg', 'image/pjpeg', 'image/png', 'image/gif'))) {
} else if (in_array($file_mime, array('image/jpeg', 'image/pjpeg', 'image/png', 'image/gif', 'image/avif', 'image/heif'))) {
$post['thumb'] = $file_name_pre . 's.' . $tinyib_uploads[$file_mime][0];
list($thumb_maxwidth, $thumb_maxheight) = thumbnailDimensions($post);

4
inc/html.php

@ -497,11 +497,11 @@ function buildPost($post, $res, $compact=false) { @@ -497,11 +497,11 @@ function buildPost($post, $res, $compact=false) {
<source src="$direct_link"></source>
</video>
EOF;
} else if (in_array(substr($post['file'], -4), array('.jpg', '.png', '.gif'))) {
} else if (in_array(substr($post['file'], -4), array('.jpg', '.png', '.gif', 'avif'))) {
$expandhtml = "<a href=\"$direct_link\" onclick=\"return expandFile(event, '${post['id']}');\"><img src=\"" . ($res == TINYIB_RESPAGE ? "../" : "") . "src/${post["file"]}\" width=\"${post["image_width"]}\" style=\"max-width: {$w}vw;height: auto;\"></a>";
}
$thumblink = "<a href=\"$direct_link\" target=\"_blank\"" . ((isEmbed($post["file_hex"]) || in_array(substr($post['file'], -4), array('.jpg', '.png', '.gif', 'webm', '.mp4'))) ? " onclick=\"return expandFile(event, '${post['id']}');\"" : "") . ">";
$thumblink = "<a href=\"$direct_link\" target=\"_blank\"" . ((isEmbed($post["file_hex"]) || in_array(substr($post['file'], -4), array('.jpg', '.png', '.gif', 'avif', 'webm', '.mp4'))) ? " onclick=\"return expandFile(event, '${post['id']}');\"" : "") . ">";
$expandhtml = rawurlencode($expandhtml);
if (isEmbed($post["file_hex"])) {

4
settings.default.php

@ -80,7 +80,9 @@ define('TINYIB_MAXMESSAGE', 8000); // Maximum message length [0 to disable] @@ -80,7 +80,9 @@ define('TINYIB_MAXMESSAGE', 8000); // Maximum message length [0 to disable]
$tinyib_uploads = array('image/jpeg' => array('jpg'),
'image/pjpeg' => array('jpg'),
'image/png' => array('png'),
'image/gif' => array('gif'));
'image/gif' => array('gif'),
// 'image/avif' => array('avif'),
// 'image/heif' => array('avif'));
// 'application/x-shockwave-flash' => array('swf', 'swf_thumbnail.png');
// 'audio/aac' => array('aac');
// 'audio/flac' => array('flac');

Loading…
Cancel
Save