I had a problem adding a product image programatically. Here's the code I used:

    ->addImageToMediaGallery('/test.jpg', array('image','thumbnail','small_image'), false, false);

$product = $productRepository->save($product);

When run, it throws this error:

Uncaught exception 'Magento\Framework\Exception\LocalizedException' with message 'There is no MediaGalleryEntryConverter for given type' in vendor/magento/module-catalog/Model/Product/Attribute/Backend/Media/EntryConverterPool.php:48

when I save product and try to update like this link: $product->save();

Throws this error:

Fatal error:Uncaught InvalidArgumentException: Required parameter 'theme_dir' was not passed in .../vendor/magento/framework/View/Design/Fallback/Rule/Simple.php:61

Any ideas ?

5 Answers 5


Maybe you should initialize the gallery first:

->setMediaGallery (array('images'=>array (), 'values'=>array ())) 
->addImageToMediaGallery('/test.jpg', array('image','thumbnail','small_image'), false, false);

In your back-end, go to Content > Design > Configuration. Then set the themes of your front-end. Save it. Then the issue should go away.




You may check the new product gallery management classes for Magento 2.1 here:



I found the solution for if someone needs future, This is theme configuration file problem when I update 2.0.x to 2.1 forgot to update all necessary theme files settings to 2.1, after that my problem solved.

        $baseImage = $value[19];
        $singleImage = explode(',', $baseImage);
        $addtionalImages = $value[20];
        $totalImages = explode(',', $addtionalImages);
        $baseImagePath = $this->dir->getRoot() . '/' . DirectoryList::PUB . '/media/import/' . $value[19];
        if (count($singleImage)>0) {
            $product->addImageToMediaGallery($baseImagePath, ['image', 'small_image', 'thumbnail'], false, false);
        if (count($totalImages)>1) {
            for ($i=1; $i<count($totalImages); $i++) {
                $addImagePath = $this->dir->getRoot() . '/' . DirectoryList::PUB . '/media/import/' . $totalImages[$i];
                $product->addImageToMediaGallery($addImagePath, [], false, false);

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.