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