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..

  • have you try any code for this?
    – Keyul Shah
    Sep 26 '14 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 '14 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 '14 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 '14 at 9:36
  • Thank you @KeyulShah .I am trying to get the image data as php Imagick readImage().. Sep 26 '14 at 9:38

I Solved My problem with following code:

$image = "pro-image-1.jpg";
$src = 'data:'.mime_content_type($image).';base64,'.$image_data;
<img src='<?php echo $src; ?> '/>



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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