ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\Filesystem\Util\Convert\ImageOutputOptions Class Reference
+ Collaboration diagram for ILIAS\Filesystem\Util\Convert\ImageOutputOptions:

Public Member Functions

 withFormat (string $format)
 @description set the desired output format. More...
 
 withJpgOutput ()
 @description set the output format to JPG More...
 
 withPngOutput ()
 @description set the output format to PNG More...
 
 withWebPOutput ()
 @description set the output format to WEBP More...
 
 withQuality (int $image_quality)
 @description set the image compression quality. More...
 
 getFormat ()
 
 getQuality ()
 

Data Fields

const FORMAT_JPG = 'jpg'
 
const FORMAT_PNG = 'png'
 
const FORMAT_WEBP = 'webp'
 
const FORMAT_KEEP = 'keep'
 

Protected Member Functions

 checkImageQuality (int $image_quality)
 

Private Member Functions

 checkFormat (string $format)
 

Private Attributes

int $quality = 75
 
string $format = self::FORMAT_JPG
 
array $allowed_formats
 

Detailed Description

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

Definition at line 26 of file ImageOutputOptions.php.

Member Function Documentation

◆ checkFormat()

ILIAS\Filesystem\Util\Convert\ImageOutputOptions::checkFormat ( string  $format)
private

Definition at line 101 of file ImageOutputOptions.php.

101 : string
102 {
103 $format = strtolower($format);
104 if ($format === 'jpeg') {
106 }
107
108 if (!in_array($format, $this->allowed_formats, true)) {
109 throw new \InvalidArgumentException('Format must be one of ' . implode(', ', $this->allowed_formats) . ', but ' . $format . ' was given.');
110 }
111 return $format;
112 }

References ILIAS\Filesystem\Util\Convert\ImageOutputOptions\$format, and ILIAS\Filesystem\Util\Convert\ImageOutputOptions\FORMAT_JPG.

Referenced by ILIAS\Filesystem\Util\Convert\ImageOutputOptions\withFormat().

+ Here is the caller graph for this function:

◆ checkImageQuality()

ILIAS\Filesystem\Util\Convert\ImageOutputOptions::checkImageQuality ( int  $image_quality)
protected

Definition at line 114 of file ImageOutputOptions.php.

114 : void
115 {
116 if ($this->format === self::FORMAT_WEBP) {
117 if ($image_quality !== 0 && $image_quality !== 100) {
118 throw new \InvalidArgumentException('WebP only supports quality 0 (loss) or 100 (losless)');
119 }
120 } elseif ($image_quality < 0 || $image_quality > 100) {
121 throw new \InvalidArgumentException('Quality must be between 0 and 100');
122 }
123 }

Referenced by ILIAS\Filesystem\Util\Convert\ImageOutputOptions\withQuality().

+ Here is the caller graph for this function:

◆ getFormat()

ILIAS\Filesystem\Util\Convert\ImageOutputOptions::getFormat ( )

Definition at line 91 of file ImageOutputOptions.php.

91 : string
92 {
93 return $this->format;
94 }

References ILIAS\Filesystem\Util\Convert\ImageOutputOptions\$format.

Referenced by ILIAS\Filesystem\Util\Convert\Images\merge(), and ILIAS\Filesystem\Util\ImageConversionTest\testImageOutputOptionSanity().

+ Here is the caller graph for this function:

◆ getQuality()

ILIAS\Filesystem\Util\Convert\ImageOutputOptions::getQuality ( )

◆ withFormat()

ILIAS\Filesystem\Util\Convert\ImageOutputOptions::withFormat ( string  $format)

@description set the desired output format.

Exceptions

InvalidArgumentException if an invalid format is passed

Definition at line 45 of file ImageOutputOptions.php.

45 : ImageOutputOptions
46 {
47 $format = $this->checkFormat($format);
48 $clone = clone $this;
49 $clone->format = $format;
50 return $clone;
51 }

References ILIAS\Filesystem\Util\Convert\ImageOutputOptions\$format, and ILIAS\Filesystem\Util\Convert\ImageOutputOptions\checkFormat().

Referenced by ILIAS\Filesystem\Util\ImageConversionTest\testImageOutputOptionSanity(), ILIAS\Filesystem\Util\ImageConversionTest\testWrongFormats(), ILIAS\Filesystem\Util\Convert\ImageOutputOptions\withJpgOutput(), ILIAS\Filesystem\Util\Convert\ImageOutputOptions\withPngOutput(), and ILIAS\Filesystem\Util\Convert\ImageOutputOptions\withWebPOutput().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ withJpgOutput()

ILIAS\Filesystem\Util\Convert\ImageOutputOptions::withJpgOutput ( )

@description set the output format to JPG

Definition at line 56 of file ImageOutputOptions.php.

56 : ImageOutputOptions
57 {
58 return $this->withFormat(self::FORMAT_JPG);
59 }
withFormat(string $format)
@description set the desired output format.

References ILIAS\Filesystem\Util\Convert\ImageOutputOptions\withFormat().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ withPngOutput()

ILIAS\Filesystem\Util\Convert\ImageOutputOptions::withPngOutput ( )

@description set the output format to PNG

Definition at line 64 of file ImageOutputOptions.php.

64 : ImageOutputOptions
65 {
66 return $this->withFormat(self::FORMAT_PNG);
67 }

References ILIAS\Filesystem\Util\Convert\ImageOutputOptions\withFormat().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ withQuality()

ILIAS\Filesystem\Util\Convert\ImageOutputOptions::withQuality ( int  $image_quality)

@description set the image compression quality.

Depending on the format, this will be ignored or other values are needed. JPG: 0-100 WEBP: 0 (loss) or 100 (lossless) PNG: 0-100 (which will be converted to 0-9 internally)

Definition at line 83 of file ImageOutputOptions.php.

83 : ImageOutputOptions
84 {
85 $this->checkImageQuality($image_quality);
86 $clone = clone $this;
87 $clone->quality = $image_quality;
88 return $clone;
89 }

References ILIAS\Filesystem\Util\Convert\ImageOutputOptions\checkImageQuality().

Referenced by ILIAS\Filesystem\Util\Convert\Images\merge(), ILIAS\Filesystem\Util\ImageConversionTest\testImageOutputOptionSanity(), and ILIAS\Filesystem\Util\ImageConversionTest\testWrongQualities().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ withWebPOutput()

ILIAS\Filesystem\Util\Convert\ImageOutputOptions::withWebPOutput ( )

@description set the output format to WEBP

Definition at line 72 of file ImageOutputOptions.php.

72 : ImageOutputOptions
73 {
74 return $this->withFormat(self::FORMAT_WEBP);
75 }

References ILIAS\Filesystem\Util\Convert\ImageOutputOptions\withFormat().

+ Here is the call graph for this function:

Field Documentation

◆ $allowed_formats

◆ $format

string ILIAS\Filesystem\Util\Convert\ImageOutputOptions::$format = self::FORMAT_JPG
private

◆ $quality

int ILIAS\Filesystem\Util\Convert\ImageOutputOptions::$quality = 75
private

◆ FORMAT_JPG

◆ FORMAT_KEEP

const ILIAS\Filesystem\Util\Convert\ImageOutputOptions::FORMAT_KEEP = 'keep'

◆ FORMAT_PNG

◆ FORMAT_WEBP

const ILIAS\Filesystem\Util\Convert\ImageOutputOptions::FORMAT_WEBP = 'webp'

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