PHPackages                             webcito/php-auto-image-resizer - 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. webcito/php-auto-image-resizer

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

webcito/php-auto-image-resizer
==============================

description

024PHP

Since May 24Pushed 1y ago1 watchersCompare

[ Source](https://github.com/ThomasDev-de/php-auto-image-resizer)[ Packagist](https://packagist.org/packages/webcito/php-auto-image-resizer)[ RSS](/packages/webcito-php-auto-image-resizer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

php-auto-image-resizer
======================

[](#php-auto-image-resizer)

A PHP file that scales and delivers images based on the screen width.

Requirements
------------

[](#requirements)

You must have at least PHP 8.2 with the PHP extension ext-imagick.

Preparation
-----------

[](#preparation)

First, the HTACCESS file must be adapted or created in the document root.

Add the following lines:

```

    # Turning on the apache rewrite engine
    RewriteEngine On
     # Specifies the base URL for per-directory rewrites
    RewriteBase /
    # First rule: If the requested path is "image-resizer.php", stop processing further rules.
    # ^image-resizer\.php$ - is a regular expression that exactly matches "image-resizer.php"
    # [L] is a flag that tells mod_rewrite to stop processing the rule set
    RewriteRule ^image-resizer\.php$ - [L]

    # Second rule: If the requested URI is any(.) file that ends (anchors the end position $)
    # with jpeg, jpg, gif, png, or webp, rewrite the request to "/image-resizer.php"
    # \.(?:jpeg|jpg|gif|png|webp)$ - is a regular expression that matches jpeg, jpg, gif, png, or webp files.
    # /image-resizer.php is the target where the matched request will be rewritten to
    # [QSA,L] are flags. QSA, or 'QueryString Append', forces the rewrite engine to append
    # a query string part in the substitution string to the existing one. L, or 'last',
    # stops mod_rewrite from processing any more rules.
    RewriteRule \.(?:jpeg|jpg|gif|png|webp)$ /image-resizer.php [QSA,L]

```

The lines cause all images with the extension jpeg, jpg, gif, png or webp to be sent to a PHP file called image-resizer.php. The name of the PHP file can be changed, but must then also be in the htaccess can be adjusted.

Make sure your web server has the rewrite module active. I describe it using Apache2.

For Apache2, it might look like this:

```
sudo a2enmod rewrite
```

If not already done, set AllowOverride to All: Apache does not allow `.htaccess` overrides by default. Edit your apache2.conf file (usually found in /etc/apache2/apache2.conf) and change AllowOverride None to AllowOverride All for the corresponding directory(s).

```

    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted

```

Restart the web server:

```
sudo service apache2 restart
```

Installation
------------

[](#installation)

### via composer

[](#via-composer)

```
composer install webcito/php-auto-image-resizer dev-main
composer dump-autoload
```

### manually

[](#manually)

Load the PHP class `/src/ImageCache.php` into your project.

Use
---

[](#use)

Create a PHP file called image-resizer.php in the DocumentRoot

The contents of the file should look something like this:

```
