diff --git a/lib/php/rendition-factory/src/Command/CreateCommand.php b/lib/php/rendition-factory/src/Command/CreateCommand.php index 3fc870e70..2317a9ff1 100644 --- a/lib/php/rendition-factory/src/Command/CreateCommand.php +++ b/lib/php/rendition-factory/src/Command/CreateCommand.php @@ -45,15 +45,42 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { - $time = microtime(true); - $mimeType = $input->getOption('type'); + $ret = 0; $src = $input->getArgument('src'); + if (is_dir($src)) { + if (false === ($od = opendir($src))) { + $output->writeln(sprintf('Directory "%s" could not be opened.', $src)); + + return 1; + } + while ($f = readdir($od)) { + if ('.' === $f || '..' === $f) { + continue; + } + $ret |= $this->doFile($input, $output, $src.'/'.$f); + } + closedir($od); + } else { + $ret = $this->doFile($input, $output, $src); + } + + return $ret; + } + + protected function doFile(InputInterface $input, OutputInterface $output, string $src): int + { if (!file_exists($src)) { $output->writeln(sprintf('File "%s" does not exist.', $src)); return 1; } + $time = microtime(true); + $output->writeln(''); + $output->writeln(sprintf('Processing file: %s', $src)); + + $mimeType = $input->getOption('type'); + if (null === $mimeType) { $mimeType = $this->mimeTypeGuesser->guessMimeTypeFromPath($src); $output->writeln(sprintf('MIME type guessed: %s', $mimeType ?? 'unknown')); diff --git a/lib/php/rendition-factory/src/Transformer/Image/Imagine/BackgroundFilterLoader.php b/lib/php/rendition-factory/src/Transformer/Image/Imagine/BackgroundFilterLoader.php index 023bc57c1..2368afb93 100644 --- a/lib/php/rendition-factory/src/Transformer/Image/Imagine/BackgroundFilterLoader.php +++ b/lib/php/rendition-factory/src/Transformer/Image/Imagine/BackgroundFilterLoader.php @@ -19,22 +19,14 @@ public function load(ImageInterface $image, array $options = []) $options['color'] ?? '#fff', $options['opacity'] ?? 100, ); - $imageSize = $image->getSize(); + $canvas = $this->imagine->create($image->getSize(), $background); - $imageW = $imageSize->getWidth(); - $imageH = $imageSize->getHeight(); + // DO NOT REMOVE THIS LINE + // This is a workaround to avoid a bug in Imagine that causes wrong positionning + // when the image has multiple layers + $unused = $image->layers()[0]; - $canvas = $this->imagine->create($imageSize, $background); - - /** - * @var ImageInterface $layer - */ - foreach ($image->layers() as $layer) { - $layerSize = $layer->getSize(); - $layerDW = ($imageW - $layerSize->getWidth()) / 2; - $layerDH = ($imageH - $layerSize->getHeight()) / 2; - $canvas->paste($layer, new Point($layerDW, $layerDH)); - } + $canvas->paste($image, new Point(0, 0)); return $canvas; }