本文主要是介绍magento----已经存在的图片地址,生成自定义尺寸的图片,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
根据已经存在的图片地址,生成自定义尺寸的图片。。
处理图片的类是: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"));
}
这篇关于magento----已经存在的图片地址,生成自定义尺寸的图片的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!