Skip to content

Instantly share code, notes, and snippets.

@hprange
Forked from samukasmk/smk_magento_resizer.php
Last active December 23, 2015 14:59
Show Gist options
  • Save hprange/6652005 to your computer and use it in GitHub Desktop.
Save hprange/6652005 to your computer and use it in GitHub Desktop.
<?php
/*
smk_magento_resizer.php
Resizes Images for isolated/specific magento (admin) server
Created By: Samuel Maciel Sampaio (samukasmk@gmail.com) [20130828]
References where I got the core:
http://stackoverflow.com/questions/2474117/how-to-get-a-products-image-in-magento
http://stackoverflow.com/questions/10426210/how-to-get-product-image-in-magento
Special Thanks for stackoverflow users:
Suman-PHP4U (http://stackoverflow.com/users/795510/suman-php4u)
silvo (http://stackoverflow.com/users/295614/silvo)
Ricardo Martins (http://stackoverflow.com/users/529403/ricardo-martins)
Mitch Thompson (http://stackoverflow.com/users/1399382/mitch-thompson)
gowri (http://stackoverflow.com/users/430112/gowri)
alex (http://stackoverflow.com/users/297028/alex)
daveshaw (http://stackoverflow.com/users/383710/daveshaw)
Suma Gowda (http://stackoverflow.com/users/1284719/suma-gowda)
Vikrant 33 (http://stackoverflow.com/users/1379084/vikrant-33)
Andriy M (http://stackoverflow.com/users/297408/andriy-m)
Shiv Kumar (http://stackoverflow.com/users/1226172/shiv-kumar)
For execute in command line:
-> Put this script in your magento root path:
EG:
$ cd /var/www/html/my_magento_folder
$ curl -O smk_magento_resizer.php
-> Running resize images creation
$ curl -L http://my-magento.com/smk_magento_resizer.php
-> If you prefer, set this call in cron
$ crontab -e
----
5 * * * * curl -L http://my-magento.com/smk_magento_resizer.php
*/
ini_set('display_errors','on');
require_once 'app/Mage.php';
Mage::app('default');
$collection = Mage::getModel('catalog/product')->getCollection();
foreach ($collection as $product) {
$products = Mage::getModel('catalog/product')->load($product->getId());
echo "---";
echo "<br>";
/* resize functions is used to resize image */
// main image of homepage/catalog
echo Mage::helper('catalog/image')->init($products, 'small_image')->resize(312);
echo "<br>";
// main large size image of product page
echo Mage::helper('catalog/image')->init($products, 'image')->resize(1000,1000);
echo "<br>";
// main small size image of product page
echo Mage::helper('catalog/image')->init($products, 'image')->resize(470,470);
echo "<br>";
// thumbnails images of product page
echo Mage::helper('catalog/image')->init($products, 'thumbnail')->resize(140,140);
echo "<br>";
// image of product in cart
echo Mage::helper('catalog/image')->init($products, 'small_image')->resize(88,77);
echo "<br>";
// thumbnails images of product cart
echo Mage::helper('catalog/image')->init($products, 'thumbnail')->resize(75);
echo "<br>";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment