torrentpier/library/attach_mod/includes/functions_thumbs.php
Roman Kelesidis 3626143879
Replaced some file exists to is file (#1276)
* Replaced some file_exists to is_file

* Update functions_thumbs.php

* Updated

* Update CronHelper.php

* Updated

* Update IPHelper.php

* Updated

* Update update_forums_atom.php

* Update functions.php

* Update Validate.php
2023-12-27 20:08:00 +07:00

58 lines
1.4 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* TorrentPier Bull-powered BitTorrent tracker engine
*
* @copyright Copyright (c) 2005-2024 TorrentPier (https://torrentpier.com)
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
*/
if (!defined('BB_ROOT')) {
die(basename(__FILE__));
}
/**
* Create thumbnail
*
* @param string $source
* @param string $newFile
* @param string $mimeType
* @return bool
* @throws Exception
*/
function createThumbnail(string $source, string $newFile, string $mimeType): bool
{
global $attach_config;
// Check for source image existence
if (!$source = realpath($source)) {
return false;
}
// Checks the max allowed filesize
$min_filesize = (int)$attach_config['img_min_thumb_filesize'];
if (!filesize($source) || filesize($source) <= $min_filesize) {
return false;
}
// Making the thumbnail image
try {
$image = new \claviska\SimpleImage();
$image
->fromFile($source)
->autoOrient()
->resize(150)
->toFile($newFile, $mimeType, ['quality' => 85]);
} catch (Exception $e) {
// Handle errors
throw new Exception($e->getMessage());
}
// Check the thumbnail existence after creating
if (!is_file($newFile)) {
return false;
}
return true;
}