Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8550085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:52:13+00:00 2026-06-11T13:52:13+00:00

In Magento, the following code will programmatically add an image a product’s image gallery

  • 0

In Magento, the following code will programmatically add an image a product’s image gallery

//set store to admin id so we can save a product
Mage::app()->getStore()->setId(Mage_Core_Model_App::ADMIN_STORE_ID);

//load a product with an id of 2514
$product = Mage::getModel('catalog/product')->load('2514');

//add the image
$product->addImageToMediaGallery('/tmp/test.png','image',false,false);        

This, as expected, will add an image to a product’s media gallery, and this image will be selected as the product’s “Base Image”. However, the “small_image” and “thumbnail” images will not be selected for this image.

If the following code is used

$product->addImageToMediaGallery('/tmp/test.png','image',false,false);        
$product->addImageToMediaGallery('/tmp/test.png','small_image',false,false);        
$product->addImageToMediaGallery('/tmp/test.png','thumbnail',false,false);        

Magento will add three new images to the media gallery. One with Base Image selected, one with Small Image selected, and a third with thumbnail.

Is it possible to signal Magento that when you call

$product->addImageToMediaGallery('/tmp/test.png','image',false,false);        

that it should automatically generate the small image and the thumbnail image?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T13:52:14+00:00Added an answer on June 11, 2026 at 1:52 pm

    Try with:

    $product->addImageToMediaGallery('/tmp/test.png',array('image', 'small_image', 'thumbnail'),false,false); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've set up the following multi site structure in Magento (1.3.2.4); Site | Store
I am able to add custom links to Magento's top.links with the following code
I've tried to create a product with the following code on a Magento 1.5.1.
The following code runs fine under Magento 1.6 but raises a Mage_Core_Exception (message: 'Cannot
I really need the following in magento. When a customer shows the config product
Can some professional experienced Magento developer tell me how to accomplish the following in
I have the following magento XML code: <action method=addLink translate=label module=customer><name>myorders</name><path>chepri/myorders/customer</path><label>Standing Orders</label></action> I was
I have the following code to grab a list of Products $collection = Mage::getModel('catalog/product')->getCollection();
I am using the following piece of code to allow users to set featured
In Magento I'm using the following code to get a bestsellers data collection: Model

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.