1# Slika - simple image handling for PHP 2 3This is a library that covers only the bare basics you need when handling images: 4 5 * resizing 6 * cropping 7 * rotation 8 9It can use either PHP's libGD or a locally installed ImageMagick binary. 10 11## Installation 12 13Use composer 14 15 composer require splitbrain/slika 16 17## Usage 18 19Simply get an Adapter from the Slika factory, run some operations on it and call `save`. 20 21Operations can be chained together. Consider the chain to be one command. Do not reuse the adapter returned by `run()`, it is a single use object. All operations can potentially throw a `\splitbrain\slika\Exception`. 22 23Options (see below) can be passed as a second parameter to the `run` factory. 24 25```php 26use \splitbrain\slika\Slika; 27use \splitbrain\slika\Exception; 28 29$options = [ 30 'quality' => 75 31] 32 33try { 34 Slika::run('input.png', $options) 35 ->resize(500,500) 36 ->rotate(Slika::ROTATE_CCW 37 ->save('output.jpg', 'jpg'); 38} catch (Exception $e) { 39 // conversion went wrong, handle it 40} 41``` 42 43## Operations 44 45### resize 46 47All resize operations will keep the original aspect ratio of the image. There will be no distortion. 48 49Keeping either width or height at zero will auto calculate the value for you. 50 51```php 52# fit the image into a bounding box of 500x500 pixels 53Slika::run('input.jpg')->resize(500,500)->save('output.png', 'png'); 54 55# adjust the image to a maximum width of 500 pixels 56Slika::run('input.jpg')->resize(500,0)->save('output.png', 'png'); 57 58# adjust the image to a maximum height of 500 pixels 59Slika::run('input.jpg')->resize(0,500)->save('output.png', 'png'); 60``` 61 62### crop 63 64Similar to resizing, but this time the image will be cropped to fit the new aspect ratio. 65 66```php 67Slika::run('input.jpg')->crop(500,500)->save('output.png', 'png'); 68``` 69 70### rotate 71 72Rotates the image. The parameter passed is one of the EXIF orientation flags: 73 74 75 76For your convenience there are three Constants defined: 77 78 79* `Slika::ROTATE_CCW` counter clockwise rotation 80* `Slika::ROTATE_CW` clockwise rotation 81* `Slika::ROTATE_TOPDOWN` full 180 degree rotation 82 83```php 84Slika::run('input.jpg')->rotate(Slika::ROTATE_CW)->save('output.png', 'png'); 85``` 86 87### autorotate 88 89Rotates the image according to the EXIF rotation tag if found. 90 91```php 92Slika::run('input.jpg')->autorotate()->save('output.png', 'png'); 93``` 94 95## Options 96 97Options can be passed as associatiave array as the second parameter in `Slika::run`. 98 99The following options are availble currently: 100 101| Option | Default | Description | 102|-------------|--------------------|--------------------------------------------| 103| `imconvert` | `/usr/bin/convert` | The path to ImageMagick's `convert` binary | 104| `quality` | `92` | The quality when writing JPEG images | 105