ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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->extract_pages = new ExtractPages();
50 $this->crop = new CropSquare();
51 }
52
53 public function getId(): string
54 {
55 return self::ID;
56 }
57
59 {
60 return $definition instanceof ilBadgePictureDefinition;
61 }
62
63 public function dependsOnEngine(): ?string
64 {
65 return ImagickEngine::class;
66 }
67
68 public function processStream(
70 FileStream $stream,
71 FlavourDefinition $for_definition
72 ): Generator {
74 $this->definition = $for_definition;
75 $this->information = $information;
76
77 $page_stream = $this->extract_pages->processStream(
78 $this->information,
79 $stream,
81 false,
82 $this->definition->getWidths()['xl'],
83 1,
84 false,
85 100
86 )
87 )->current()?->getStream();
88
89 if ($page_stream === null) {
90 return;
91 }
92
93 $i = 0;
94 foreach ($for_definition->getWidths() as $width) {
95 yield new Result(
96 $for_definition,
97 $this->cropImage($page_stream, $width),
98 $i,
99 true
100 );
101 $i++;
102 }
103 }
104
105 protected function cropImage(
106 FileStream $stream,
107 int $size
108 ): ?Stream {
109 $quality = $size <= self::FULL_QUALITY_SIZE_THRESHOLD
110 ? 100
111 : $this->definition->getQuality();
112
113
114 return $this->crop->processStream(
115 $this->information,
116 $stream,
117 new CropToSquare(
118 false,
119 $size,
120 $quality
121 )
122 )->current()->getStream();
123 }
124}
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