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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
<?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 Magento\Framework\App\Bootstrap; $params = $_SERVER; $bootstrap = Bootstrap::create(BP, $params); $obj = $bootstrap->getObjectManager(); $state = $obj->get('Magento\Framework\App\State'); $state->setAreaCode('frontend'); /** * Start Script Execution Time */ $time_start = microtime(true); /** * Declare objects using ObjectManager */ $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $resizeImage = $objectManager->get('\Magento\MediaStorage\Service\ImageResize'); $product_id=20; $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $_product = $objectManager->get('Magento\Catalog\Model\Product')->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.
[crayon-63d3ebb83142c329996321/] Using above fucntion Images can be imported directly from...
Override view block using di.xml and add the below code...
You can check a list of called layout XML for...
Follow the below steps to install and set up PWA...
If you want to remove all leading zero's from order,...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.