How to get a product's image in Magento?

后端 未结 12 1116
慢半拍i
慢半拍i 2020-12-01 06:32

I\'m running on version 1.3.2.1, but on my client\'s server they had Magento 1.3.0 so my previous code to display images for my local copy,

echo $this->he         


        
12条回答
  •  北海茫月
    2020-12-01 06:56

    You can try to replace $this-> by Mage:: in some cases. You need to convert to string.

    In my case i'm using DirectResize extension (direct link), so my code is like this:

    (string)Mage::helper('catalog/image')->init($_product, 'image')->directResize(150,150,3)
    

    The ratio options (3rd param) are :

    • none proportional. The image will be resized at the Width and Height values.
    • proportional, based on the Width value 2
    • proportional, based on the Height value 3
    • proportional for the new image can fit in the Width and the Height values. 4
    • proportional. The new image will cover an area with the Width and the Height values.

    Update: other info and versions here


    The common way, without plugin would be:

    (string)Mage::helper('catalog/image')->init($_product, 'image')->resize(150)
    

    You can replace 'image' with 'small_image' or 'thumbnail'.

提交回复
热议问题