18 declare(strict_types=1);
43 public const ID =
'extract_pages';
53 return ImagickEngineWithOptionalFFMpeg::class;
67 throw new \InvalidArgumentException(
'Invalid definition');
70 if (!class_exists(\Imagick::class)) {
75 $img = new \Imagick();
78 $this->high_quality = $for_definition->useMaxQuality();
79 if ($this->high_quality) {
81 $img->setResolution(300, 300);
83 $quality = $for_definition->getQuality();
90 case ($mime_type ===
'image/svg+xml' || $mime_type ===
'image/svg'):
91 $extractor =
new SVG();
93 case (str_contains($mime_type,
'video')):
94 $extractor =
new Video();
96 case ($mime_type ===
'application/pdf'):
97 $extractor =
new PDF();
101 $target_format = $extractor->getTargetFormat();
102 $target_background = $extractor->getBackground();
103 $alpha_channel = $extractor->getAlphaChannel();
104 $remove_color = $extractor->getRemoveColor();
105 $resolution = $extractor->getResolution();
108 $img->setResolution($resolution, $resolution);
109 $img->setBackgroundColor($target_background);
113 $img = $extractor->readImage($img, $stream, $for_definition);
114 }
catch (\ImagickException) {
120 $max_size = $for_definition->getMaxSize();
121 $img->resetIterator();
124 $gif = $target_format ===
'gif' ? new \Imagick() :
null;
126 $gif->setFormat(
'GIF');
129 for ($x = 0; ($x < $for_definition->getMaxPages() && $x < $img->getNumberImages()); $x++) {
130 $img->setIteratorIndex($x);
131 $img->setImageAlphaChannel($alpha_channel);
132 $img->setImageBackgroundColor($target_background);
133 $img->setImageFormat($target_format);
135 if ($remove_color !==
null) {
136 $img->transparentPaintImage($remove_color, 0, 0,
false);
139 [$columns, $rows] = $this->calculateWidthHeightFromImage($img, $max_size);
141 if (!$this->high_quality) {
142 $yield = $img->thumbnailImage(
146 $for_definition->isFill()
149 $img->setImageResolution($resolution, $resolution);
150 $img->setImageCompression(\Imagick::COMPRESSION_JPEG);
151 $img->setImageCompressionQuality($quality);
154 $yield = $img->resizeImage(
157 \Imagick::FILTER_MITCHELL,
162 if ($yield && $gif ===
null) {
169 } elseif ($yield && $gif !==
null) {
170 $gif->addImage($img->getImage());
171 $gif->setImageDelay(50);
176 $gif->setImageFormat(
'gif');
177 $gif->setIteratorIndex(0);
178 $gif->setImageIterations(0);
179 [$columns, $rows] = $this->calculateWidthHeightFromImage($gif, $max_size);
180 $gif->thumbnailImage(
184 $for_definition->isFill()
persist()
Define whether the generated flavor and the respective streams should be persisted, or whether they should only be generated and used in-memory.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static ofString(string $string)
Creates a new stream with an initial value.
The base interface for all filesystem streams.