I faced an issue with one particular product that wasn’t generating the cache & resized images. And there is Magento’s default command to generate the catalog images, but it only generates all the product images at that time so that procedure wasn’t an option to choose.
So to solve the problem, I created one script file on the root of the Magento directory and added the static product id in that script, so it could generate the resized Images as per theme images for that particular product.
Step 1: Create a resize_image.php on the root directory of Magento and add the below code in the file.
<?php
/**
* Script For resize images for a particular product.
* @author Magemonkeys
*/
/**
* For Development Purpose (Error Displaying)
*/
//ini_set('display_errors', 1);
//error_reporting(E_ALL);
/**
* If server value is not compatible
*/
ini_set('memory_limit', '1024M');
ini_set('max_execution_time', '18000');
/**
* If your external file is in root folder
*/
require __DIR__ . '/app/bootstrap.php';
use MagentoFrameworkAppBootstrap;
$params = $_SERVER;
$bootstrap = Bootstrap::create(BP, $params);
$obj = $bootstrap->getObjectManager();
$state = $obj->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');
/**
* Start Script Execution Time
*/
$time_start = microtime(true);
/**
* Declare objects using ObjectManager
*/
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$resizeImage = $objectManager->get('MagentoMediaStorageServiceImageResize');
$product_id=20;
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$_product = $objectManager->get('MagentoCatalogModelProduct')->load($product_id);
$galleryImages = $_product->getMediaGalleryImages();
if ($galleryImages)
{
foreach ($galleryImages as $image) {
$resizeImage->resizeFromImageName($image->getFile());
}
}
Now, you have to run this file through a browser e.g. http://example.com/resize_image.php and you can see that all the images of that product are resized as per the theme images.

