ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ilBadgePictureMachine.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
33
35{
37
38 public const ID = 'badge_image_resize_machine';
39 private const FULL_QUALITY_SIZE_THRESHOLD = 100;
40
45
46 public function __construct()
47 {
49 $this->crop = new CropSquare();
50 }
51
52 public function getId(): string
53 {
54 return self::ID;
55 }
56
58 {
59 return $definition instanceof ilBadgePictureDefinition;
60 }
61
62 public function dependsOnEngine(): ?string
63 {
64 return ImagickEngine::class;
65 }
66
67 public function processStream(
69 FileStream $stream,
70 FlavourDefinition $for_definition
71 ): Generator {
73 $this->definition = $for_definition;
74 $this->information = $information;
75
76 $i = 0;
77 foreach ($for_definition->getWidths() as $width) {
78 yield new Result(
79 $for_definition,
80 $this->cropImage($stream, $width),
81 $i,
82 true
83 );
84 $i++;
85 }
86 }
87
88 protected function cropImage(
89 FileStream $stream,
90 int $size
91 ): ?Stream {
92 $quality = $size <= self::FULL_QUALITY_SIZE_THRESHOLD
93 ? 100
94 : $this->definition->getQuality();
95
96 return $this->crop->processStream(
97 $this->information,
98 $stream,
99 new CropToSquare(
100 false,
101 $size,
102 $quality
103 )
104 )->current()->getStream();
105 }
106}
canHandleDefinition(FlavourDefinition $definition)
Check if a corresponding configuration can be processed by this Machine.
__construct()
FlavourMachines must be able to be created without further dependencies.
cropImage(FileStream $stream, int $size)
dependsOnEngine()
Return the class name of the Engine that is required for this Machine to work.
ilBadgePictureDefinition $definition
The base interface for all filesystem streams.
Definition: FileStream.php:32
processStream(FileInformation $information, FileStream $stream, FlavourDefinition $for_definition)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc