19declare(strict_types=1);
42 use ImageSizeCalculator;
44 public const ID =
'extract_pages';
54 return ImagickEngineWithOptionalFFMpeg::class;
68 throw new \InvalidArgumentException(
'Invalid definition');
71 if (!class_exists(\Imagick::class)) {
76 $img = new \Imagick();
79 $this->high_quality = $for_definition->useMaxQuality();
80 if ($this->high_quality) {
82 $img->setResolution(300, 300);
84 $quality = $for_definition->getQuality();
87 $extractor =
new General();
89 $mime_type = $information->getMimeType();
91 case ($mime_type ===
'image/svg+xml' || $mime_type ===
'image/svg'):
92 $extractor =
new SVG();
94 case (str_contains($mime_type,
'video')):
95 $extractor =
new Video();
97 case ($mime_type ===
'application/pdf'):
98 $extractor =
new PDF();
102 $target_format = $extractor->getTargetFormat();
103 $target_background = $extractor->getBackground();
104 $alpha_channel = $extractor->getAlphaChannel();
105 $remove_color = $extractor->getRemoveColor();
106 $resolution = $extractor->getResolution();
109 $img->setResolution($resolution, $resolution);
110 $img->setBackgroundColor($target_background);
114 $img = $extractor->readImage($img, $stream, $for_definition);
115 }
catch (\ImagickException) {
121 $max_size = $for_definition->getMaxSize();
122 $img->resetIterator();
125 $gif = $target_format ===
'gif' ? new \Imagick() : null;
127 $gif->setFormat(
'GIF');
130 for ($x = 0; ($x < $for_definition->getMaxPages() && $x < $img->getNumberImages()); $x++) {
131 $img->setIteratorIndex($x);
132 $img->setImageAlphaChannel($alpha_channel);
133 $img->setImageBackgroundColor($target_background);
134 $img->setImageFormat($target_format);
136 if ($remove_color !==
null) {
137 $img->transparentPaintImage($remove_color, 0, 0,
false);
140 [$columns, $rows] = $this->calculateWidthHeightFromImage($img, $max_size);
142 if (!$this->high_quality) {
143 $yield = $img->thumbnailImage(
147 $for_definition->isFill()
150 $img->setImageResolution($resolution, $resolution);
151 $img->setImageCompression(\Imagick::COMPRESSION_JPEG);
152 $img->setImageCompressionQuality($quality);
155 $yield = $img->resizeImage(
158 \Imagick::FILTER_MITCHELL,
163 if ($yield && $gif ===
null) {
168 $for_definition->persist()
170 } elseif ($yield && $gif !==
null) {
171 $gif->addImage($img->getImage());
172 $gif->setImageDelay(50);
177 $gif->setImageFormat(
'gif');
178 $gif->setIteratorIndex(0);
179 $gif->setImageIterations(0);
180 [$columns, $rows] = $this->calculateWidthHeightFromImage($gif, $max_size);
181 $gif->thumbnailImage(
185 $for_definition->isFill()
192 $for_definition->persist()
Stream factory which enables the user to create streams without the knowledge of the concrete class.
static ofString(string $string)
Creates a new stream with an initial value.
The base interface for all filesystem streams.
if(!file_exists('../ilias.ini.php'))