diff --git a/src/Command/RerenderAssetsCommand.php b/src/Command/RerenderAssetsCommand.php new file mode 100644 index 0000000..c4cbf7b --- /dev/null +++ b/src/Command/RerenderAssetsCommand.php @@ -0,0 +1,58 @@ +em->getRepository(RenderedAsset::class)->findAll(); + $count = 0; + + foreach ($assets as $asset) { + $asset->setStatus(RenderStatus::Pending)->setFilePath(null); + $this->bus->dispatch(new RenderImageMessage( + $asset->getImage()->getId(), + $asset->getDeviceModel()->value, + $asset->getOrientation()->value, + )); + $count++; + } + + $this->em->flush(); + + $io->success("Reset and re-dispatched $count rendered assets."); + return Command::SUCCESS; + } +} diff --git a/src/MessageHandler/RenderImageMessageHandler.php b/src/MessageHandler/RenderImageMessageHandler.php index 7818cd2..6f6a016 100644 --- a/src/MessageHandler/RenderImageMessageHandler.php +++ b/src/MessageHandler/RenderImageMessageHandler.php @@ -94,9 +94,26 @@ final class RenderImageMessageHandler $imagick->setBackgroundColor('white'); $imagick->mergeImageLayers(\Imagick::LAYERMETHOD_FLATTEN); $imagick->autoOrient(); - $imagick->cropThumbnailImage($width, $height); - // Portrait: rotate the cropped photo 90° CCW so the packed .bin's row + // Fit the source into the target box without cropping aggressively; + // composite onto a white canvas of exact target dims so an aspect + // mismatch (e.g. portrait crop served to a landscape device) shows + // up as letterbox bars instead of a brutally center-cropped slice. + // For correctly-cropped photos the source already matches the target + // aspect and `thumbnailImage` produces target dims with no padding. + $imagick->thumbnailImage($width, $height, true); + if ($imagick->getImageWidth() !== $width || $imagick->getImageHeight() !== $height) { + $canvas = new \Imagick(); + $canvas->newImage($width, $height, new \ImagickPixel('white')); + $canvas->setImageFormat('png'); + $offsetX = (int) (($width - $imagick->getImageWidth()) / 2); + $offsetY = (int) (($height - $imagick->getImageHeight()) / 2); + $canvas->compositeImage($imagick, \Imagick::COMPOSITE_OVER, $offsetX, $offsetY); + $imagick->destroy(); + $imagick = $canvas; + } + + // Portrait: rotate the fitted photo 90° CCW so the packed .bin's row // layout matches the EPD's native 800-pixel scan order. The frame is // physically rotated 90° CW for portrait (ribbon on right from EPD's // POV → on left from user's view), so the photo's top edge maps to the