{"id":21525801,"url":"https://github.com/bkwld/croppa","last_synced_at":"2025-05-14T05:11:51.937Z","repository":{"id":4877571,"uuid":"6032809","full_name":"BKWLD/croppa","owner":"BKWLD","description":"Image thumbnail creation through specially formatted URLs for Laravel.","archived":false,"fork":false,"pushed_at":"2025-02-17T11:11:02.000Z","size":680,"stargazers_count":500,"open_issues_count":23,"forks_count":91,"subscribers_count":29,"default_branch":"master","last_synced_at":"2025-05-14T03:43:11.163Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"elastic/kibana","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BKWLD.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-10-01T16:38:23.000Z","updated_at":"2025-03-14T00:44:22.000Z","dependencies_parsed_at":"2023-01-13T13:16:44.288Z","dependency_job_id":"f8b966d9-c6fc-4ef0-80cb-ef8859a0ed9a","html_url":"https://github.com/BKWLD/croppa","commit_stats":{"total_commits":343,"total_committers":34,"mean_commits":"10.088235294117647","dds":0.3177842565597667,"last_synced_commit":"ade55922a77817972df82f2f00be647ae6ffcbae"},"previous_names":[],"tags_count":64,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BKWLD%2Fcroppa","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BKWLD%2Fcroppa/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BKWLD%2Fcroppa/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BKWLD%2Fcroppa/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BKWLD","download_url":"https://codeload.github.com/BKWLD/croppa/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254076850,"owners_count":22010611,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-24T01:38:31.066Z","updated_at":"2025-05-14T05:11:46.927Z","avatar_url":"https://github.com/BKWLD.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Croppa\n\n[![Packagist](https://img.shields.io/packagist/v/bkwld/croppa.svg)](https://packagist.org/packages/bkwld/croppa)\n\nCroppa 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.\n\n    /storage/uploads/09/03/screenshot.png\n\nTo produce a 300x200 thumbnail of this, you would change the path to:\n\n    /storage/uploads/09/03/screenshot-300x200.png\n\nThis 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.\n\nAt 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.\n\nSince 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/).\n\n## Server Requirements:\n\n- [gd](http://php.net/manual/en/book.image.php)\n- [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.\n\n### Nginx\n\nWhen 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.\n\n```nginx\n# Media: images, icons, video, audio, HTC\nlocation ~* \\.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {\n  error_page 404 = /index.php?$query_string;\n  expires 1M;\n  access_log off;\n  add_header Cache-Control \"public\";\n}\n```\n\n## Installation\n\nAdd Croppa to your project: `composer require bkwld/croppa`\n\n## Configuration\n\nRead 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)):\n\nYou can publish the config file into your app’s config directory, by running the following command:\n\n```php\nphp artisan vendor:publish --tag=croppa-config\n```\n\n#### Local src and crops directories\n\nThe most common scenario, the src images and their crops are created in the default ”public” Laravel disk.\n\n```php\nreturn [\n    'src_disk' =\u003e 'public',\n    'crops_disk' =\u003e 'public',\n    'path' =\u003e 'storage/(.*)$',\n];\n```\n\nThus, if you have `\u003cimg src=\"{{ Croppa::url('file.jpg', 200) }}\"\u003e`, 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).\n\n#### Src images on S3, local crops\n\nThis 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.\n\n```php\n// Croppa config.php\nreturn [\n    'src_disk' =\u003e 's3',\n    'tmp_disk' =\u003e 'temp',\n    'crops_disk' =\u003e 'public',\n    'path' =\u003e 'storage/(.*)$',\n];\n```\n\nThus, if you have `\u003cimg src=\"{{ Croppa::url('file.jpg', 200, 100) }}\"\u003e`, 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`.\n\n## Usage\n\nThe URL schema that Croppa uses is:\n\n    /path/to/image-widthxheight-option1-option2(arg1,arg2).ext\n\nSo these are all valid:\n\n    /storage/image-300x200.webp             // Crop to fit in 300x200\n    /storage/image-_x200.webp               // Resize to height of 200px\n    /storage/image-300x_.webp               // Resize to width of 300px\n    /storage/image-300x200-resize.webp      // Resize to fit within 300x200\n    /storage/image-300x200-quadrant(T).webp // See the quadrant description below\n\n#### Croppa::url($url, $width, $height, $options)\n\nTo make preparing the URLs that Croppa expects an easier job, you can use the following view helper:\n\n```php\n\u003cimg src=\"{{ Croppa::url($url, $width, $height, $options) }}\" /\u003e\n\u003c!-- Examples (that would produce the URLs above) --\u003e\n\u003cimg src=\"{{ Croppa::url('storage/image.webp', 300, 200) }}\" /\u003e\n\u003cimg src=\"{{ Croppa::url('storage/image.webp', null, 200) }}\" /\u003e\n\u003cimg src=\"{{ Croppa::url('storage/image.webp', 300) }}\" /\u003e\n\u003cimg src=\"{{ Croppa::url('storage/image.webp', 300, 200, ['resize']) }}\" /\u003e\n\u003cimg src=\"{{ Croppa::url('storage/image.webp', 300, 200, ['pad']) }}\" /\u003e\n\u003cimg src=\"{{ Croppa::url('storage/image.webp', 300, 200, ['pad' =\u003e [45,168,147]]) }}\" /\u003e\n\u003cimg src=\"{{ Croppa::url('storage/image.webp', 300, 200, ['quadrant' =\u003e 'T']) }}\" /\u003e\n\u003c!-- Or, if there were multiple arguments for the last example --\u003e\n\u003cimg src=\"{{ Croppa::url('/uploads/image.png', 300, 200, ['quadrant' =\u003e ['T']]) }}\" /\u003e\n```\n\nThese are the arguments that Croppa::url() takes:\n\n- $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.\n- $width : A number or null for wildcard\n- $height : A number or null for wildcard\n- $options - An array of key value pairs, where the value is an optional array of arguments for the option. Supported option are:\n  - `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).\n  - `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]\n  - `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).\n  - `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.\n  - `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)`\n  - `quality($int)` - Set the jpeg compression quality from 0 to 100.\n  - `interlace($bool)` - Set to `1` or `0` to turn interlacing on or off\n  - `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.\n\n#### Croppa::render($cropurl)\n\nIf you want to create the image programmatically you can pass to this function the url generated by Croppa::url.\nThis will only create the thumbnail and exit.\n\n```php\nCroppa::render('image-300x200.png');\n```\n\nor\n\n```php\nCroppa::render(Croppa::url('image.png', 300, 200));\n```\n\n#### Croppa::delete($url)\n\nYou can delete a source image and all of its crops by running:\n\n```php\nCroppa::delete('/path/to/src.png');\n```\n\n#### Croppa::reset($url)\n\nSimilar to `Croppa::delete()` except the source image is preserved, only the crops are deleted.\n\n```php\nCroppa::reset('/path/to/src.png');\n```\n\n## Console commands\n\n#### `croppa:purge`\n\nDeletes **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:\n\n- `--filter` - Applies a whitelisting regex filter to the crops. For example: `--filter=^01/` matches all crops in the \"./public/uploads/01/\" directory\n- `--dry-run` - Ouputs the files that would be deleted to the console, but doesn’t actually remove\n\n## croppa.js\n\nA 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.\n\n### croppa.url(url, width, height, options)\n\nWorks just like the PHP `Croppa::url` except for how options get formatted (since JS doesn’t have associative arrays).\n\n```js\ncroppa.url('/path/to/img.jpg', 300, 200, ['resize']);\ncroppa.url('/path/to/img.jpg', 300, 200, ['resize', { quadrant: 'T' }]);\ncroppa.url('/path/to/img.jpg', 300, 200, ['resize', { quadrant: ['T'] }]);\n```\n\nRun `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.\n\n## History\n\nRead the Github [project releases](https://github.com/BKWLD/croppa/releases) for release notes.\n\nThis 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/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbkwld%2Fcroppa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbkwld%2Fcroppa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbkwld%2Fcroppa/lists"}