ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ILIAS\Filesystem\Util\ImageConversionTest Class Reference
+ Inheritance diagram for ILIAS\Filesystem\Util\ImageConversionTest:
+ Collaboration diagram for ILIAS\Filesystem\Util\ImageConversionTest:

Public Member Functions

 testImageThumbnailActualImage ()
 
 testImageSquareActualImage ()
 
 testResizeToFitWidth (int $width, int $height, int $final_width, int $final_height)
 getImageSizesByWidth More...
 
 testResizeToFitHeight (int $width, int $height, int $final_height, int $final_width)
 getImageSizesByHeight More...
 
 testResizeByFixedSize (int $width, int $height, int $final_width, int $final_height, bool $crop)
 getImageSizesByFixed More...
 
 testImageOutputOptions (ImageOutputOptions $options, string $expected_mime_type, int $expected_quality)
 getImageOptions More...
 
 testImageOutputOptionSanity ()
 
 testWrongFormats (string $format)
 getWrongFormats More...
 
 testWrongQualities (int $quality)
 getWrongQualites More...
 
 testFormatConvert ()
 
 testFailed ()
 
 testBackgroundColor (?string $color)
 getColors More...
 
 testWriteImage ()
 
 testHighDensityPixel ()
 

Static Public Member Functions

static getImageSizesByWidth ()
 
static getImageSizesByHeight ()
 
static getImageSizesByFixed ()
 
static getImageOptions ()
 
static getWrongFormats ()
 
static getWrongQualites ()
 
static getColors ()
 

Protected Member Functions

 setUp ()
 
 checkImagick ()
 
 getImageSizeFromStream (FileStream $stream)
 
 getImageTypeFromStream (FileStream $stream)
 
 getImageQualityFromStream (FileStream $stream)
 
 createTestImageStream (int $width, int $height)
 

Protected Attributes

const BY_WIDTH_FINAL = 256
 
const BY_HEIGHT_FINAL = 756
 
const W = 'width'
 
const H = 'height'
 
const IMAGE_JPEG = 'image/jpeg'
 
const IMAGE_PNG = 'image/png'
 
const IMAGE_WEBP = 'image/webp'
 
Images $images
 

Private Member Functions

 colorDiff (string $hex_color_one, string $hex_color_two)
 

Detailed Description

Author
Fabian Schmid fabia.nosp@m.n@sr.nosp@m..solu.nosp@m.tion.nosp@m.s

Definition at line 33 of file ImageConversionTest.php.

Member Function Documentation

◆ checkImagick()

ILIAS\Filesystem\Util\ImageConversionTest::checkImagick ( )
protected

Definition at line 510 of file ImageConversionTest.php.

Referenced by ILIAS\Filesystem\Util\ImageConversionTest\setUp().

510  : void
511  {
512  if (!class_exists('Imagick')) {
513  $this->markTestSkipped('Imagick not installed');
514  }
515  }
+ Here is the caller graph for this function:

◆ colorDiff()

ILIAS\Filesystem\Util\ImageConversionTest::colorDiff ( string  $hex_color_one,
string  $hex_color_two 
)
private

Definition at line 411 of file ImageConversionTest.php.

Referenced by ILIAS\Filesystem\Util\ImageConversionTest\testBackgroundColor().

411  : int
412  {
413  preg_match('/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i', $hex_color_one, $rgb_one);
414  preg_match('/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i', $hex_color_two, $rgb_two);
415 
416  return abs(hexdec($rgb_one[1]) - hexdec($rgb_two[1]))
417  + abs(hexdec($rgb_one[2]) - hexdec($rgb_two[2]))
418  + abs(hexdec($rgb_one[3]) - hexdec($rgb_two[3]));
419  }
+ Here is the caller graph for this function:

◆ createTestImageStream()

ILIAS\Filesystem\Util\ImageConversionTest::createTestImageStream ( int  $width,
int  $height 
)
protected

Definition at line 540 of file ImageConversionTest.php.

