PHPackages                             gnahotelsolutions/image-cacher - 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. [Caching](/categories/caching)
4. /
5. gnahotelsolutions/image-cacher

ActiveLibrary[Caching](/categories/caching)

gnahotelsolutions/image-cacher
==============================

Creates a resized or cropped version of the image in the cache directory

4.0.5(2w ago)66.2k—3.6%2[1 PRs](https://github.com/gnahotelsolutions/image-cacher/pulls)MITPHPPHP ^8.2CI failing

Since Feb 20Pushed 2w ago5 watchersCompare

[ Source](https://github.com/gnahotelsolutions/image-cacher)[ Packagist](https://packagist.org/packages/gnahotelsolutions/image-cacher)[ Docs](https://github.com/gnahotelsolutions/image-cacher)[ RSS](/packages/gnahotelsolutions-image-cacher/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)Dependencies (4)Versions (28)Used By (0)

Create smaller versions of the same image
=========================================

[](#create-smaller-versions-of-the-same-image)

[![Latest Version on Packagist](https://camo.githubusercontent.com/05906bf4224f880910e02746a895260169958621fb9869232e4360108dfc33fb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f676e61686f74656c736f6c7574696f6e732f696d6167652d6361636865722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/gnahotelsolutions/image-cacher)[![Build status](https://github.com/gnahotelsolutions/image-cacher/actions/workflows/php.yml/badge.svg)](https://github.com/gnahotelsolutions/image-cacher/actions/workflows/php.yml/badge.svg)[![Quality Score](https://camo.githubusercontent.com/9ee29e1ccc94ad69e00cf3c4009ced19f045538e36f2d664a2405375f60208eb/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f676e61686f74656c736f6c7574696f6e732f696d6167652d6361636865722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/gnahotelsolutions/image-cacher)[![Total Downloads](https://camo.githubusercontent.com/52242efc9470ac4b8a917cf6149306f2caadd256141d855613628f3999a90d98/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f676e61686f74656c736f6c7574696f6e732f696d6167652d6361636865722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/gnahotelsolutions/image-cacher)

With this package you can create smaller versions of the same image to optimize user's transfer data. What's the point of downloading a 3000x3000 image on a 200x200 thumbnail? This package is very helpful when dealing with [responsive images](https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images)

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

[](#installation)

You can install the package via composer:

```
composer require gnahotelsolutions/image-cacher
```

Usage
-----

[](#usage)

```
use GNAHotelSolutions\ImageCacher\Cacher;
use GNAHotelSolutions\ImageCacher\Image;

// Image located in public/img/hotel/rooms/double-room.jpg
$image = new Image('hotel/rooms/double-room.jpg', 'img');

$resized = (new Cacher())->resize($image, 1920, 1080); // Get a smaller version of the image or the same if the size is smaller.

$cropped = (new Cacher())->crop($image, 1920, 1080); // Get a cropped version of the image.
```

### Generating a thumbnail

[](#generating-a-thumbnail)

```
