magento----已经存在的图片地址,生成自定义尺寸的图片

来源:互联网 发布:用友软件下载免费版 编辑:程序博客网 时间:2024/06/07 12:24

根据已经存在的图片地址,生成自定义尺寸的图片。。

处理图片的类是: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"));
    }

原创粉丝点击