ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
FirstPageToTileImageFlavourMachine.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
33 
39 {
40  public const ID = "be03e07e396a61f7d9b31a712f0913fe9c6cd43b009ce69d30aa0f10bd3500bd";
41  private const FULL_QUALITY_SIZE_THRESHOLD = 100;
45  private ?FileInformation $information = null;
46 
47  public function __construct()
48  {
49  $this->extract_pages = new ExtractPages();
50  $this->crop = new CropRectangle();
51  }
52 
53 
54  public function getId(): string
55  {
56  return self::ID;
57  }
58 
59  public function canHandleDefinition(FlavourDefinition $definition): bool
60  {
61  return $definition instanceof ilObjectTileImageFlavourDefinition;
62  }
63 
64  public function dependsOnEngine(): ?string
65  {
66  return ImagickEngine::class;
67  }
68 
69  public function processStream(
70  FileInformation $information,
71  FileStream $stream,
72  FlavourDefinition $for_definition
73  ): \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 $width
108  ) {
109  $quality = $width <= self::FULL_QUALITY_SIZE_THRESHOLD
110  ? 100 // we take 100% jpeg quality for small resultions
111  : $this->definition->getQuality();
112 
113 
114  return $this->crop->processStream(
115  $this->information,
116  $stream,
117  new CropToRectangle(
118  false,
119  $width,
120  $this->definition->getRatio(),
121  $quality
122  )
123  )->current()->getStream();
124  }
125 }
dependsOnEngine()
Return the class name of the Engine that is required for this Machine to work.
processStream(FileInformation $information, FileStream $stream, FlavourDefinition $for_definition)
ilObjectTileImageFlavourDefinition $definition
__construct()
FlavourMachines must be able to be created without further dependencies.
canHandleDefinition(FlavourDefinition $definition)
Check if a corresponding configuration can be processed by this Machine.
cropImage(FileStream $stream, int $width)
The base interface for all filesystem streams.
Definition: FileStream.php:31