Referenced by ILIAS\Filesystem\Util\ImageConversionTest\testFormatConvert(), ILIAS\Filesystem\Util\ImageConversionTest\testImageOutputOptions(), ILIAS\Filesystem\Util\ImageConversionTest\testResizeByFixedSize(), ILIAS\Filesystem\Util\ImageConversionTest\testResizeToFitHeight(), ILIAS\Filesystem\Util\ImageConversionTest\testResizeToFitWidth(), and ILIAS\Filesystem\Util\ImageConversionTest\testWriteImage().

540  : FileStream
541  {
542  $img = new \Imagick();
543  $img->newImage($width, $height, new \ImagickPixel('black'));
544  $img->setImageFormat('jpg');
545 
546  $stream = Streams::ofString($img->getImageBlob());
547  $stream->rewind();
548  return $stream;
549  }
+ Here is the caller graph for this function:

◆ getColors()

static ILIAS\Filesystem\Util\ImageConversionTest::getColors ( )
static

Definition at line 393 of file ImageConversionTest.php.

393  : array
394  {
395  return [
396  [null],
397  ['#000000'],
398  ['#ff0000'],
399  ['#00ff00'],
400  ['#0000ff'],
401  ['#ffffff'],
402  ['#A3BF5A'],
403  ['#E9745A'],
404  ['#5A5AE9'],
405  ['#5AE9E9'],
406  ['#E95AE9'],
407  ['#E9E95A'],
408  ];
409  }

◆ getImageOptions()

static ILIAS\Filesystem\Util\ImageConversionTest::getImageOptions ( )
static

Definition at line 245 of file ImageConversionTest.php.

245  : array
246  {
247  $options = new ImageOutputOptions();
248  return [
249  [$options, self::IMAGE_JPEG, 75],
250  [$options->withPngOutput()->withQuality(22), self::IMAGE_PNG, 0],
251  [$options->withJpgOutput()->withQuality(100), self::IMAGE_JPEG, 100],
252  [$options->withFormat('png')->withQuality(50), self::IMAGE_PNG, 0],
253  [$options->withFormat('jpg')->withQuality(87), self::IMAGE_JPEG, 87],
254  [$options->withQuality(5)->withJpgOutput(), self::IMAGE_JPEG, 5],
255  [$options->withQuality(10)->withJpgOutput(), self::IMAGE_JPEG, 10],
256  [$options->withQuality(35)->withJpgOutput(), self::IMAGE_JPEG, 35],
257  [$options->withQuality(0)->withWebPOutput(), self::IMAGE_WEBP, 0],
258  [$options->withQuality(100)->withWebPOutput(), self::IMAGE_WEBP, 100],
259  ];
260  }

◆ getImageQualityFromStream()

ILIAS\Filesystem\Util\ImageConversionTest::getImageQualityFromStream ( FileStream  $stream)
protected

Definition at line 531 of file ImageConversionTest.php.

Referenced by ILIAS\Filesystem\Util\ImageConversionTest\testImageOutputOptions().

531  : int
532  {
533  $stream->rewind();
534  $img = new \Imagick();
535  $img->readImageBlob((string) $stream);
536 
537  return $img->getImageCompressionQuality();
538  }
+ Here is the caller graph for this function:

◆ getImageSizeFromStream()

ILIAS\Filesystem\Util\ImageConversionTest::getImageSizeFromStream ( FileStream  $stream)
protected

Definition at line 517 of file ImageConversionTest.php.

References ILIAS\Repository\int().

Referenced by ILIAS\Filesystem\Util\ImageConversionTest\testFormatConvert(), ILIAS\Filesystem\Util\ImageConversionTest\testImageSquareActualImage(), ILIAS\Filesystem\Util\ImageConversionTest\testResizeByFixedSize(), ILIAS\Filesystem\Util\ImageConversionTest\testResizeToFitHeight(), and ILIAS\Filesystem\Util\ImageConversionTest\testResizeToFitWidth().

