2013-10-16 29 views
0

我使用下面的代碼通過他們的標籤,以顯示產品圖片:Magento的調整圖像

$productId = $this->getProduct_id(); 
$_product = Mage::getModel('catalog/product')->load($productId); 


src="<?php echo $_product->getMediaGalleryImages()->getItemByColumnValue('label', 'mylabel')->getUrl(); ?>" 

我如何調整圖片的大小?

+0

$ _image->調整(50,50); –

回答

1

//圖片名稱

$ image =「」;

// actual image path 

// $ imageUrl = Mage :: getBaseDir('media')。 DS。'test'。 DS。$ image;

你的情況圖片網址

$imageUrl="<?php echo $_product->getMediaGalleryImages()->getItemByColumnValue('label', 'mylabel')->getUrl(); ?>" 


    // Give resized image path to be saved 
    // here, the resized image will save in media/test/resized folder 

$ imageResized =法師:: getBaseDir( '媒體')。 DS。'test'。 DS。'resized'。 DS。$ image;

// image will resize only if the image file exists and the resized image file doesn't exist 



if (!file_exists($imageResized) && file_exists($imageUrl)) 
    { 
     $imageObj = new Varien_Image($imageUrl); 
     $imageObj->constrainOnly(TRUE); 
     $imageObj->keepAspectRatio(TRUE); 
     $imageObj->keepFrame(FALSE); 
     $imageObj->resize(300, null); 
     $imageObj->save($imageResized); 
    } 

希望這將幫助你