PHPackages                             bkwld/croppa - 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. bkwld/croppa

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

bkwld/croppa
============

Image thumbnail creation through specially formatted URLs for Laravel

8.0.0(2mo ago)506511.0k↓28.2%88[24 issues](https://github.com/BKWLD/croppa/issues)20MITPHPPHP ^8.1CI failing

Since Apr 3Pushed 2mo ago26 watchersCompare

[ Source](https://github.com/BKWLD/croppa)[ Packagist](https://packagist.org/packages/bkwld/croppa)[ Docs](https://github.com/bkwld/croppa)[ RSS](/packages/bkwld-croppa/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (10)Dependencies (24)Versions (66)Used By (20)

Croppa
======

[](#croppa)

[![Latest Version on Packagist](https://camo.githubusercontent.com/67da1bf3de45713fce9cf0f5f062ef47e28fce6deb482b35b2827edb5710506b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f626b776c642f63726f7070612e737667)](https://packagist.org/packages/bkwld/croppa)[![MIT Licensed](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](LICENSE.md)[![run-tests](https://github.com/bkwld/croppa/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/bkwld/croppa/actions/workflows/tests.yml)[![PHPStan](https://github.com/bkwld/croppa/actions/workflows/phpstan.yml/badge.svg?branch=master)](https://github.com/bkwld/croppa/actions/workflows/phpstan.yml)[![Rector](https://github.com/bkwld/croppa/actions/workflows/rector.yml/badge.svg?branch=master)](https://github.com/bkwld/croppa/actions/workflows/rector.yml)[![Pint](https://github.com/bkwld/croppa/actions/workflows/pint.yml/badge.svg)](https://github.com/bkwld/croppa/actions/workflows/pint.yml)

Croppa is a thumbnail generator bundle for Laravel. It follows a different approach from libraries that store your thumbnail dimensions in the model. Instead, the resizing and cropping instructions come from specially formatted URLs.

```
/storage/uploads/09/03/screenshot.png

```

To produce a 300x200 thumbnail of this, you would change the path to:

```
/storage/uploads/09/03/screenshot-300x200.png

```

This file, of course, doesn’t exist yet. Croppa listens for specifically formatted image routes and builds this thumbnail on the fly, outputting the image data (with correct headers) to the browser instead of returning a 404 response.

At the same time, it saves the newly cropped image to the disk in the same location (the "…-300x200.png" path) that you requested. As a result, **all future requests get served directly from the disk**, bypassing PHP and avoiding unnecessary overhead. In other words, **your app does not need to boot up just to serve an image**. This is a key differentiator compared to other similar libraries.

Since version 4.0, Croppa allows images to be stored on remote disks such as S3, Dropbox, FTP, and more, thanks to [Flysystem integration](http://flysystem.thephpleague.com/).

Server Requirements:
--------------------

[](#server-requirements)

- [gd](http://php.net/manual/en/book.image.php)
- [exif](http://php.net/manual/en/book.exif.php) - Required if you want to have Croppa auto-rotate images from devices like mobile phones based on exif meta data.

### Nginx

[](#nginx)

When using [Nginx HTTP server boilerplate configs](https://github.com/h5bp/server-configs-nginx), add `error_page 404 = /index.php?$query_string;` in the location block for Media, located in file h5bp/location/expires.conf.

```
# Media: images, icons, video, audio, HTC
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
  error_page 404 = /index.php?$query_string;
  expires 1M;
  access_log off;
  add_header Cache-Control "public";
}
```

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

[](#installation)

Add Croppa to your project: `composer require bkwld/croppa`

Configuration
-------------

[](#configuration)

Read the [source of the config file](https://github.com/BKWLD/croppa/tree/master/config/config.php) for documentation of the config options. Here are some examples of common setups (additional [examples can be found here](https://github.com/BKWLD/croppa/wiki/Examples)):

You can publish the config file into your app’s config directory, by running the following command:

```
php artisan vendor:publish --tag=croppa-config
```

#### Local src and crops directories

[](#local-src-and-crops-directories)

The most common scenario, the src images and their crops are created in the default ”public” Laravel disk.

```
return [
    'src_disk' => 'public',
    'crops_disk' => 'public',
    'path' => 'storage/(.*)$',
];
```

Thus, if you have ``, the returned URL will be `/storage/file-200x_.jpg`, the source image will be looked for at `'/storage/app/public/file.jpg'`, and the new crop will be created at `'/storage/app/public/file-200x_.jpg'`. And because the URL generated by `Croppa::url()` points to the location where the crop was created, the web server (Apache, etc) will directly serve it on the next request (your app won’t boot just to serve an image).

#### Src images on S3, local crops

[](#src-images-on-s3-local-crops)

This is a good solution for a load balanced environment. Each app server will end up with it’s own cache of cropped images, so there is some wasted space. But the web server (Apache, etc) can still serve the crops directly on subsequent crop requests. A tmp\_disk must also be defined to temporarily store the source image.

```
// Croppa config.php
return [
    'src_disk' => 's3',
    'tmp_disk' => 'temp',
    'crops_disk' => 'public',
    'path' => 'storage/(.*)$',
];
```

Thus, if you have ``, the returned URL will be `/storage/file-200x100.jpg`, the source image will be looked for immediately within the S3 bucket that was configured as part of the Flysystem instance, and the new crop will be created at `/storage/app/public/file-200x100.jpg`.

Usage
-----

[](#usage)

The URL schema that Croppa uses is:

```
/path/to/image-widthxheight-option1-option2(arg1,arg2).ext

```

So these are all valid:

```
/storage/image-300x200.webp             // Crop to fit in 300x200
/storage/image-_x200.webp               // Resize to height of 200px
/storage/image-300x_.webp               // Resize to width of 300px
/storage/image-300x200-resize.webp      // Resize to fit within 300x200
/storage/image-300x200-quadrant(T).webp // See the quadrant description below

```

#### Croppa::url($url, $width, $height, $options)

[](#croppaurlurl-width-height-options)

To make preparing the URLs that Croppa expects an easier job, you can use the following view helper:

```

```

These are the arguments that Croppa::url() takes:

- $url : The URL of your source image. The path to the image relative to the `src_disk` will be extracted using the `path` config regex.
- $width : A number or null for wildcard
- $height : A number or null for wildcard
- $options - An array of key value pairs, where the value is an optional array of arguments for the option. Supported option are:
    - `resize` - Make the image fit in the provided width and height through resizing. When omitted, the default is to crop to fit in the bounds (unless one of sides is a wildcard).
    - `pad` - Pad an image to desired dimensions. Moves the image into the center and fills the rest with given color. If no color is given, it will use white \[255,255,255\]
    - `quadrant($quadrant)` - Crop the remaining overflow of an image using the passed quadrant heading. The supported `$quadrant` values are: `T` - Top (good for headshots), `B` - Bottom, `L` - Left, `R` - Right, `C` - Center (default).
    - `trim($x1, $y1, $x2, $y2)` - Crop the source image to the size defined by the two sets of coordinates ($x1, $y1, ...) BEFORE applying the $width and $height parameters. This is designed to be used with a frontend cropping UI like [jcrop](http://deepliquid.com/content/Jcrop.html) so that you can respect a cropping selection that the user has defined but then output thumbnails or sized down versions of that selection with Croppa.
    - `trim_perc($x1_perc, $y1_perc, $x2_perc, $y2_perc)` - Has the same effect as `trim()` but accepts coordinates as percentages. Thus, the the upper left of the image is "0" and the bottom right of the image is "1". So if you wanted to trim the image to half the size around the center, you would add an option of `trim_perc(0.25,0.25,0.75,0.75)`
    - `quality($int)` - Set the jpeg compression quality from 0 to 100.
    - `interlace($bool)` - Set to `1` or `0` to turn interlacing on or off
    - `upsize($bool)` - Set to `1` or `0` to allow images to be upsized. If falsey and you ask for a size bigger than the source, it will **only** create an image as big as the original source.

#### Croppa::render($cropurl)

[](#cropparendercropurl)

If you want to create the image programmatically you can pass to this function the url generated by Croppa::url. This will only create the thumbnail and exit.

```
Croppa::render('image-300x200.png');
```

or

```
Croppa::render(Croppa::url('image.png', 300, 200));
```

#### Croppa::delete($url)

[](#croppadeleteurl)

You can delete a source image and all of its crops by running:

```
Croppa::delete('/path/to/src.png');
```

#### Croppa::reset($url)

[](#croppareseturl)

Similar to `Croppa::delete()` except the source image is preserved, only the crops are deleted.

```
Croppa::reset('/path/to/src.png');
```

Console commands
----------------

[](#console-commands)

#### `croppa:purge`

[](#croppapurge)

Deletes **all** crops. This works by scanning the `crops_disk` recursively and matching all files that have the Croppa naming convention where a corresponding `src` file can be found. Accepts the following options:

- `--filter` - Applies a whitelisting regex filter to the crops. For example: `--filter=^01/` matches all crops in the "./public/uploads/01/" directory
- `--dry-run` - Ouputs the files that would be deleted to the console, but doesn’t actually remove

croppa.js
---------

[](#croppajs)

A module is included to prepare formatted URLs from JS. This can be helpful when you are creating views from JSON responses from an AJAX request; you don’t need to format the URLs on the server. It can be loaded via Require.js, CJS, or as browser global variable.

### croppa.url(url, width, height, options)

[](#croppaurlurl-width-height-options-1)

Works just like the PHP `Croppa::url` except for how options get formatted (since JS doesn’t have associative arrays).

```
croppa.url('/path/to/img.jpg', 300, 200, ['resize']);
croppa.url('/path/to/img.jpg', 300, 200, ['resize', { quadrant: 'T' }]);
croppa.url('/path/to/img.jpg', 300, 200, ['resize', { quadrant: ['T'] }]);
```

Run `php artisan asset:publish bkwld/croppa` to have Laravel copy the JS to your public directory. It will go to /public/packages/bkwld/croppa/js by default.

History
-------

[](#history)

Read the Github [project releases](https://github.com/BKWLD/croppa/releases) for release notes.

This package uses [Intervention Image](https://image.intervention.io/) to do all the image resizing. "Crop" is equivalent to its cover() method and "resize" is scale(). Support for interacting with non-local disks provided by [Flysystem](http://flysystem.thephpleague.com/).

###  Health Score

71

—

ExcellentBetter than 100% of packages

Maintenance84

Actively maintained with recent releases

Popularity58

Moderate usage in the ecosystem

Community43

Growing community involvement

Maturity86

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 68.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~75 days

Recently: every ~162 days

Total

64

Last Release

79d ago

Major Versions

3.6.2 → 4.0.02015-04-13

4.11.1 → 5.0.02022-04-18

5.1.0 → 6.0.02022-05-15

6.0.2 → 7.0.02024-05-28

7.0.6 → 8.0.02026-03-22

PHP version history (7 changes)2.0.0PHP &gt;=5.3.0

4.0.0PHP &gt;=5.4.0

4.6.0PHP &gt;=5.5.0

4.9.0PHP ^7.2.5

4.11.0PHP ^7.2.5|^8.0

5.0.0PHP ^8.0.2

7.0.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/77567?v=4)[Robert Reinhard](/maintainers/weotch)[@weotch](https://github.com/weotch)

---

Top Contributors

[![weotch](https://avatars.githubusercontent.com/u/77567?v=4)](https://github.com/weotch "weotch (289 commits)")[![sdebacker](https://avatars.githubusercontent.com/u/134503?v=4)](https://github.com/sdebacker "sdebacker (93 commits)")[![jordanade](https://avatars.githubusercontent.com/u/2799445?v=4)](https://github.com/jordanade "jordanade (6 commits)")[![williamwa](https://avatars.githubusercontent.com/u/1631629?v=4)](https://github.com/williamwa "williamwa (3 commits)")[![xel1045](https://avatars.githubusercontent.com/u/1497697?v=4)](https://github.com/xel1045 "xel1045 (2 commits)")[![Ardakilic](https://avatars.githubusercontent.com/u/2063957?v=4)](https://github.com/Ardakilic "Ardakilic (2 commits)")[![ehsanquddusi](https://avatars.githubusercontent.com/u/186699?v=4)](https://github.com/ehsanquddusi "ehsanquddusi (2 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (2 commits)")[![mgsmus](https://avatars.githubusercontent.com/u/543371?v=4)](https://github.com/mgsmus "mgsmus (2 commits)")[![toyi](https://avatars.githubusercontent.com/u/15825155?v=4)](https://github.com/toyi "toyi (2 commits)")[![gsmeira](https://avatars.githubusercontent.com/u/1690400?v=4)](https://github.com/gsmeira "gsmeira (1 commits)")[![carusogabriel](https://avatars.githubusercontent.com/u/16328050?v=4)](https://github.com/carusogabriel "carusogabriel (1 commits)")[![artrz](https://avatars.githubusercontent.com/u/2359890?v=4)](https://github.com/artrz "artrz (1 commits)")[![mauserrifle](https://avatars.githubusercontent.com/u/1580250?v=4)](https://github.com/mauserrifle "mauserrifle (1 commits)")[![adis-io](https://avatars.githubusercontent.com/u/592907?v=4)](https://github.com/adis-io "adis-io (1 commits)")[![miking7](https://avatars.githubusercontent.com/u/5072816?v=4)](https://github.com/miking7 "miking7 (1 commits)")[![moebrowne](https://avatars.githubusercontent.com/u/8448512?v=4)](https://github.com/moebrowne "moebrowne (1 commits)")[![petebacondarwin](https://avatars.githubusercontent.com/u/15655?v=4)](https://github.com/petebacondarwin "petebacondarwin (1 commits)")[![S1lentAvenger](https://avatars.githubusercontent.com/u/22122511?v=4)](https://github.com/S1lentAvenger "S1lentAvenger (1 commits)")[![bigbozo](https://avatars.githubusercontent.com/u/621152?v=4)](https://github.com/bigbozo "bigbozo (1 commits)")

---

Tags

laravelimageresizethumb

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/bkwld-croppa/health.svg)

```
[![Health](https://phpackages.com/badges/bkwld-croppa/health.svg)](https://phpackages.com/packages/bkwld-croppa)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.7k532.1M19.2k](/packages/laravel-framework)[intervention/image-laravel

Laravel Integration of Intervention Image

1558.1M158](/packages/intervention-image-laravel)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k28.4M134](/packages/laravel-cashier)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

76318.2M110](/packages/laravel-mcp)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9732.3M121](/packages/roots-acorn)[unisharp/laravel-filemanager

A file upload/editor intended for use with Laravel 5 to 10 and CKEditor / TinyMCE

2.1k3.4M80](/packages/unisharp-laravel-filemanager)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
