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

ActiveLibrary

lastwhitebird/croppa-multidir
=============================

Image thumbnail creation through specially formatted URLs for Laravel

4.7.1(8y ago)015MITPHPPHP &gt;=5.5.0

Since Apr 3Pushed 8y ago1 watchersCompare

[ Source](https://github.com/lastwhitebird/croppa)[ Packagist](https://packagist.org/packages/lastwhitebird/croppa-multidir)[ RSS](/packages/lastwhitebird-croppa-multidir/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (9)Versions (44)Used By (0)

Croppa
======

[](#croppa)

[![Packagist](https://camo.githubusercontent.com/67da1bf3de45713fce9cf0f5f062ef47e28fce6deb482b35b2827edb5710506b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f626b776c642f63726f7070612e737667)](https://packagist.org/packages/bkwld/croppa) [![Build Status](https://camo.githubusercontent.com/df71796f94d3260bace307f1354ee3651993d727ce63e4c34bd2c20a8cb73c07/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f424b574c442f63726f7070612e737667)](https://travis-ci.org/BKWLD/croppa)

Croppa is an thumbnail generator bundle for Laravel 4.x, 5.x and Lumen (local storage only). It follows a different approach from libraries that store your thumbnail dimensions in the model, like [Paperclip](https://github.com/thoughtbot/paperclip). Instead, the resizing and cropping instructions come from specially formatted urls. For instance, say you have an image with this path:

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

```

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

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

```

This file, of course, doesn't exist yet. Croppa listens for specifically formatted image routes and build this thumbnail on the fly, outputting the image data (with correct headers) to the browser instead of the 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**, bybassing PHP and all that overhead. In other words, **your app *does not boot* just to serve an image**. This is a differentiating point compared to other, similar libraries.

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

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

[](#installation)

#### 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.

#### Laravel:

[](#laravel)

1. Add Croppa to your project: `composer require bkwld/croppa`
2. If using Laravel &lt; 5.5:
    - Add Croppa as a provider in your `app` config's provider list: `'Bkwld\Croppa\ServiceProvider'`
    - Add the facade to your `app` config's aliases: `'Croppa' => 'Bkwld\Croppa\Facade'`

#### Lumen:

[](#lumen)

1. Add Croppa to your project: `composer require bkwld/croppa`
2. Enable facades and add the facade in bootstrap/app.php: `class_alias('Bkwld\Croppa\Facade', 'Croppa');`.
3. Add the provider in bootstrap/app.php: `$app->register('Bkwld\Croppa\ServiceProvider');`.
4. Create a directory on the project root called 'config' and copy the config file there then rename it to croppa.php.
5. Add a Laravel helpers file like [this one](https://gist.github.com/vluzrmos/30defc977877e0eba7b2) to the files autoloading section in your composer.json.

#### 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";
}
```

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

[](#configuration)

Read the [source of the config file](https://github.com/BKWLD/croppa/blob/master/src/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
```

#### Local src and crops directories

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

The most common scenario, the src images and their crops are created in the doc\_root's "uploads" directory.

```
return [
	'src_dir' => public_path().'/uploads',
	'crops_dir' => public_path().'/uploads',
	'path' => 'uploads/(.*)$',
];
```

Thus, if you have `
