// TODO: Check whether I missed error handling somewhere during refactoring.
function readImageFromFile($path, $error_message) {
switch (pathinfo($path)["extension"]) {
case "jpg":
case "jpeg": return imagecreatefromjpeg($path);
case "png": return imagecreatefrompng($path);
case "gif": return imagecreatefromgif($path);
case "avif": return imagecreatefromavif($path);
}
fancyDie(__($error_message));
return false;
}
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.'));
}
function saveImageToFile($image, $path) {
switch (pathinfo($path)["extension"]) {
case "jpg":
case "jpeg": return imagejpeg($image, $path, 90); // why only set quality for jpegs?
fancyDie('ImageMagick is not installed, or the convert command is not in the server\'s $PATH.<br>Install ImageMagick, or set TINYIB_THUMBNAIL to \'gd\' or \'ffmpeg\'.');
function createFallbackImage($source, $destination) {
$image = readImageFromFile($source, '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.');
saveImageToFile($image, $destination);
}
function imageMagickThumbnail($file_location, $thumb_location, $new_w, $new_h) {
$discard = '';
$exit_status = 1;
exec("convert -version", $discard, $exit_status);
if ($exit_status != 0) {
fancyDie('ImageMagick is not installed, or the convert command is not in the server\'s $PATH.<br>Install ImageMagick, or set TINYIB_THUMBNAIL to \'gd\' or \'ffmpeg\'.');
function gdThumbnail($file_location, $file_extension, $thumb_location, $new_w, $new_h) {
$src_img = readImageFromFile($file_location, '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.');
function spoilerThumbnail($file_location, $thumb_location) {
// Why don't we resize images here?
$src_img = readImageFromFile($file_location, '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.');
blurImage($src_img);
saveImageToFile($src_img, $thumb_location);
imagedestroy($src_img);
}
function createThumbnail($file_location, $thumb_location, $new_w, $new_h, $spoiler) {
$path = pathinfo($file_location);
$file_extension = $path['extension'];
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.'));