Magento Add image to media gallery

Following snippet used to add image to magento image gallery via script

The snippet can be used in the previous post used to show how to insert the simple product via script having custom attributes

First you need to create the product object via the product model as follows

require_once 'app/Mage.php';

$product = Mage::getModel('catalog/product');

Now once the object in place then you can add the image as product attribute

$product->addImageToMediaGallery('full/path/to/image', array('small_image','thumbnail','image'), false, false);

Note the second parameter that specifies the where to add the image, currently all three given ie small image thumbnail and large image.

Depending on the image name various images can be added setting individual images

The API reference can be found at


What you think ? Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s