taurus-media/module-image-cleaner
Composer 安装命令:
composer require taurus-media/module-image-cleaner
包简介
Cleanup unused product images
README 文档
README
A performance-optimized Magento 2 module to identify and remove unused product images.
Features
- Safe for Large Catalogs: Uses a temporary database table to index used images, ensuring constant-time lookups.
- Memory Efficient: Uses PHP Generators and Iterators to stream files without loading them all into memory.
- Batch Processing: Supports batching and sleep intervals to minimize system load.
- Trash-first Policy: Unused images are moved to
var/image-cleaner-trash/instead of being deleted immediately. - Automatic Cleanup: A daily cron job automatically purges files from the trash that are older than 7 days.
- Dry-run by Default: Safety first—no images are moved unless the
--deleteflag is explicitly provided and confirmed.
Installation
Place the module code in app/code/Taurus/ImageCleaner.
bin/magento module:enable Taurus_ImageCleaner bin/magento setup:upgrade
Usage
Commands
Basic Dry-Run:
bin/magento catalog:image:cleanup
Actually Move Unused Images to Trash:
bin/magento catalog:image:cleanup --delete
Advanced Usage:
bin/magento catalog:image:cleanup --delete --batch-size=1000 --sleep=1 --output-file=unused_images.log
Options
--dry-run: (Default) Scans and reports unused images without moving them.--delete: Enables moving unused images to trash (var/image-cleaner-trash/). Requires manual confirmation.--batch-size=<int>: Number of images to process before sleeping/logging (default: 5000).--sleep=<int>: Seconds to sleep between batches (default: 0).--output-file=<path>: Path (relative tovar/) to log the list of unused images.
Trash & Recovery
When running with --delete, images are moved to var/image-cleaner-trash/.
If you accidentally move images that should have been kept, you can move them back to pub/media/catalog/product/.
A cron job taurus_image_cleaner_trash_purge runs daily at 01:00 and deletes files from the trash that are older than 7 days.
How it Works
- Indexing: The module creates a temporary table
taurus_image_cleaner_used_images. - Collection: It populates this table with image paths from:
catalog_product_entity_media_gallery(Media gallery entries)catalog_product_entity_varchar(Main image, small image, thumbnail, and swatch image attributes)
- Scanning: It uses
RecursiveDirectoryIteratorto scanpub/media/catalog/product/. - Validation: For each file, it performs a fast indexed lookup against the temporary table.
- Action: If an image is not found in the index, it's marked as unused and optionally moved to trash.
- Cleanup: The temporary database table is dropped after the process completes.
- Maintenance: A cron job cleans up the trash folder periodically.
Safety & Warnings
- Backup Recommended: Always back up your
pub/media/catalog/productdirectory and your database before running with the--deleteflag in a production environment. - Excluded Directories: The module automatically ignores
watermark,tmp,placeholder, and other temporary directories. - Cache Scanning: The module now also scans the
pub/media/catalog/product/cachedirectory. Cached images are considered unused if their corresponding original product image is not found in the database. - Normalized Paths: Only images following the Magento standard structure
pub/media/catalog/product/[a-z0-9]/[a-z0-9]/...are processed.
Requirements
- Magento 2.4+
- PHP 8.1+
taurus-media/module-image-cleaner 适用场景与选型建议
taurus-media/module-image-cleaner 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 taurus-media/module-image-cleaner 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 taurus-media/module-image-cleaner 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 16
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-03