<?php
$standardImageWidth = 40;
$sourceFilePath = '';
$destinationFilePath = '';
$adapterGd2 = new Varien_Image_Adapter_Gd2();
$adapterGd2->open($sourceFilePath);
$imageWidth = $adapterGd2->getOriginalWidth();
$imageHeight = $adapterGd2->getOriginalHeight();
if($imageWidth > $standardImageWidth)
{
$width = $standardImageWidth;
$scale = $standardImageWidth / $imageWidth;
$height = ceil($scale * $imageHeight);
}
else
{
$width = $imageWidth;
$height = $imageHeight;
}
$adapterGd2->resize($width,$height);
$adapterGd2->save($destinationFilePath);
?>