2021-12-14 18:32:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2007-12-06 02:26:34 +00:00
|
|
|
|
2023-01-10 22:44:09 +00:00
|
|
|
namespace Shimmie2;
|
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
class PixelFileHandler extends DataHandlerExtension
|
|
|
|
{
|
2021-03-14 23:43:50 +00:00
|
|
|
protected array $SUPPORTED_MIME = [MimeType::JPEG, MimeType::GIF, MimeType::PNG, MimeType::WEBP];
|
2019-06-14 17:34:53 +00:00
|
|
|
|
2020-02-23 18:37:22 +00:00
|
|
|
protected function media_check_properties(MediaCheckPropertiesEvent $event): void
|
2019-06-25 20:17:13 +00:00
|
|
|
{
|
2023-02-22 23:37:37 +00:00
|
|
|
$filename = $event->image->get_image_filename();
|
|
|
|
$mime = $event->image->get_mime();
|
|
|
|
|
|
|
|
$event->image->lossless = Media::is_lossless($filename, $mime);
|
2020-02-23 18:37:22 +00:00
|
|
|
$event->image->audio = false;
|
2023-02-22 23:37:37 +00:00
|
|
|
switch ($mime) {
|
2020-06-14 16:05:55 +00:00
|
|
|
case MimeType::GIF:
|
2023-02-22 23:37:37 +00:00
|
|
|
$event->image->video = MimeType::is_animated_gif($filename);
|
2020-02-23 18:37:22 +00:00
|
|
|
break;
|
2020-06-14 16:05:55 +00:00
|
|
|
case MimeType::WEBP:
|
2023-02-22 23:37:37 +00:00
|
|
|
$event->image->video = MimeType::is_animated_webp($filename);
|
2020-02-23 18:37:22 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$event->image->video = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$event->image->image = !$event->image->video;
|
2019-06-25 20:17:13 +00:00
|
|
|
|
2023-02-22 23:37:37 +00:00
|
|
|
$info = getimagesize($event->image->get_image_filename());
|
2020-02-23 18:37:22 +00:00
|
|
|
if ($info) {
|
2020-01-29 20:22:50 +00:00
|
|
|
$event->image->width = $info[0];
|
|
|
|
$event->image->height = $info[1];
|
2019-06-25 20:17:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
protected function check_contents(string $tmpname): bool
|
|
|
|
{
|
2019-06-09 18:22:48 +00:00
|
|
|
$valid = [IMAGETYPE_PNG, IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_WEBP];
|
2019-05-28 16:59:38 +00:00
|
|
|
$info = getimagesize($tmpname);
|
2020-02-23 18:14:15 +00:00
|
|
|
return $info && in_array($info[2], $valid);
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
|
|
|
|
2024-01-09 04:49:19 +00:00
|
|
|
protected function create_thumb(Image $image): bool
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
2019-06-18 18:45:59 +00:00
|
|
|
try {
|
2024-01-09 04:49:19 +00:00
|
|
|
create_image_thumb($image);
|
2019-06-18 18:45:59 +00:00
|
|
|
return true;
|
2023-01-11 11:15:26 +00:00
|
|
|
} catch (\Exception $e) {
|
2024-01-09 17:59:41 +00:00
|
|
|
throw new UploadException("Error while creating thumbnail: ".$e->getMessage());
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-15 11:52:35 +00:00
|
|
|
public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
2021-04-25 10:20:55 +00:00
|
|
|
if ($event->context == "view") {
|
2024-01-19 18:57:02 +00:00
|
|
|
$event->add_part(\MicroHTML\rawHTML("
|
2021-04-25 10:20:55 +00:00
|
|
|
<form>
|
|
|
|
<select class='shm-zoomer'>
|
|
|
|
<option value='full'>Full Size</option>
|
|
|
|
<option value='width'>Fit Width</option>
|
|
|
|
<option value='height'>Fit Height</option>
|
|
|
|
<option value='both'>Fit Both</option>
|
|
|
|
</select>
|
|
|
|
</form>
|
2024-01-19 18:57:02 +00:00
|
|
|
"), 20);
|
2021-04-25 10:20:55 +00:00
|
|
|
}
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2007-12-06 02:26:34 +00:00
|
|
|
}
|