Remove Main Product Image in Magento CE 1.7.0.2

ce-1.7.0.2imageproduct

I want to programmatically remove ALL product images as I am going to programmatically re-add all images. I've managed to remove gallery images (thanks to https://stackoverflow.com/questions/5709496/magento-programmatically-remove-product-images) but I can't get rid of that main image.

I can delete it from the file system obviously but that still leaves a placeholder (with broken image).

Any tips on how to remove the image without removing the product would be very appreciated.

Best Answer

    $attrCode         = 'media_gallery';
    $mediaGalleryData = $product->getData($attrCode);
    if (isset($mediaGalleryData['images'])) {
        foreach ($mediaGalleryData['images'] as &$image) {
            $image['removed'] = 1;
        }
        $product->setData($attrCode, $mediaGalleryData);
        $product->save();
    }