517  : array
518  {
519  $getimagesizefromstring = getimagesizefromstring((string) $stream);
520  return [
521  self::W => (int) round($getimagesizefromstring[0]),
522  self::H => (int) round($getimagesizefromstring[1])
523  ];
524  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getImageSizesByFixed()

static ILIAS\Filesystem\Util\ImageConversionTest::getImageSizesByFixed ( )
static

Definition at line 210 of file ImageConversionTest.php.

210  : array
211  {
212  return [
213  [1024, 768, 300, 100, true],
214  [1024, 768, 300, 100, false],
215  [1024, 768, 100, 300, true],
216  [1024, 768, 100, 300, false],
217  [400, 300, 500, 400, true],
218  [400, 300, 500, 400, false],
219  ];
220  }

◆ getImageSizesByHeight()

static ILIAS\Filesystem\Util\ImageConversionTest::getImageSizesByHeight ( )
static

Definition at line 158 of file ImageConversionTest.php.

158  : array
159  {
160  return [
161  [400, 300, self::BY_HEIGHT_FINAL, 1008],
162  [300, 400, self::BY_HEIGHT_FINAL, 567],
163  [200, 200, self::BY_HEIGHT_FINAL, 756],
164  [248, 845, self::BY_HEIGHT_FINAL, 221],
165  ];
166  }

◆ getImageSizesByWidth()

static ILIAS\Filesystem\Util\ImageConversionTest::getImageSizesByWidth ( )
static

Definition at line 107 of file ImageConversionTest.php.

107  : array
108  {
109  return [
110  [400, 300, self::BY_WIDTH_FINAL, 192],
111  [300, 400, self::BY_WIDTH_FINAL, 341],
112  [543, 431, self::BY_WIDTH_FINAL, 203],
113  [200, 200, self::BY_WIDTH_FINAL, 256],
114  ];
115  }

◆ getImageTypeFromStream()

ILIAS\Filesystem\Util\ImageConversionTest::getImageTypeFromStream ( FileStream  $stream)
protected

Definition at line 526 of file ImageConversionTest.php.

Referenced by ILIAS\Filesystem\Util\ImageConversionTest\testFormatConvert(), and ILIAS\Filesystem\Util\ImageConversionTest\testImageOutputOptions().

526  : string
527  {
528  return finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $stream->read(255));
529  }
+ Here is the caller graph for this function:

◆ getWrongFormats()

static ILIAS\Filesystem\Util\ImageConversionTest::getWrongFormats ( )
static

Definition at line 310 of file ImageConversionTest.php.

310  : array
311  {
312  return [
313  ['gif'],
314  ['bmp'],
315  ['jpg2000'],
316  ];
317  }

◆ getWrongQualites()

static ILIAS\Filesystem\Util\ImageConversionTest::getWrongQualites ( )
static

Definition at line 329 of file ImageConversionTest.php.

329  : array
330  {
331  return [
332  [-1],
333  [101],
334  [102],
335  ];
336  }

◆ setUp()

ILIAS\Filesystem\Util\ImageConversionTest::setUp ( )
protected

Definition at line 46 of file ImageConversionTest.php.

References ILIAS\Filesystem\Util\ImageConversionTest\checkImagick().

46  : void
47  {
48  $this->checkImagick();
49  $this->images = new Images(
50  true,
51  );
52  }
+ Here is the call graph for this function:

◆ testBackgroundColor()

ILIAS\Filesystem\Util\ImageConversionTest::testBackgroundColor ( ?string  $color)

getColors

Definition at line 424 of file ImageConversionTest.php.

References ILIAS\Filesystem\Util\ImageConversionTest\colorDiff().

424  : void
425  {
426  $transparent_png = __DIR__ . '/img/transparent.png';
427  $this->assertFileExists($transparent_png);
428  $png = Streams::ofResource(fopen($transparent_png, 'rb'));
429 
430  $converter_options = (new ImageConversionOptions())
431  ->withThrowOnError(true)
432  ->withFixedDimensions(100, 100);
433 
434  if ($color !== null) {
435  $converter_options = $converter_options->withBackgroundColor($color);
436  } else {
437  $color = '#ffffff';
438  }
439 
440  $output_options = (new ImageOutputOptions())
441  ->withQuality(100)
442  ->withJpgOutput();
443 
444  $converter = new ImageConverter($converter_options, $output_options, $png);
445  $this->assertTrue($converter->isOK());
446  $converted_stream = $converter->getStream();
447  $gd_image = imagecreatefromstring((string) $converted_stream);
448  $colors = imagecolorsforindex($gd_image, imagecolorat($gd_image, 1, 1));
449 
450  $color_in_converted_picture = sprintf("#%02x%02x%02x", $colors['red'], $colors['green'], $colors['blue']);
451  $color_diff = $this->colorDiff($color, $color_in_converted_picture);
452 
453  $this->assertLessThan(3, $color_diff);
454  }
colorDiff(string $hex_color_one, string $hex_color_two)
+ Here is the call graph for this function:

