cancel
Showing results for 
Search instead for 
Did you mean: 

Generate Thumbnail Programmatically

Generate Thumbnail Programmatically

<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
ini_set('max_execution_time', -1);
ini_set('memory_limit', -1);

require_once('app/Mage.php');

Mage::app();

$collection = Mage::getModel('catalog/product')->getCollection();

$count_images = 0;
$urls = "";

foreach($collection as $product)
{
	$_product = Mage::getModel('catalog/product')->load($product->getId());
	$_gallery = $_product->getMediaGalleryImages();

	$count_images += count($_gallery);

	foreach($_gallery as $image)
	{
		$image_path = realpath('media/catalog/product/'.$image->getFile());
		echo $image_path.' ->'.Mage::helper('catalog/image')->init($_product->getProduct(), 'thumbnail', $image_path)->keepAspectRatio(TRUE)->resize(200,null)."\n";
	}
}

echo "$count_images thumbnail generated";
?>


This is my code to generate product thumbnail for the specific size manually via terminal

 

php generate_thumbnail_all.php



But it only work on some machine.
But the code have no errors.

The script not work but if i browse magento catalog page, the thumbnail generated.

3 REPLIES 3

Re: Generate Thumbnail Programmatically [solved]

[solved]

Re: Generate Thumbnail Programmatically [solved]

Care to post the resolution?

Re: Generate Thumbnail Programmatically [solved]

require_once('app/Mage.php');

The above line fails to resolve in Magento v2.04 Smiley Sad