本文共 932 字,大约阅读时间需要 3 分钟。
根据已经存在的图片地址,生成自定义尺寸的图片。。
处理图片的类是:lib/Varien/Image.php。
public function getThumbnailResize($width, $height = null) {
// actual path of image $imageUrl = Mage::getBaseDir('media').DS.$this->getData("thumbnail"); // path of the resized image to be saved // here, the resized image is saved in media/resized folder $imageResized = Mage::getBaseDir('media').DS."resized_".$this->getData("thumbnail"); // resize image only if the image file exists and the resized image file doesn't exist // the image is resized proportionally with the width/height 135px if (!file_exists($imageResized)&&file_exists($imageUrl)) { $imageObj = new Varien_Image($imageUrl); $imageObj->constrainOnly(TRUE); $imageObj->keepAspectRatio(TRUE); $imageObj->keepFrame(FALSE);$imageObj->resize($width, $height);
$imageObj->save($imageResized); } return (Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB) . "media/" . "resized_".$this->getData("thumbnail")); }转载地址:http://xwcli.baihongyu.com/