ILIAS  trunk Revision v11.0_alpha-1811-gd2d5443e411
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ILIAS\Filesystem\Util\Convert\Images Class Reference
+ Collaboration diagram for ILIAS\Filesystem\Util\Convert\Images:

Public Member Functions

 __construct (bool $throw_on_error=false)
 
 thumbnail (FileStream $stream, int $fit_into_size, ?ImageOutputOptions $image_output_options=null)
 Creates an image from the given stream which fits into the given size and keeps the aspect ratio. More...
 
 croppedSquare (FileStream $stream, int $square_size, ?ImageOutputOptions $image_output_options=null)
 Creates an image from the given stream which fits into the given size, but is cropped to fill the whole square. More...
 
 resizeByWidth (FileStream $stream, int $width, ?ImageOutputOptions $image_output_options=null)
 Resizes an image to an image with the given width. More...
 
 resizeByHeight (FileStream $stream, int $height, ?ImageOutputOptions $image_output_options=null)
 Resizes an image to an image with the given height. More...
 
 resizeToFixedSize (FileStream $stream, int $width, int $height, bool $crop_or_otherwise_squeeze=true, ?ImageOutputOptions $image_output_options=null)
 Creates an image from the given stream, resized to width and height given. More...
 
 convertToFormat (FileStream $stream, string $to_format, ?int $width=null, ?int $height=null, ?ImageOutputOptions $image_output_options=null)
 Creates an image from the given stream, converted to the desired format. More...
 

Protected Attributes

ImageConversionOptions $conversion_options
 
ImageOutputOptions $image_output_options
 

Private Member Functions

 merge (?ImageOutputOptions $image_output_options)
 

Detailed Description

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

Definition at line 29 of file Images.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Filesystem\Util\Convert\Images::__construct ( bool  $throw_on_error = false)
Parameters
bool$throw_on_errorif there is any error, throw an exception, otherwise one must check with isOK()

Definition at line 37 of file Images.php.

39  {
40  // Defaults
41  $this->conversion_options = (new ImageConversionOptions())
42  ->withMakeTemporaryFiles(false)
43  ->withThrowOnError($throw_on_error);
44  $this->image_output_options = (new ImageOutputOptions())
45  ->withJpgOutput()
46  ->withQuality(75);
47  }

Member Function Documentation

◆ convertToFormat()

ILIAS\Filesystem\Util\Convert\Images::convertToFormat ( FileStream  $stream,
string  $to_format,
?int  $width = null,
?int  $height = null,
?ImageOutputOptions  $image_output_options = null 
)

Creates an image from the given stream, converted to the desired format.

Currently supported target formats are:

Definition at line 158 of file Images.php.

References ILIAS\Filesystem\Util\Convert\Images\merge(), null, ILIAS\Filesystem\Util\Convert\ImageConversionOptions\withHeight(), ILIAS\Filesystem\Util\Convert\ImageConversionOptions\withKeepAspectRatio(), ILIAS\Filesystem\Util\Convert\ImageConversionOptions\withKeepDimensions(), and ILIAS\Filesystem\Util\Convert\ImageConversionOptions\withWidth().

164  : ImageConverter {
165  $conversion_options = $this->conversion_options
166  ->withKeepAspectRatio(true)
167  ->withCrop(true);
168 
169  if ($height !== null) {
171  }
172  if ($width !== null) {
174  }
175  if ($width === null && $height === null) {
177  }
178  return new ImageConverter(
180  $this->merge($image_output_options)->withFormat($to_format),
181  $stream
182  );
183  }
withWidth(int $width)
Resize the image to the given width.
withKeepAspectRatio(bool $keep_aspect_ratio)
Keep the aspect ratio while resizing the image.
ImageConversionOptions $conversion_options
Definition: Images.php:31
withKeepDimensions(bool $keep)
No resizing, the original image dimension will be used.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
ImageOutputOptions $image_output_options
Definition: Images.php:32
merge(?ImageOutputOptions $image_output_options)
Definition: Images.php:185
withHeight(int $height)
Resize the image to the given height.
+ Here is the call graph for this function:

◆ croppedSquare()

ILIAS\Filesystem\Util\Convert\Images::croppedSquare ( FileStream  $stream,
int  $square_size,
?ImageOutputOptions  $image_output_options = null 
)

Creates an image from the given stream which fits into the given size, but is cropped to fill the whole square.

Use getStream() to get final image.

Definition at line 72 of file Images.php.

References ILIAS\Filesystem\Util\Convert\Images\merge().

76  : ImageConverter {
77  return new ImageConverter(
78  $this->conversion_options
79  ->withFitIn($square_size)
80  ->withKeepAspectRatio(true)
81  ->withCrop(true),
83  $stream
84  );
85  }
ImageOutputOptions $image_output_options
Definition: Images.php:32
merge(?ImageOutputOptions $image_output_options)
Definition: Images.php:185
+ Here is the call graph for this function:

◆ merge()

ILIAS\Filesystem\Util\Convert\Images::merge ( ?ImageOutputOptions  $image_output_options)
private

◆ resizeByHeight()

ILIAS\Filesystem\Util\Convert\Images::resizeByHeight ( FileStream  $stream,
int  $height,
?ImageOutputOptions  $image_output_options = null 
)

Resizes an image to an image with the given height.

The width is calculated to keep the aspect ratio. Use getStream() to get final image.

Definition at line 113 of file Images.php.

References ILIAS\Filesystem\Util\Convert\Images\merge().

117  : ImageConverter {
118  return new ImageConverter(
119  $this->conversion_options
120  ->withHeight($height)
121  ->withKeepAspectRatio(true),
123  $stream
124  );
125  }
ImageOutputOptions $image_output_options
Definition: Images.php:32
merge(?ImageOutputOptions $image_output_options)
Definition: Images.php:185
+ Here is the call graph for this function:

◆ resizeByWidth()

ILIAS\Filesystem\Util\Convert\Images::resizeByWidth ( FileStream  $stream,
int  $width,
?ImageOutputOptions  $image_output_options = null 
)

Resizes an image to an image with the given width.

The height is calculated to keep the aspect ratio. Use getStream() to get final image.

Definition at line 93 of file Images.php.

References ILIAS\Filesystem\Util\Convert\Images\merge().

97  : ImageConverter {
98  return new ImageConverter(
99  $this->conversion_options
100  ->withWidth($width)
101  ->withKeepAspectRatio(true),
103  $stream
104  );
105  }
ImageOutputOptions $image_output_options
Definition: Images.php:32
merge(?ImageOutputOptions $image_output_options)
Definition: Images.php:185
+ Here is the call graph for this function:

◆ resizeToFixedSize()

ILIAS\Filesystem\Util\Convert\Images::resizeToFixedSize ( FileStream  $stream,
int  $width,
int  $height,
bool  $crop_or_otherwise_squeeze = true,
?ImageOutputOptions  $image_output_options = null 
)

Creates an image from the given stream, resized to width and height given.

The original image can be cropped (to keep aspect ratio) or not (which squeezes the original to fit). Use getStream() to get final image.

Definition at line 133 of file Images.php.

References ILIAS\Filesystem\Util\Convert\Images\merge().

139  : ImageConverter {
140  return new ImageConverter(
141  $this->conversion_options
142  ->withWidth($width)
143  ->withHeight($height)
144  ->withCrop($crop_or_otherwise_squeeze)
145  ->withKeepAspectRatio(true),
147  $stream
148  );
149  }
ImageOutputOptions $image_output_options
Definition: Images.php:32
merge(?ImageOutputOptions $image_output_options)
Definition: Images.php:185
+ Here is the call graph for this function:

◆ thumbnail()

ILIAS\Filesystem\Util\Convert\Images::thumbnail ( FileStream  $stream,
int  $fit_into_size,
?ImageOutputOptions  $image_output_options = null 
)

Creates an image from the given stream which fits into the given size and keeps the aspect ratio.

Use getStream() to get final image.

Definition at line 53 of file Images.php.

References ILIAS\Filesystem\Util\Convert\Images\merge().

57  : ImageConverter {
58  return new ImageConverter(
59  $this->conversion_options
60  ->withFitIn($fit_into_size)
61  ->withCrop(false)
62  ->withKeepAspectRatio(true),
64  $stream
65  );
66  }
ImageOutputOptions $image_output_options
Definition: Images.php:32
merge(?ImageOutputOptions $image_output_options)
Definition: Images.php:185
+ Here is the call graph for this function:

Field Documentation

◆ $conversion_options

ImageConversionOptions ILIAS\Filesystem\Util\Convert\Images::$conversion_options
protected

Definition at line 31 of file Images.php.

◆ $image_output_options

ImageOutputOptions ILIAS\Filesystem\Util\Convert\Images::$image_output_options
protected

Definition at line 32 of file Images.php.

Referenced by ILIAS\Filesystem\Util\Convert\Images\merge().


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