Magento 2.3 php bin/magento catalog:image:resize issues image does not exist


if you are gettting issues like File '/var/www/magento/pub/media/catalog/product/s/w/swatch_image.jpg' does not exist during running this command php bin/magento catalog:image:resize then simply upload the mising images in their folder and again run this command.

or if it is showing multiple image missing and you want to skip this missing image error and continue command run then go to
vendor/magento/module-media-storage/Service/ImageResize.php file and replace this function
public function resizeFromThemes(array $themes = null): \Generator
    {
        $count = $this->productImage->getCountAllProductImages();
        if (!$count) {
            throw new NotFoundException(__('Cannot resize images - product images not found'));
        }

        $productImages = $this->productImage->getAllProductImages();
        $viewImages = $this->getViewImages($themes ?? $this->getThemesInUse());

        foreach ($productImages as $image) {
            $originalImageName = $image['filepath'];
            $originalImagePath = $this->mediaDirectory->getAbsolutePath(
                $this->imageConfig->getMediaPath($originalImageName)
            );
            foreach ($viewImages as $viewImage) {
                $this->resize($viewImage, $originalImagePath, $originalImageName);
            }
            yield $originalImageName => $count;
        }
    }
with below function
public function resizeFromThemes(array $themes = null): \Generator
    {
        $count = $this->productImage->getCountAllProductImages();
        if (!$count) {
            throw new NotFoundException(__('Cannot resize images - product images not found'));
        }

        $productImages = $this->productImage->getAllProductImages();
        $viewImages = $this->getViewImages($themes ?? $this->getThemesInUse());

        foreach ($productImages as $image) {
            $originalImageName = $image['filepath'];
            $originalImagePath = $this->mediaDirectory->getAbsolutePath(
                $this->imageConfig->getMediaPath($originalImageName)
            );
            if(file_exists($originalImagePath)){

                foreach ($viewImages as $viewImage) {
                    $this->resize($viewImage, $originalImagePath, $originalImageName);
                }
                yield $originalImageName => $count;
            }
            else{
                $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/skipimages.log');
                $logger = new \Zend\Log\Logger();
                $logger->addWriter($writer);
                //$logger->debug(__METHOD__);
                $logger->debug($originalImagePath);
                //die('test');
            }
        }
    }
and run resize command again. Now using this function all missing images will be skip and avaliable image will be resize. you can also find the skipped log images in var/log/skipimages.log file.

i will recommend you that you should extend this function in your custom module.
Previous
Next Post »