wp-optimize
/
vendor
/
rosell-dk
/
webp-convert
/
tests
/
Convert
/
Converters
/
ImageMagickTest.php
ImageMagickTest.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.5, at vendor/rosell-dk/webp-convert/tests/Convert/Converters/ImageMagickTest.php
| 1 | <?php |
| 2 | /** |
| 3 | * WebPConvert - Convert JPEG & PNG to WebP with PHP |
| 4 | * |
| 5 | * @link https://github.com/rosell-dk/webp-convert |
| 6 | * @license MIT |
| 7 | */ |
| 8 | |
| 9 | namespace WebPConvert\Tests\Convert\Converters; |
| 10 | |
| 11 | use WebPConvert\Convert\Converters\ImageMagick; |
| 12 | use WebPConvert\Convert\Exceptions\ConversionFailed\ConverterNotOperationalException; |
| 13 | use WebPConvert\Loggers\BufferLogger; |
| 14 | |
| 15 | use PHPUnit\Framework\TestCase; |
| 16 | |
| 17 | class ImageMagickTest extends TestCase |
| 18 | { |
| 19 | |
| 20 | public static function getImageFolder() |
| 21 | { |
| 22 | return realpath(__DIR__ . '/../../images'); |
| 23 | } |
| 24 | |
| 25 | public static function getImagePath($image) |
| 26 | { |
| 27 | return self::getImageFolder() . '/' . $image; |
| 28 | } |
| 29 | |
| 30 | public function testConvert() |
| 31 | { |
| 32 | ConverterTestHelper::runAllConvertTests($this, 'ImageMagick'); |
| 33 | } |
| 34 | |
| 35 | private static function tryThis($test, $source, $options) |
| 36 | { |
| 37 | $bufferLogger = new BufferLogger(); |
| 38 | |
| 39 | try { |
| 40 | ImageMagick::convert($source, $source . '.webp', $options, $bufferLogger); |
| 41 | |
| 42 | $test->addToAssertionCount(1); |
| 43 | } catch (ConversionFailedException $e) { |
| 44 | |
| 45 | //$bufferLogger->getText() |
| 46 | throw $e; |
| 47 | } catch (ConverterNotOperationalException $e) { |
| 48 | // (SystemRequirementsNotMetException is also a ConverterNotOperationalException) |
| 49 | // this is ok. |
| 50 | return; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | public function testWithNice() { |
| 55 | $source = self::getImagePath('test.png'); |
| 56 | $options = [ |
| 57 | 'use-nice' => true, |
| 58 | 'encoding' => 'lossless', |
| 59 | ]; |
| 60 | self::tryThis($this, $source, $options); |
| 61 | } |
| 62 | |
| 63 | } |
| 64 |