PHPackages                             navt/reduction - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. navt/reduction

ActiveLibrary[Image &amp; Media](/categories/media)

navt/reduction
==============

Optimization of images size on the site

79PHP

Since Nov 22Pushed 3y ago2 watchersCompare

[ Source](https://github.com/navt/reduction)[ Packagist](https://packagist.org/packages/navt/reduction)[ RSS](/packages/navt-reduction/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Reduction
=========

[](#reduction)

Utility Reduction is designed to optimize the size of images on a website. Often, users upload too large images to the server :)
The logic of the application is as follows: first, directories are inspected for the presence of image files (jpeg, png, gif) larger than a certain size, then the found files can be overwritten with the optimal width and height (the proportions remain correct). Files are searched recursively.
You can select images not only by the file size, but also by the size of the "long" side of the image. The settings are placed in the file `data/config.json`.
To navigate how much the application is running in time and consumes memory, the Marker class is written. The results are written to the log.

Let's look at the file `data/config.json`, in it:
`"folderPath"` - relative path to target images directory from `app.php`
`"mode"` - mode for selecting images either `"ImageSide"`, or `"FileSize"`
`"maxFileSize"` - in the `"FileSize"` mode, files larger than the specified size in bytes will be selected
`"maxImageSide"` - in the `"ImageSide"` mode, files with a long side larger than the value in pixels specified here will be selected
`"maxWidth"` - width of new images, if images are horizontal in pixels
`"maxHeight"` - height of new images, if images are vertical in pixels
`"ableTypes"` - array of file extensions, optionally there should be 3 values, select one or two for "dot" work
`"quality"` - the `quality` parameter when recording jpeg and png images using the imagejpeg(), imagepng() functions

Usage
-----

[](#usage)

Consider the case where you place the `vendor` directory in the root directory of your site.

```
# go to the root directory of site
$ cd root-of-site
# require package navt/reduction
$ composer require navt/reduction:dev-master
# make sure that there is no app.php file and no data directory in the root directory.
# copy
$ cp vendor/navt/reduction/app.php ./
$ cp -r vendor/navt/reduction/data ./
```

Edit` data/config.json` and `app.php` in accordance with your current task.
Run

```
$ php -f app.php
```

Initially, the `app.php` file contains the code to inspect the target directory. If you decide that it is time to reduce the size of the selected files, then the code in `app.php` should be changed to:

```
