开发者

How to resize image coming from media in frontend?

开发者 https://www.devze.com 2023-03-25 17:42 出处:网络
i am trying to resize the images on frontend that are uploaded to my folder in media. I tried this code but its not displaying anything for me :(

i am trying to resize the images on frontend that are uploaded to my folder in media. I tried this code but its not displaying anything for me :(

   foreach($this->myBanners() as $_testing_banners){

    $img_location = Mage::getBaseUrl('media'). 'Banners/images/demand/'.$_testing_banners['bannerimage'];

    $image= new Varien_Image($img_location);

    echo '<img src="'.$image->resize(200, 200).'" alt="" />';

    }

although this shows images but original size :( not resized :(

foreach($this->myBanners() as $_testing_banners){

$开发者_C百科img_location = Mage::getBaseUrl('media'). 'Banners/images/demand/'.$_testing_banners['bannerimage'];


echo '<img src="'.$img_location.'" alt="" />';

}

so how can i resize them ????? any idea ???


I think this way it will work.

 foreach($this->myBanners() as $_testing_banners){

    $img_location = Mage::getBaseDir('media'). 'Banners/images/demand/'.$_testing_banners['bannerimage'];

    $imageResized = Mage::getBaseDir('media'). 'Banners/images/demand/resized/'.$_testing_banners['bannerimage'];          

    $image= new Varien_Image($img_location);
    $image->resize(200, 200);
    $image->save($imageResized);

    echo '<img src="'.Mage::getBaseUrl('media'). 'Banners/images/demand/resized/'.$_testing_banners['bannerimage'].'" alt="" />';

    }
  • Used getBaseDir instead of getBaseUrl.
  • Saved image after resize
  • Used the resized image path in image source

Hope it helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消