mirror of
https://framagit.org/hubzilla/core.git
synced 2026-06-21 00:52:33 -04:00
Add AVIF support for PhotoImagick
It seems AVIF support was added to the GD photo driver, but not ImageMagick. This patch adds it to ImageMagick as well, if supported by the underlying library. I also added pecl imagick extension to CI so that we can test it.
This commit is contained in:
@@ -89,9 +89,9 @@ default:
|
||||
before_script:
|
||||
# Install & enable Xdebug for code coverage reports
|
||||
- apt-get update
|
||||
- apt-get install -yqq libicu-dev libjpeg-dev libpng-dev libpq-dev libyaml-dev libgmp-dev libzip-dev mariadb-client postgresql-client unzip zip
|
||||
- pecl install xdebug yaml
|
||||
- docker-php-ext-enable xdebug yaml
|
||||
- apt-get install -yqq libicu-dev libjpeg-dev libpng-dev libpq-dev libyaml-dev libgmp-dev libzip-dev mariadb-client postgresql-client libmagickcore-7.q16-dev libmagickwand-dev unzip zip
|
||||
- pecl install imagick xdebug yaml
|
||||
- docker-php-ext-enable imagick xdebug yaml
|
||||
- docker-php-ext-configure gd --with-jpeg=/usr/include/
|
||||
- docker-php-ext-install gd gmp intl pdo_mysql pdo_pgsql zip exif
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Zotlabs\Photo;
|
||||
|
||||
use Imagick;
|
||||
use Zotlabs\Lib\Config;
|
||||
|
||||
/**
|
||||
@@ -16,8 +17,14 @@ class PhotoImagick extends PhotoDriver {
|
||||
'image/png' => 'png',
|
||||
'image/gif' => 'gif'
|
||||
];
|
||||
if(\Imagick::queryFormats("WEBP"))
|
||||
|
||||
if (Imagick::queryFormats('WEBP')) {
|
||||
$ret['image/webp'] = 'webp';
|
||||
}
|
||||
|
||||
if (Imagick::queryFormats('AVIF')) {
|
||||
$ret['image/avif'] = 'avif';
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
43
tests/unit/Photo/PhotoMagickTest.php
Normal file
43
tests/unit/Photo/PhotoMagickTest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2026 The Hubzilla Community
|
||||
* SPDX-FileContributor: Harald Eilertsen <haraldei@anduin.net>
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
namespace Zotlabs\Tests\Unit\Photo;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Zotlabs\Photo\PhotoImagick;
|
||||
|
||||
class PhotoMagickTest extends TestCase
|
||||
{
|
||||
public function testSupportedFormats(): void {
|
||||
$ph = new PhotoImagick(null, null);
|
||||
|
||||
$types = $ph->supportedTypes();
|
||||
|
||||
$this->assertEquals('webp', $types['image/webp']);
|
||||
$this->assertEquals('avif', $types['image/avif']);
|
||||
$this->assertEquals('gif', $types['image/gif']);
|
||||
$this->assertEquals('jpg', $types['image/jpeg']);
|
||||
$this->assertEquals('png', $types['image/png']);
|
||||
}
|
||||
|
||||
public function testInitializingWithImage(): void {
|
||||
$data = file_get_contents('images/hz-16.png');
|
||||
|
||||
// If no type is given, make it a jpeg, regardless of input format.
|
||||
$ph = new PhotoImagick($data);
|
||||
$this->assertEquals('image/jpeg', $ph->getType());
|
||||
|
||||
$formats = $ph->supportedTypes();
|
||||
|
||||
// When a type is givem the image should be given that type.
|
||||
foreach($formats as $format => $ext) {
|
||||
$ph = new PhotoImagick($data, $format);
|
||||
$this->assertEquals($format, $ph->getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user