Browse Source

Add support for marking an image as a spoiler, causing the thumbnail to be blurred

shortcut
Trevor Slocum 1 year ago
parent
commit
a3a8b8db28
  1. 8
      imgboard.php
  2. 43
      inc/functions.php
  3. 5
      inc/html.php

8
imgboard.php

@ -304,6 +304,8 @@ if (!isset($_GET['delete']) && !isset($_GET['manage']) && (isset($_POST['name'])
$post['ip'] = remoteAddress();
$spoiler = TINYIB_SPOILERIMAGE && isset($_POST['spoiler']);
if ($rawpost || !in_array('name', $hide_fields)) {
list($post['name'], $post['tripcode']) = nameAndTripcode($_POST['name']);
$post['name'] = cleanString(substr($post['name'], 0, 75));
@ -436,7 +438,7 @@ if (!isset($_GET['delete']) && !isset($_GET['manage']) && (isset($_POST['name'])
fancyDie(__('Failed to download file at specified URL.'));
}
$post = attachFile($post, $filepath, basename(parse_url(trim($_POST['embed']), PHP_URL_PATH)), false);
$post = attachFile($post, $filepath, basename(parse_url(trim($_POST['embed']), PHP_URL_PATH)), false, $spoiler);
} else {
$post['file_hex'] = $service;
$temp_file = time() . substr(microtime(), 2, 3);
@ -461,7 +463,7 @@ if (!isset($_GET['delete']) && !isset($_GET['manage']) && (isset($_POST['name'])
list($thumb_maxwidth, $thumb_maxheight) = thumbnailDimensions($post);
if (!createThumbnail($file_location, $thumb_location, $thumb_maxwidth, $thumb_maxheight)) {
if (!createThumbnail($file_location, $thumb_location, $thumb_maxwidth, $thumb_maxheight, $spoiler)) {
fancyDie(__('Could not create thumbnail.'));
}
@ -477,7 +479,7 @@ if (!isset($_GET['delete']) && !isset($_GET['manage']) && (isset($_POST['name'])
} else if (isset($_FILES['file']) && $_FILES['file']['name'] != "" && ($rawpost || !in_array('file', $hide_fields))) {
validateFileUpload();
$post = attachFile($post, $_FILES['file']['tmp_name'], $_FILES['file']['name'], true);
$post = attachFile($post, $_FILES['file']['tmp_name'], $_FILES['file']['name'], true, $spoiler);
}
if ($post['file'] == '') { // No file uploaded

43
inc/functions.php

@ -558,7 +558,7 @@ function ffmpegThumbnail($file_location, $thumb_location, $new_w, $new_h) {
}
}
function createThumbnail($file_location, $thumb_location, $new_w, $new_h) {
function createThumbnail($file_location, $thumb_location, $new_w, $new_h, $spoiler) {
$system = explode(".", $thumb_location);
$system = array_reverse($system);
if (TINYIB_THUMBNAIL == 'gd' || (TINYIB_THUMBNAIL == 'ffmpeg' && preg_match("/jpg|jpeg/", $system[0]))) {
@ -631,6 +631,43 @@ function createThumbnail($file_location, $thumb_location, $new_w, $new_h) {
}
}
if (!$spoiler) {
return true;
}
if (preg_match("/jpg|jpeg/", $system[0])) {
$src_img = imagecreatefromjpeg($thumb_location);
} else if (preg_match("/png/", $system[0])) {
$src_img = imagecreatefrompng($thumb_location);
} else if (preg_match("/gif/", $system[0])) {
$src_img = imagecreatefromgif($thumb_location);
} else {
return true;
}
if (!$src_img) {
fancyDie(__('Unable to read the uploaded file while creating its thumbnail. A common cause for this is an incorrect extension when the file is actually of a different type.'));
}
$gaussian = array(array(1.0, 2.0, 1.0), array(2.0, 4.0, 2.0), array(1.0, 2.0, 1.0));
for ($x = 1; $x <= 149; $x++) {
imageconvolution($src_img, $gaussian, 16, 0);
}
if (preg_match("/png/", $system[0])) {
if (!imagepng($src_img, $thumb_location)) {
return false;
}
} else if (preg_match("/jpg|jpeg/", $system[0])) {
if (!imagejpeg($src_img, $thumb_location, 70)) {
return false;
}
} else if (preg_match("/gif/", $system[0])) {
if (!imagegif($src_img, $thumb_location)) {
return false;
}
}
imagedestroy($src_img);
return true;
}
@ -756,7 +793,7 @@ function getEmbed($url) {
return array('', array());
}
function attachFile($post, $filepath, $filename, $uploaded) {
function attachFile($post, $filepath, $filename, $uploaded, $spoiler) {
global $tinyib_uploads;
if (!is_file($filepath) || !is_readable($filepath)) {
@ -838,7 +875,7 @@ function attachFile($post, $filepath, $filename, $uploaded) {
$post['thumb'] = $file_name_pre . 's.' . $tinyib_uploads[$file_mime][0];
list($thumb_maxwidth, $thumb_maxheight) = thumbnailDimensions($post);
if (!createThumbnail($file_src, 'thumb/' . $post['thumb'], $thumb_maxwidth, $thumb_maxheight)) {
if (!createThumbnail($file_src, 'thumb/' . $post['thumb'], $thumb_maxwidth, $thumb_maxheight, $spoiler)) {
@unlink($file_src);
fancyDie(__('Could not create thumbnail.'));
}

5
inc/html.php

@ -217,6 +217,10 @@ EOF;
$filetypes_html = '<li>' . supportedFileTypes() . '</li>';
$txt_file = __('File');
$spoiler_html = '';
if (TINYIB_SPOILERIMAGE) {
$spoiler_html = '<label><input type="checkbox" name="spoiler" value="1"> Spoiler</label>';
}
$file_input_html = <<<EOF
<tr>
<td class="postblock">
@ -224,6 +228,7 @@ EOF;
</td>
<td>
<input type="file" name="file" size="35" accesskey="f">
$spoiler_html
</td>
</tr>
EOF;

Loading…
Cancel
Save