ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
FirstPageToTileImageFlavourMachine.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
33
39{
40 public const ID = "be03e07e396a61f7d9b31a712f0913fe9c6cd43b009ce69d30aa0f10bd3500bd";
44 private const FULL_QUALITY_SIZE_THRESHOLD = 100;
47 private ?TileImageFlavourDefinition $definition = null;
49
50 public function __construct()
51 {
52 $this->extract_pages = new ExtractPages();
53 $this->crop = new CropRectangle();
54 }
55
56
57 public function getId(): string
58 {
59 return self::ID;
60 }
61
63 {
64 return $definition instanceof TileImageFlavourDefinition;
65 }
66
67 public function dependsOnEngine(): ?string
68 {
69 return ImagickEngine::class;
70 }
71
72 public function processStream(
74 FileStream $stream,
75 FlavourDefinition $for_definition
76 ): \Generator {
77 $this->definition = $for_definition;
78 $this->information = $information;
79
80 $page_stream = $this->extract_pages->processStream(
81 $this->information,
82 $stream,
84 false,
85 $this->definition->getWidths()['xl'],
86 1,
87 false,
88 100
89 )
90 )->current()?->getStream();
91
92 if ($page_stream === null) {
93 return;
94 }
95
96 $i = 0;
97 foreach ($for_definition->getWidths() as $width) {
98 yield new Result(
99 $for_definition,
100 $this->cropImage($page_stream, $width),
101 $i,
102 true
103 );
104 $i++;
105 }
106 }
107
108 protected function cropImage(
109 FileStream $stream,
110 int $width
111 ) {
112 $quality = $width <= self::FULL_QUALITY_SIZE_THRESHOLD
113 ? 100 // we take 100% jpeg quality for small resultions
114 : $this->definition->getQuality();
115
116
117 return $this->crop->processStream(
118 $this->information,
119 $stream,
120 new CropToRectangle(
121 false,
122 $width,
123 $this->definition->getRatio(),
124 $quality
125 )
126 )->current()->getStream();
127 }
128}
cropImage(FileStream $stream, int $width)
__construct()
FlavourMachines must be able to be created without further dependencies.
processStream(FileInformation $information, FileStream $stream, FlavourDefinition $for_definition)
canHandleDefinition(FlavourDefinition $definition)
Check if a corresponding configuration can be processed by this Machine.
dependsOnEngine()
Return the class name of the Engine that is required for this Machine to work.
The base interface for all filesystem streams.
Definition: FileStream.php:32