ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
LegacyImageConversionTest.php
Go to the documentation of this file.
1 <?php
2 
19 namespace ILIAS\Filesystem\Util;
20 
27 
31 class LegacyImageConversionTest extends TestCase
32 {
33  private LegacyImages $images;
34 
35 
36  protected function setUp(): void
37  {
38  $this->checkImagick();
39  $this->images = new LegacyImages();
40  }
41 
42 
43  public static function someDefinitions(): array
44  {
45  return [
46  [100, 100, 'jpg', 'image/jpeg'],
47  [256, 25, 'jpg', 'image/jpeg'],
48  [1024, 5, 'jpg', 'image/jpeg'],
49  [128, 10, 'jpg', 'image/jpeg'],
50  [895, 22, 'png', 'image/png'],
51  [86, 4, 'png', 'image/png'],
52  [147, 8, 'png', 'image/png'],
53  [1000, 10, 'png', 'image/png'],
54  ];
55  }
56 
61  int $expected_height,
62  int $expected_quality,
63  string $format,
64  string $expected_mime_type
65  ): void {
66  $img = __DIR__ . '/img/robot.jpg';
67  $this->assertFileExists($img);
68 
69  $temp_file = tempnam(sys_get_temp_dir(), 'img');
70 
71  $thumbnail = $this->images->thumbnail(
72  $img,
73  $temp_file,
74  $expected_height,
75  $format,
76  $expected_quality
77  );
78 
79  $this->assertEquals($temp_file, $thumbnail);
80 
81  $test_image = new \Imagick($thumbnail);
82 
83  // PNGs do not have a quality setting which can be read by getImageCompressionQuality()
84  if ($format === 'png') {
85  $expected_quality = 0;
86  }
87 
88  $this->assertEquals($expected_quality, $test_image->getImageCompressionQuality());
89  $this->assertEquals($expected_height, $test_image->getImageHeight());
90  $this->assertEquals((int) round($expected_height * 0.75), $test_image->getImageWidth());
91  unlink($temp_file);
92  }
93 
94  protected function checkImagick(): void
95  {
96  if (!class_exists('Imagick')) {
97  $this->markTestSkipped('Imagick not installed');
98  }
99  }
100 }
testImageThumbnailActualImage(int $expected_height, int $expected_quality, string $format, string $expected_mime_type)
someDefinitions
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...