Skip to content

Commit

Permalink
[handle_pixel] avif support, fixes #1302
Browse files Browse the repository at this point in the history
  • Loading branch information
shish committed Dec 10, 2024
1 parent 497083a commit 9f5f781
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ FROM unit:php8.3 AS base
RUN apt update && \
apt upgrade -y && \
apt install -y --no-install-recommends \
curl rsync imagemagick zip unzip libpq-dev libpng-dev libjpeg-dev libzip-dev libwebp-dev && \
curl rsync imagemagick zip unzip libpq-dev libpng-dev libjpeg-dev libzip-dev libwebp-dev libavif-dev && \
rm -rf /var/lib/apt/lists/*
RUN pecl install redis-6.1.0 && docker-php-ext-enable redis
RUN pecl install apcu-5.1.24 && docker-php-ext-enable apcu
RUN apt-get update && apt-get install -y libmemcached-dev libssl-dev zlib1g-dev && \
pecl install memcached-3.3.0 && docker-php-ext-enable memcached
RUN docker-php-ext-configure gd --with-jpeg --with-webp && \
RUN docker-php-ext-configure gd --with-jpeg --with-webp --with-avif && \
docker-php-ext-install gd
RUN docker-php-ext-install mysqli pgsql pdo pdo_mysql pdo_pgsql zip pcntl

Expand Down
2 changes: 1 addition & 1 deletion ext/handle_pixel/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ class PixelFileHandlerInfo extends ExtensionInfo
public string $url = self::SHIMMIE_URL;
public array $authors = self::SHISH_AUTHOR;
public ExtensionCategory $category = ExtensionCategory::FILE_HANDLING;
public string $description = "Handle JPEG, PNG, GIF, WEBP, etc files";
public string $description = "Handle JPEG, PNG, GIF, and similar files";
public bool $core = true;
}
10 changes: 8 additions & 2 deletions ext/handle_pixel/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@

class PixelFileHandler extends DataHandlerExtension
{
protected array $SUPPORTED_MIME = [MimeType::JPEG, MimeType::GIF, MimeType::PNG, MimeType::WEBP];
protected array $SUPPORTED_MIME = [
MimeType::JPEG,
MimeType::GIF,
MimeType::PNG,
MimeType::WEBP,
MimeType::AVIF,
];

protected function media_check_properties(MediaCheckPropertiesEvent $event): void
{
Expand Down Expand Up @@ -37,7 +43,7 @@ protected function media_check_properties(MediaCheckPropertiesEvent $event): voi

protected function check_contents(string $tmpname): bool
{
$valid = [IMAGETYPE_PNG, IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_WEBP];
$valid = [IMAGETYPE_PNG, IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_WEBP, IMAGETYPE_AVIF];
$info = getimagesize($tmpname);
return $info && in_array($info[2], $valid);
}
Expand Down
2 changes: 2 additions & 0 deletions ext/handle_pixel/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public static function formatList(): array
["jpeg"],
["png"],
["gif"],
["webp"],
["avif"],
];
}

Expand Down
7 changes: 6 additions & 1 deletion ext/media/media_engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ abstract class MediaEngine
MimeType::GIF,
MimeType::JPEG,
MimeType::PNG,
MimeType::WEBP
MimeType::WEBP,
MimeType::AVIF,
],
MediaEngine::IMAGICK => [
MimeType::GIF,
MimeType::JPEG,
MimeType::PNG,
MimeType::WEBP,
MimeType::WEBP_LOSSLESS,
MimeType::AVIF,
],
MediaEngine::FFMPEG => [
MimeType::JPEG,
Expand All @@ -54,6 +56,7 @@ abstract class MediaEngine
MimeType::TGA,
MimeType::WEBP,
MimeType::WEBP_LOSSLESS,
MimeType::AVIF,
],
MediaEngine::IMAGICK => [
MimeType::BMP,
Expand All @@ -67,6 +70,7 @@ abstract class MediaEngine
MimeType::WEBP,
MimeType::WEBP_LOSSLESS,
MimeType::ICO,
MimeType::AVIF,
],
MediaEngine::FFMPEG => [
MimeType::AVI,
Expand All @@ -80,6 +84,7 @@ abstract class MediaEngine
MimeType::JPEG,
MimeType::GIF,
MimeType::PNG,
MimeType::AVIF,
],
];
public const RESIZE_TYPE_SUPPORT = [
Expand Down
1 change: 1 addition & 0 deletions ext/mime/file_extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class FileExtension
public const ASF = 'asf';
public const ASX = 'asx';
public const AVI = 'avi';
public const AVIF = 'avif';
public const BMP = 'bmp';
public const BZIP = 'bz';
public const BZIP2 = 'bz2';
Expand Down
5 changes: 5 additions & 0 deletions ext/mime/mime_map.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ class MimeMap
self::MAP_EXT => [FileExtension::AVI],
self::MAP_MIME => [MimeType::AVI, 'video/avi', 'video/msvideo'],
],
MimeType::AVIF => [
self::MAP_NAME => "AVIF",
self::MAP_EXT => [FileExtension::AVIF],
self::MAP_MIME => [MimeType::AVIF],
],
MimeType::ASF => [
self::MAP_NAME => "ASF/WMV",
self::MAP_EXT => [FileExtension::ASF, FileExtension::ASX, FileExtension::WMA, FileExtension::WMV],
Expand Down
1 change: 1 addition & 0 deletions ext/mime/mime_type.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class MimeType
public const ANI = 'application/riff+ani';
public const ASF = 'video/x-ms-asf';
public const AVI = 'video/x-msvideo';
public const AVIF = 'image/avif';
// Went with mime types from http://fileformats.archiveteam.org/wiki/Comic_Book_Archive
public const COMIC_ZIP = 'application/vnd.comicbook+zip';
public const COMIC_RAR = 'application/vnd.comicbook-rar';
Expand Down

0 comments on commit 9f5f781

Please sign in to comment.