Overtime your Magento 2 media directory can become quite bloated, with images that are no longer used. Just identifying the images can be hard enough sometimes. This guide will take you through the process of how to identify and clean up media images.
1. Install Hackathon Module
The first step is to install the magento-hackathon/module-eavcleaner-m2 module.
This can be done on a instance if your using MDOQ managed Magento hosting, or using your normal development environment.
You then need to release this change to production.
This will need to be a downtime release (one including php bin/magento setup:upgrade) as we have added a new module.
3. Backup media
Before proceeding we recommend creating a copy of your media directory, in the case that any mistakes happen when cleaning up the directory.
4. Identifying Old Media
On your production server run the following
php bin/magento eav:media:remove-unused --dry-run
This will list all the files the module has identified.
5. Removing Old Media
Once you have assessed the list from the previous step and you are happy with it, you can remove the old media with the following
php bin/magento eav:media:remove-unused
(This may take some time to complete)