I am assigning multiple images onto a product in my magento store with the below:

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

$images_array = array("image1.jpg","image2.jpg","image3.jpg");
$_product->setMediaGallery (array('images'=>array (), 'values'=>array ()));

$i = 1;
foreach($images_array as $img){
    $img_url = $path.$img;
            $_product->addImageToMediaGallery ($img_url, array ('thumbnail','small_image','image'), false, false);
            $_product->addImageToMediaGallery ($img_url, null, false, false);

I am missing the ability to set the image label during the addImageToMediaGallery method. Is this possible?


You need update label after image save

foreach($product->getData('media_gallery') as $each){

    foreach($each as $image) {
        echo "<pre>";
        echo "</pre>";  

        $attributes = $product->getTypeInstance(true)
    $attributes['media_gallery']->getBackend()->updateImage($product, $image['file'], $data=array('position'=>$i,'label'=>$image['file']));

  • Very nice solution, thanks. Do you also happen to know how to add a label for different storeviews? Like for example I want our English storeview to have an English image label string and our Dutch storeview a Dutch image label. – SuperDicq Feb 15 '19 at 15:34

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.