Image Resize Helper Composition
Posted Almost 12 years ago. Visible to the public.
The product image resizing goes through a few layers of abstraction, so I thought I'd add a quick UML diagram showing composition through the layers. The resizing ultimately gets done by the gd PHP extension.
Related cards:
Get and Resize Category Images
public function getCategoryImage(Mage_Catalog_Model_Category $category, $width = 250, $height = 250)
{
// return when no image exists
if (!$category->getImage()) {
return false;
}
// return when...
Resizing A Product Image
$helper = Mage::helper('catalog/image');
$helper->init($product, 'image');
$helper->resize(216, 161);
// the helpers __toString() method outputs the url
echo $helper;
![](http://mikewhitby.co.uk/makandra-track.gif?a=resizing-...
Importing Images
Ok so to import images you first need these columns:
-
_media_attribute_id
- the attribute_id ofmedia_gallery
(see below) -
_media_image
- the path of the image, i.e./some_image.jpg
-
_media_lable
- the image label, i.e. "My nice imag...
Helper Block Definition
<config>
<global>
<helpers>
<namespace_module>
<class>Namespace_Module_Helper</class>
</namespace_module>
</helpers>
</global>
</config>
![](http:...
Config Helper Rewrite Definition
<config>
<global>
<helpers>
<catalog>
<rewrite>
<data>Namespace_Module_Helper_Catalog_Data</data>
</rewrite>
</catalog>
...
Boilerplate Helper Class
/**
* Yourcompany.com
*
* PHP Version 5
*
* @category Namespace
* @package Namespace_Module
* @author Your Name <your.name@yourcompany.com>
* @copyright 2012 yourcompany.com
* @license http:...
Resizing via Varien_Image
$image = new Varien_Image('/full/fs/path/to/image.jpg');
// you cannot use method chaining with Varien_Image
$image->constrainOnly(false);
$image->keepFrame(true);
// avoid black borders by setting background colour
$i...
Boilerplate Admin Controller
/**
* Yourcompany.com
*
* PHP Version 5
*
* @category Namespace
* @package Namespace_Module
* @author Your Name <your.name@yourcompany.com>
* @copyright 2012 yourcompany.com
* @license http:...
Getting The Amount Of Items in the Cart
To get the amount of line items (i.e. 10 of 1 product is 1):
Mage::helper('checkout/cart')->getItemsCount();
To get the total number of items (i.e. 10 of 1 product is 10):
Mage::helper('checkout/cart')->getSummaryCount();
![](http://mi...
Posted by Mike Whitby to Magento (2012-07-06 14:20)