◆ testFailed()

ILIAS\Filesystem\Util\ImageConversionTest::testFailed ( )

Definition at line 376 of file ImageConversionTest.php.

376  : void
377  {
378  $false_stream = Streams::ofString('false');
379  $images = new Images(
380  false,
381  false
382  );
383 
384  $resized = $images->resizeToFixedSize(
385  $false_stream,
386  5,
387  5
388  );
389  $this->assertFalse($resized->isOK());
390  $this->assertInstanceOf(\Throwable::class, $resized->getThrowableIfAny());
391  }

◆ testFormatConvert()

ILIAS\Filesystem\Util\ImageConversionTest::testFormatConvert ( )

Definition at line 348 of file ImageConversionTest.php.

References ILIAS\Filesystem\Util\ImageConversionTest\createTestImageStream(), ILIAS\Filesystem\Util\ImageConversionTest\getImageSizeFromStream(), and ILIAS\Filesystem\Util\ImageConversionTest\getImageTypeFromStream().

348  : void
349  {
350  $jpg = $this->createTestImageStream(10, 10);
351  $png = $this->images->convertToFormat(
352  $jpg,
353  'png'
354  );
355 
356  $this->assertEquals(self::IMAGE_PNG, $this->getImageTypeFromStream($png->getStream()));
357  $size = $this->getImageSizeFromStream($png->getStream());
358  $this->assertEquals(10, $size[self::W]);
359  $this->assertEquals(10, $size[self::H]);
360 
361  // With Dimensions
362  $jpg = $this->createTestImageStream(10, 10);
363  $png = $this->images->convertToFormat(
364  $jpg,
365  'png',
366  20,
367  20
368  );
369 
370  $this->assertEquals(self::IMAGE_PNG, $this->getImageTypeFromStream($png->getStream()));
371  $size = $this->getImageSizeFromStream($png->getStream());
372  $this->assertEquals(20, $size[self::W]);
373  $this->assertEquals(20, $size[self::H]);
374  }
+ Here is the call graph for this function:

◆ testHighDensityPixel()

ILIAS\Filesystem\Util\ImageConversionTest::testHighDensityPixel ( )

Definition at line 481 of file ImageConversionTest.php.

481  : void
482  {
483  $file = 'https://upload.wikimedia.org/wikipedia/commons/5/5e/Jan_Vermeer_-_The_Art_of_Painting_-_Google_Art_Project.jpg';
484  $curl = curl_init();
485  curl_setopt($curl, CURLOPT_URL, $file);
486  curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
487  curl_setopt($curl, CURLOPT_USERAGENT, 'PHPUnit/1.0');
488  $string = curl_exec($curl);
489  curl_close($curl);
490 
491  $img = Streams::ofString($string);
492  $this->assertInstanceOf(FileStream::class, $img);
493 
494  $converter_options = (new ImageConversionOptions())
495  ->withWidth(80)
496  ->withHeight(80)
497  ->withKeepAspectRatio(true)
498  ->withCrop(true)
499  ->withThrowOnError(true);
500 
501  $output_options = (new ImageOutputOptions())
502  ->withQuality(60)
503  ->withFormat(ImageOutputOptions::FORMAT_PNG);
504 
505  $converter = new ImageConverter($converter_options, $output_options, $img);
506  $this->assertTrue($converter->isOK());
507  }

◆ testImageOutputOptions()

ILIAS\Filesystem\Util\ImageConversionTest::testImageOutputOptions ( ImageOutputOptions  $options,
string  $expected_mime_type,
int  $expected_quality 
)

getImageOptions

Definition at line 266 of file ImageConversionTest.php.

References ILIAS\Filesystem\Util\ImageConversionTest\createTestImageStream(), ILIAS\Filesystem\Util\ImageConversionTest\getImageQualityFromStream(), and ILIAS\Filesystem\Util\ImageConversionTest\getImageTypeFromStream().

270  : void {
271  $resized = $this->images->resizeToFixedSize(
272  $this->createTestImageStream(10, 10),
273  5,
274  5,
275  true,
276  $options
277  );
278 
279  $this->assertEquals($expected_mime_type, $this->getImageTypeFromStream($resized->getStream()));
280  $this->assertEquals($expected_quality, $this->getImageQualityFromStream($resized->getStream()));
281  }
+ Here is the call graph for this function:

◆ testImageOutputOptionSanity()

ILIAS\Filesystem\Util\ImageConversionTest::testImageOutputOptionSanity ( )

Definition at line 283 of file ImageConversionTest.php.

283  : void
284  {
285  $options = new ImageOutputOptions();
286 
287  // Defaults
288  $this->assertEquals('jpg', $options->getFormat());
289  $this->assertEquals(75, $options->getQuality());
290 
291  $png = $options->withPngOutput();
292  $this->assertEquals('png', $png->getFormat());
293  $this->assertEquals('jpg', $options->getFormat()); // original options should not change
294  $png_explicit = $options->withFormat('png');
295  $this->assertEquals('png', $png_explicit->getFormat());
296 
297  $jpg = $options->withJpgOutput();
298  $this->assertEquals('jpg', $jpg->getFormat());
299  $jpg_explicit = $options->withFormat('jpg');
300  $this->assertEquals('jpg', $jpg_explicit->getFormat());
301  $jpeg = $options->withFormat('jpeg');
302  $this->assertEquals('jpg', $jpeg->getFormat());
303 
304  // Quality
305  $low = $options->withQuality(5);
306  $this->assertEquals(5, $low->getQuality());
307  $this->assertEquals(75, $options->getQuality()); // original options should not change
308  }

◆ testImageSquareActualImage()

ILIAS\Filesystem\Util\ImageConversionTest::testImageSquareActualImage ( )

Definition at line 81 of file ImageConversionTest.php.

References ILIAS\Filesystem\Util\ImageConversionTest\getImageSizeFromStream().

81  : void
82  {
83  $img = __DIR__ . '/img/robot.jpg';
84  $this->assertFileExists($img);
85  $getimagesize = getimagesize($img);
86  $original_width = $getimagesize[0]; // should be 600
87  $original_height = $getimagesize[1]; // should be 800
88  $this->assertEquals(600, $original_width);
89  $this->assertEquals(800, $original_height);
90 
91  // make tumbnail
92  $original_stream = Streams::ofResource(fopen($img, 'rb'));
93 
94  $thumbnail_converter = $this->images->croppedSquare(
95  $original_stream,
96  200
97  );
98  $this->assertTrue($thumbnail_converter->isOK());
99  $this->assertNull($thumbnail_converter->getThrowableIfAny());
100 
101  $getimagesizefromstring = $this->getImageSizeFromStream($thumbnail_converter->getStream());
102 
103  $this->assertEquals(200, $getimagesizefromstring[self::W]);
104  $this->assertEquals(200, $getimagesizefromstring[self::H]);
105  }
+ Here is the call graph for this function:

◆ testImageThumbnailActualImage()

ILIAS\Filesystem\Util\ImageConversionTest::testImageThumbnailActualImage ( )

Definition at line 54 of file ImageConversionTest.php.

54  : void
55  {
56  $img = __DIR__ . '/img/robot.jpg';
57  $this->assertFileExists($img);
58  $getimagesize = getimagesize($img);
59  $original_width = $getimagesize[0]; // should be 600
60  $original_height = $getimagesize[1]; // should be 800
61  $this->assertEquals(600, $original_width);
62  $this->assertEquals(800, $original_height);
63 
64  // make tumbnail
65  $original_stream = Streams::ofResource(fopen($img, 'rb'));
66 
67  $thumbnail_converter = $this->images->thumbnail(
68  $original_stream,
69  100
70  );
71  $this->assertTrue($thumbnail_converter->isOK());
72  $this->assertNull($thumbnail_converter->getThrowableIfAny());
73  $converted_stream = $thumbnail_converter->getStream();
74 
75  $getimagesizefromstring = getimagesizefromstring((string) $converted_stream);
76 
77  $this->assertEquals(75, $getimagesizefromstring[0]); // width
78  $this->assertEquals(100, $getimagesizefromstring[1]); // height
79  }

