ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilBadgePictureMachine.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
33 
35 {
37 
38  public const ID = 'badge_image_resize_machine';
39  private const FULL_QUALITY_SIZE_THRESHOLD = 100;
40 
41  private CropSquare $crop;
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 
58  public function canHandleDefinition(FlavourDefinition $definition): bool
59  {
60  return $definition instanceof ilBadgePictureDefinition;
61  }
62 
63  public function dependsOnEngine(): ?string
64  {
65  return ImagickEngine::class;
66  }
67 
68  public function processStream(
69  FileInformation $information,
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,
80  new PagesToExtract(
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 }
cropImage(FileStream $stream, int $size)
ilBadgePictureDefinition $definition
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
__construct()
FlavourMachines must be able to be created without further dependencies.
dependsOnEngine()
Return the class name of the Engine that is required for this Machine to work.
processStream(FileInformation $information, FileStream $stream, FlavourDefinition $for_definition)
__construct(Container $dic, ilPlugin $plugin)
canHandleDefinition(FlavourDefinition $definition)
Check if a corresponding configuration can be processed by this Machine.
The base interface for all filesystem streams.
Definition: FileStream.php:31