ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilUserProfilePictureMachine.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
33
38{
40 public const ID = "a3c77dec93b5303f4340767b9a445ad591f6025a9ca7edbf24fa8ab23a851eae";
41 private const FULL_QUALITY_SIZE_THRESHOLD = 100;
46
47 public function __construct()
48 {
49 $this->crop = new CropSquare();
50 $this->grey = new MakeGreyScale();
51 }
52
53
54 public function getId(): string
55 {
56 return self::ID;
57 }
58
60 {
62 }
63
64 public function dependsOnEngine(): ?string
65 {
66 return GDEngine::class;
67 }
68
69 public function processStream(
71 FileStream $stream,
72 FlavourDefinition $for_definition
73 ): \Generator {
75 $this->definition = $for_definition;
76 $this->information = $information;
77
78 $i = 0;
79 foreach ($for_definition->getSizes() as $size) {
80 if (($croped_image = $this->cropImage($stream, $size)) === null) {
81 continue;
82 }
83 yield new Result(
84 $for_definition,
85 $croped_image,
86 $i,
87 true
88 );
89 $i++;
90 }
91 }
92
93 protected function cropImage(
94 FileStream $stream,
95 int $size
96 ): ?FileStream {
97 $quality = $size <= self::FULL_QUALITY_SIZE_THRESHOLD
98 ? 100 // we take 100% jpeg quality for small resultions
99 : $this->definition->getQuality();
100
101
102 return $this->crop->processStream(
103 $this->information,
104 $stream,
105 new CropToSquare(
106 false,
107 $size,
108 $quality
109 )
110 )->current()?->getStream();
111 }
112
113 protected function makeGreyScale(
114 FileStream $stream
115 ): ?FileStream {
116 return $this->grey->processStream(
117 $this->information,
118 $stream,
119 new ToGreyScale(
120 false,
121 $this->definition->getQuality()
122 )
123 )->current()?->getStream();
124 }
125}
dependsOnEngine()
Return the class name of the Engine that is required for this Machine to work.
cropImage(FileStream $stream, int $size)
__construct()
FlavourMachines must be able to be created without further dependencies.
ilUserProfilePictureDefinition $definition
canHandleDefinition(FlavourDefinition $definition)
Check if a corresponding configuration can be processed by this Machine.
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
The base interface for all filesystem streams.
Definition: FileStream.php:32
processStream(FileInformation $information, FileStream $stream, FlavourDefinition $for_definition)