◆ testResizeByFixedSize()

ILIAS\Filesystem\Util\ImageConversionTest::testResizeByFixedSize ( int  $width,
int  $height,
int  $final_width,
int  $final_height,
bool  $crop 
)

getImageSizesByFixed

Definition at line 225 of file ImageConversionTest.php.

References ILIAS\Filesystem\Util\ImageConversionTest\createTestImageStream(), and ILIAS\Filesystem\Util\ImageConversionTest\getImageSizeFromStream().

231  : void {
232  $stream = $this->createTestImageStream($width, $height);
233  $dimensions = $this->getImageSizeFromStream($stream);
234  $this->assertEquals($width, $dimensions[self::W]);
235  $this->assertEquals($height, $dimensions[self::H]);
236 
237  $by_fixed = $this->images->resizeToFixedSize($stream, $final_width, $final_height, $crop);
238  $this->assertTrue($by_fixed->isOK());
239  $new_dimensions = $this->getImageSizeFromStream($by_fixed->getStream());
240 
241  $this->assertEquals($final_width, $new_dimensions[self::W]);
242  $this->assertEquals($final_height, $new_dimensions[self::H]);
243  }
+ Here is the call graph for this function:

◆ testResizeToFitHeight()

ILIAS\Filesystem\Util\ImageConversionTest::testResizeToFitHeight ( int  $width,
int  $height,
int  $final_height,
int  $final_width 
)

getImageSizesByHeight

Definition at line 172 of file ImageConversionTest.php.

References ILIAS\Filesystem\Util\ImageConversionTest\createTestImageStream(), and ILIAS\Filesystem\Util\ImageConversionTest\getImageSizeFromStream().

177  : void {
178  $stream = $this->createTestImageStream($width, $height);
179  $dimensions = $this->getImageSizeFromStream($stream);
180  $this->assertEquals($width, $dimensions[self::W]);
181  $this->assertEquals($height, $dimensions[self::H]);
182 
183  // resize to fit
184  $resized = $this->images->resizeByHeight($stream, self::BY_HEIGHT_FINAL);
185  $this->assertTrue($resized->isOK());
186  $new_dimensions = $this->getImageSizeFromStream($resized->getStream());
187 
188  $this->assertEquals($final_width, $new_dimensions[self::W]);
189  $this->assertEquals($final_height, $new_dimensions[self::H]);
190 
191  // check aspect ratio
192  $this->assertEquals(
193  round($width > $height),
194  round($final_width > $final_height)
195  );
196  $this->assertEquals(
197  round($width / $height),
198  round($new_dimensions[self::W] / $new_dimensions[self::H])
199  );
200  $this->assertEquals(
201  $width > $height,
202  $width > $height
203  );
204  $this->assertEquals(
205  $width > $height,
206  $new_dimensions[self::W] > $new_dimensions[self::H]
207  );
208  }
+ Here is the call graph for this function:

◆ testResizeToFitWidth()

ILIAS\Filesystem\Util\ImageConversionTest::testResizeToFitWidth ( int  $width,
int  $height,
int  $final_width,
int  $final_height 
)

getImageSizesByWidth

Definition at line 120 of file ImageConversionTest.php.

References ILIAS\Filesystem\Util\ImageConversionTest\createTestImageStream(), and ILIAS\Filesystem\Util\ImageConversionTest\getImageSizeFromStream().

