Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [Images] add AVIF support #8713

Closed
wants to merge 10 commits into from
2 changes: 1 addition & 1 deletion app/Config/Publisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ class Publisher extends BasePublisher
*/
public $restrictions = [
ROOTPATH => '*',
FCPATH => '#\.(s?css|js|map|html?|xml|json|webmanifest|ttf|eot|woff2?|gif|jpe?g|tiff?|png|webp|bmp|ico|svg)$#i',
FCPATH => '#\.(s?css|js|map|html?|xml|json|webmanifest|ttf|eot|woff2?|gif|jpe?g|tiff?|png|webp|avif|bmp|ico|svg)$#i',
];
}
4 changes: 2 additions & 2 deletions system/Database/BaseResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ public function getResultObject(): array
* @param string $type The type of result object. 'array', 'object' or class name.
* @phpstan-param class-string<T>|'array'|'object' $type
*
* @return array|object|stdClass|null
* @phpstan-return ($type is 'object' ? stdClass|null : ($type is 'array' ? array|null : T|null))
* @return array|float|int|object|stdClass|string|null
* @phpstan-return ($n is string ? float|int|string|null : ($type is 'object' ? stdClass|null : ($type is 'array' ? array|null : T|null)))
*/
public function getRow($n = 0, string $type = 'object')
{
Expand Down
4 changes: 2 additions & 2 deletions system/Database/ResultInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public function getResultObject(): array;
* @param string $type The type of result object. 'array', 'object' or class name.
* @phpstan-param class-string<T>|'array'|'object' $type
*
* @return array|object|stdClass|null
* @phpstan-return ($type is 'object' ? stdClass|null : ($type is 'array' ? array|null : T|null))
* @return array|float|int|object|stdClass|string|null
* @phpstan-return ($n is string ? float|int|string|null : ($type is 'object' ? stdClass|null : ($type is 'array' ? array|null : T|null)))
*/
public function getRow($n = 0, string $type = 'object');

Expand Down
1 change: 1 addition & 0 deletions system/Images/Handlers/BaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ abstract class BaseHandler implements ImageHandlerInterface
protected $supportTransparency = [
IMAGETYPE_PNG,
IMAGETYPE_WEBP,
IMAGETYPE_AVIF,
];

/**
Expand Down
17 changes: 17 additions & 0 deletions system/Images/Handlers/GDHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,16 @@ public function save(?string $target = null, int $quality = 90): bool
}
break;

case IMAGETYPE_AVIF:
if (! function_exists('imageavif')) {
throw ImageException::forInvalidImageCreate(lang('Images.avifNotSupported'));
}

if (! @imagewebp($this->resource, $target, $quality)) {
throw ImageException::forSaveFailed();
}
break;

default:
throw ImageException::forInvalidImageCreate();
}
Expand Down Expand Up @@ -365,6 +375,13 @@ protected function getImageResource(string $path, int $imageType)
}

return imagecreatefromwebp($path);

case IMAGETYPE_AVIF:
if (! function_exists('imagecreatefromavif')) {
throw ImageException::forInvalidImageCreate(lang('Images.avifNotSupported'));
}

return imagecreatefromavif($path);

default:
throw ImageException::forInvalidImageCreate('Ima');
Expand Down
1 change: 1 addition & 0 deletions system/Images/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public function getProperties(bool $return = false)
IMAGETYPE_JPEG => 'jpeg',
IMAGETYPE_PNG => 'png',
IMAGETYPE_WEBP => 'webp',
IMAGETYPE_AVIF => 'avif',
];

$mime = 'image/' . ($types[$vals[2]] ?? 'jpg');
Expand Down
1 change: 1 addition & 0 deletions system/Language/en/Images.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
'jpgNotSupported' => 'JPG images are not supported.',
'pngNotSupported' => 'PNG images are not supported.',
'webpNotSupported' => 'WEBP images are not supported.',
'avifNotSupported' => 'AVIF images are not supported.',
'fileNotSupported' => 'The supplied file is not a supported image type.',
'unsupportedImageCreate' => 'Your server does not support the GD function required to process this type of image.',
'jpgOrPngRequired' => 'The image resize protocol specified in your preferences only works with JPEG or PNG image types.',
Expand Down
Loading