Closed
Description
I'm pretty sure in Magento 2.1 (and maybe 2.2) when you ran bin/magento catalog:images:resize
, it only resized images which weren't already resized before.
This no longer seems to be the case in Magento 2.3.
I think this behavior got introduced by 4988790 (not verified yet)
Preconditions (*)
- Magento 2.3.3
- PHP 7.2.26
Steps to reproduce (*)
- Have a shop with a product with an image
- Run
bin/magento catalog:images:resize
- Look at the timestamp of the resized images in
pub/media/catalog/product/cache/
- Wait a while
- Run
bin/magento catalog:images:resize
again - Notice that the modified timestamp of images in
pub/media/catalog/product/cache/
has been altered, which means the images got resized again even if they already exist.
Expected result (*)
- Executing
bin/magento catalog:images:resize
should not re-save an already resized image
Actual result (*)
- Executing
bin/magento catalog:images:resize
re-saves already resized images
Temp solution
This seems to resolve the issue after some very initial testing:
diff --git a/app/code/Magento/MediaStorage/Service/ImageResize.php b/app/code/Magento/MediaStorage/Service/ImageResize.php
index 6da48ee69ed..ccfce994752 100644
--- a/app/code/Magento/MediaStorage/Service/ImageResize.php
+++ b/app/code/Magento/MediaStorage/Service/ImageResize.php
@@ -287,13 +287,18 @@ class ImageResize
private function resize(array $viewImage, string $originalImagePath, string $originalImageName)
{
$imageParams = $this->paramsBuilder->build($viewImage);
- $image = $this->makeImage($originalImagePath, $imageParams);
$imageAsset = $this->assertImageFactory->create(
[
'miscParams' => $imageParams,
'filePath' => $originalImageName,
]
);
+ if ($this->mediaDirectory->isFile($imageAsset->getPath())) {
+ // image was already resized, let's quit!
+ return;
+ }
+
+ $image = $this->makeImage($originalImagePath, $imageParams);
if (isset($imageParams['watermark_file'])) {
if ($imageParams['watermark_height'] !== null) {
Postponing the initialization of the $image
variable also has a very big impact on performance.
Metadata
Metadata
Assignees
Labels
Gate 3 Passed. Manual verification of the issue completed. Issue is confirmedGate 1 Passed. Automatic verification of issue format passedGate 4. Acknowledged. Issue is added to backlog and ready for developmentIndicates original Magento version for the Issue report.The issue has been reproduced on latest 2.4-develop branch