125  : void {
126  $stream = $this->createTestImageStream($width, $height);
127  $dimensions = $this->getImageSizeFromStream($stream);
128  $this->assertEquals($width, $dimensions[self::W]);
129  $this->assertEquals($height, $dimensions[self::H]);
130 
131  // resize to fit width
132  $resized = $this->images->resizeByWidth($stream, self::BY_WIDTH_FINAL);
133  $this->assertTrue($resized->isOK());
134  $new_dimensions = $this->getImageSizeFromStream($resized->getStream());
135 
136  $this->assertEquals($final_width, $new_dimensions[self::W]);
137  $this->assertEquals($final_height, $new_dimensions[self::H]);
138 
139  // check aspect ratio
140  $this->assertEquals(
141  round($width > $height),
142  round($final_width > $final_height)
143  );
144  $this->assertEquals(
145  round($width / $height),
146  round($new_dimensions[self::W] / $new_dimensions[self::H])
147  );
148  $this->assertEquals(
149  $width > $height,
150  $width > $height
151  );
152  $this->assertEquals(
153  $width > $height,
154  $new_dimensions[self::W] > $new_dimensions[self::H]
155  );
156  }
+ Here is the call graph for this function:

◆ testWriteImage()

ILIAS\Filesystem\Util\ImageConversionTest::testWriteImage ( )

Definition at line 456 of file ImageConversionTest.php.

References ILIAS\Filesystem\Util\ImageConversionTest\createTestImageStream().

456  : void
457  {
458  $img = $this->createTestImageStream(10, 10);
459 
460  $output_path = __DIR__ . '/img/output.jpg';
461  $converter_options = (new ImageConversionOptions())
462  ->withThrowOnError(true)
463  ->withMakeTemporaryFiles(false)
464  ->withFixedDimensions(100, 100)
465  ->withOutputPath($output_path);
466 
467  $output_options = (new ImageOutputOptions())
468  ->withQuality(10)
469  ->withJpgOutput();
470 
471  $converter = new ImageConverter($converter_options, $output_options, $img);
472  $this->assertTrue($converter->isOK());
473 
474  $this->assertFileExists($output_path);
475  $stream = $converter->getStream();
476  $this->assertEquals($output_path, $stream->getMetadata('uri'));
477 
478  unlink($output_path);
479  }
+ Here is the call graph for this function:

◆ testWrongFormats()

ILIAS\Filesystem\Util\ImageConversionTest::testWrongFormats ( string  $format)

getWrongFormats

Definition at line 322 of file ImageConversionTest.php.

322  : void
323  {
324  $options = new ImageOutputOptions();
325  $this->expectException(\InvalidArgumentException::class);
326  $wrong = $options->withFormat($format);
327  }

◆ testWrongQualities()

ILIAS\Filesystem\Util\ImageConversionTest::testWrongQualities ( int  $quality)

getWrongQualites

Definition at line 341 of file ImageConversionTest.php.

341  : void
342  {
343  $options = new ImageOutputOptions();
344  $this->expectException(\InvalidArgumentException::class);
345  $wrong = $options->withQuality($quality);
346  }

Field Documentation

◆ $images

Images ILIAS\Filesystem\Util\ImageConversionTest::$images
protected

Definition at line 44 of file ImageConversionTest.php.

◆ BY_HEIGHT_FINAL

const ILIAS\Filesystem\Util\ImageConversionTest::BY_HEIGHT_FINAL = 756
protected

Definition at line 38 of file ImageConversionTest.php.

◆ BY_WIDTH_FINAL

const ILIAS\Filesystem\Util\ImageConversionTest::BY_WIDTH_FINAL = 256
protected

Definition at line 37 of file ImageConversionTest.php.

◆ H

const ILIAS\Filesystem\Util\ImageConversionTest::H = 'height'
protected

Definition at line 40 of file ImageConversionTest.php.

◆ IMAGE_JPEG

const ILIAS\Filesystem\Util\ImageConversionTest::IMAGE_JPEG = 'image/jpeg'
protected

Definition at line 41 of file ImageConversionTest.php.

◆ IMAGE_PNG

const ILIAS\Filesystem\Util\ImageConversionTest::IMAGE_PNG = 'image/png'
protected

Definition at line 42 of file ImageConversionTest.php.

◆ IMAGE_WEBP

const ILIAS\Filesystem\Util\ImageConversionTest::IMAGE_WEBP = 'image/webp'
protected

Definition at line 43 of file ImageConversionTest.php.

◆ W

const ILIAS\Filesystem\Util\ImageConversionTest::W = 'width'
protected

Definition at line 39 of file ImageConversionTest.php.


The documentation for this class was generated from the following file: