title: Magento programmatically remove product images
body: <p>This must be a such a simple programming task that I absolutely  cannot find any information about it on the net. Basically, I'm trying to DELETE product images. I want to delete all images from a product's media gallery. Can I do this without wading through a million lines of code for such a simple task?</p>
  
  <p>Please note that I've already tried this:</p>
  
  <pre><code>$attributes = $product-&gt;getTypeInstance()-&gt;getSetAttributes();
  if (isset($attributes['media_gallery'])) {
      $gallery = $attributes['media_gallery'];
      $galleryData = $product-&gt;getMediaGallery();//this returns NULL
  
      foreach($galleryData['images'] as $image){
          if ($gallery-&gt;getBackend()-&gt;getImage($product, $image['file'])) {
              $gallery-&gt;getBackend()-&gt;removeImage($product, $image['file']);
          }
      }
  }
  </code></pre>
  
  <p>This absolutely does not work. I'm trying to delete images during an import so that I do not keep accruing duplicates. Any help would be greatly appreciated.</p>