Download the PHP package baldwin/magento2-module-image-cleanup without Composer

On this page you can find all versions of the php package baldwin/magento2-module-image-cleanup. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package magento2-module-image-cleanup

Image Cleanup module for Magento 2

Purpose

When adding products in your webshop, eventually you'll also have to delete some of those products. But sometimes Magento doesn't remove images associated with the products that you delete.
So you'll have to manually delete them from time to time from disk, which is hard to do manually. This module gives you some options to delete those lingering unused images from the disk so you can recover some diskspace on your server.

Implemented Features

Watch out

Compatibility

Installation

You can use composer to install this module:

Or download the code and put all the files in the directory app/code/Baldwin/ImageCleanup

After which you can then activate it in Magento using:

Usage

There are 4 command line commands you can use execute:

There are some extra options for some of these commands:

The -n option can be used if you want to setup a cronjob to regularly call these cleanup commands, it will not ask for confirmation before removing files, and will just assume you said 'yes, go ahead' (which can be dangerous!)

The module will output all the things it deleted in a log file {magento-project}/var/log/baldwin-imagecleanup.log so you can inspect it later in case you want to figure out why something got removed.

For optimal & fastest cleanup, it's advised to run the commands in this order:

  1. bin/magento catalog:images:remove-obsolete-db-entries
  2. bin/magento catalog:images:remove-unused-hash-directories
  3. bin/magento catalog:images:remove-unused-files
  4. bin/magento catalog:images:remove-corrupt-resized-files

If you don't run these in this order, it might mean you'll need to run some of them a second time for them to find more things to cleanup or it might mean that they'll take longer then needed.

Configuration

There is a configuration section in the backoffice under: Stores > Configuration > Catalog > Catalog > Product Image Cleanup Settings

Documentation about resized/cached directories

Magento saves resized product images in certain directories in pub/media/catalog/product/cache The directory names are basically an md5 hash of a bunch of parameters like: width, height, background-color, quality, rotation, ... (which tend to be defined in the etc/view.xml file of themes) Sometimes, Magento tweaks how the hash gets calculated in certain newer versions of Magento, or your theme changes some parameter which both can make those hashes no longer being used.

This module has the option to detect such directories and can remove them together with all the files in there.

Note to self

In our class Baldwin\ImageCleanup\Finder\UnusedCacheHashDirectoriesFinder, we borrowed some code from core Magento that was private and not easily callable. We made only very slight changes to deal with coding standards and static analysis, but it's mostly the same as the original source. These pieces of code were based on code that didn't really change since Magento 2.3.4.

It's important that we check with every single new Magento version that gets released, that the code in Magento\MediaStorage\Service\ImageResize doesn't change in such a way that we need to adapt our own implementation.

So this is something that needs to be double checked with every new Magento release.


All versions of magento2-module-image-cleanup with dependencies

PHP Build Version
Package Version
Requires php Version ~7.3.0 || ~7.4.0 || ~8.1.0 || ~8.2.0 || ~8.3.0
magento/framework Version ^102.0.4 || ^103.0
magento/module-catalog Version ^103.0.4 || ^104.0
magento/module-eav Version ^102.0.4
magento/module-store Version ^101.0.4
magento/module-theme Version ^101.0.4
symfony/console Version ^4.0 || ^5.0 || ^6.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package baldwin/magento2-module-image-cleanup contains the following files

Loading the files please wait ....