Replace Product Images in Magento 2
Having old, low-res image and now looking for a solution to replace product images in Magento 2 with new ones? Or maybe you have uploaded wrong or have duplicated images as a result of upload/ update of products, which are already in the database with images assigned?
In this tutorial we will show you how to easily clear your image gallery and get rid of images shown twice.
Delete Duplicate Magento Images From Directory
One day you may notice that you have multiple identical images for the same product. This happens pretty often in case you haven’t updated the image location in the CSV to the cached version or import fails and you re-run it. Instead of replacing the existing images, Magento will annoyingly again add the same image, creating create a copy with _1.jpg etc at the end of filename.
Once images are loaded they end up in the media/catalog/product directory. There you will find a series of subfolders (two levels deep) that represent image name (one letter for each level), e.g. picture.jpg will be loaded to media/catalog/product/p/i/picture.jpg
You can remove duplicates with underbar and number in the name from each of them. However, this seems much of a headache and manual work to do.
Remove Old Magento Product Images While Importing New Ones
If you do not want to go through every 2 subfolders of /media/catalog/product directory in order to delete from there old images, use Store Manager for Magento tool.
Comparing to scripts running, it does not require tech knowledge to use and should not be adjusted to definite Magento version (as it supports both Magento 1 and 2). Just install it on our Windows-based PC and test how it works!
With Store Manager there is no need to make any additional actions before import. Simply run the process from the application.
Select the file with correct images that you are going to upload.
Specify correct delimiter settings for the file to be consumed by the system properly.
Furthermore, assign small, base, thumbnail and gallery columns of CSV file to corresponding database fields.
Configure import method and additional import settings if necessary and you are free to go with import itself.
Detect Duplicate Magento Images Running Diagnostics
Store Manager for Magento Adobe Commerce (Magento Enterprise) also includes Store Diagnostic functionality allowing to searched for products with duplicated images.
After you run it, you will get the list of goods with identical images. So you will be able either to delete unnecessary product images manually or re-do import to substitute incorrect images.