0

I am currently displaying the product images for product editing. In this I have to get the produt images and insert into the 'src' of an html element.

I know how to get the product image ..But how can i get its data and this data can be set as src of an img html element?

Thanks in advance..

6
  • have you try any code for this?
    – Keyul Shah
    Sep 26, 2014 at 9:27
  • yes @KeyulShah .I tried this.'if(count($product->getMediaGalleryImages())>0){ foreach($product->getMediaGalleryImages as $image){ Mage::log($image->getUrl()); } }'.But It count is 0 even this product has one image. Sep 26, 2014 at 9:31
  • As per Standard if you want to fetch the product Image then you can try $product_image = Mage::helper('catalog/image')->init($productmodel,'small_image')->keepFrame(true)->resize(width,height).'';
    – Keyul Shah
    Sep 26, 2014 at 9:35
  • make sure you have assign small_image at product level don't need to fetch data as per your logic
    – Keyul Shah
    Sep 26, 2014 at 9:36
  • Thank you @KeyulShah .I am trying to get the image data as php Imagick readImage().. Sep 26, 2014 at 9:38

1 Answer 1

0

I Solved My problem with following code:

<?php 
$image = "pro-image-1.jpg";
$image_data=base64_encode(file_get_contents(Mage::helper('catalog/image')->init($product,'image')));
$src = 'data:'.mime_content_type($image).';base64,'.$image_data;
?>
<img src='<?php echo $src; ?> '/>

Source.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.