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
$image->backgroundColor(array(255,255,255));
$image->keepAspectRatio(true);
$image->resize(216, 139);
$image->save('/full/fs/path/to/save/to.jpg');
Related cards:
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-...
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...
Image Resize Helper Composition
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.
![](http://mikewhitby.co.uk/makandra-...
Create Admin User/Role via SQL
Fasntastic webpage which allows you to create a new admin user and role via SQL - it does all the SQL generation for you and also looks lovely!
Reindex Via Code
An example of code qhich allows you to reindex:
$indexer = Mage::getSingleton('index/indexer');
$process = $indexer->getProcessByCode('catalog_product_price');
$process->reindexEverything();
The following are indexer codes which you ...
Stop Controller Dispatch
In an action controllers preDispatch() method you can stop dispatch by calling the following:
$this->setFlag('', self::FLAG_NO_DISPATCH, true);
If you were listening via an observer, your code would look like this:
public function someO...
Nginx Virtual Store Subdirectories
Note - this article only applies to nginx and PHP-FPM!
If you want to have stores which are accessed via subdirectories as opposed to domain names, the standard method I've found is to make a directory with a copy of index.php
in it, using ...
Product Attribute Addition
This code shows all possible configuration options for an attribute that I know of, you need not include all of these when adding an attribute (although it won't hurt)
$installer = Mage::getResourceModel('catalog/setup', 'catalog_setup');
...
Adding Breadcrumbs
Via code (usually in a controller):
$crumbs = Mage::app()->getLayout->getBlock('breadcrumbs');
$crumbs->addCrumb('home', array(
'label' => 'Home',
'title' => 'Go to Home Page',
'link' => Mage::getUrl('')
));
V...
Adding A CSS Class To The Body Tag
To add a class via layout XML:
<reference name="root">
<action method="addBodyClass"><classname>whatever</classname></action>
</reference>
Or to add via code, from a controller or block
if ($root = $this->getLayout()->getBlo...