|
| 1 | +# PHP ImageResize Library |
| 2 | +## What is it |
| 3 | +A library implemented by PHP to **resize image smartly** and add water mark. |
| 4 | + |
| 5 | +This library will help you resize the image according to the width and height defined and cut smartly to promise the length-to-width ratio, and add water mark in the mean time. |
| 6 | + |
| 7 | +## Requirements |
| 8 | +- PHP 5 + |
| 9 | +- PHP GD |
| 10 | +- composer |
| 11 | +> Please assure that you have installed php-gd, and install it via `apt install php7.0-gd` or `apt install php5-gd` is recommended. |
| 12 | +
|
| 13 | +## Installation |
| 14 | +Here are two ways to install: |
| 15 | +- Using composer: |
| 16 | + ``` |
| 17 | + composer require php-quickorm/image-resize |
| 18 | + ``` |
| 19 | +
|
| 20 | +- or download the `ImageResize.php` to your project and import it by `require "ImageResize.php";` |
| 21 | +
|
| 22 | +## Usage |
| 23 | +
|
| 24 | +### Resize |
| 25 | +
|
| 26 | +```php |
| 27 | +// Resize the firework.jpg to 800x600 |
| 28 | +$a = new ImageResize(realpath('firework.jpg'),800,600); |
| 29 | +
|
| 30 | +// Save to firework2.png; |
| 31 | +$a->save("firework.png"); |
| 32 | +
|
| 33 | +// or send as HTTP response |
| 34 | +$a->render(); |
| 35 | +``` |
| 36 | + |
| 37 | +### Water Mark |
| 38 | + |
| 39 | +```php |
| 40 | +// Resize the firework.jpg to 800x600 |
| 41 | +$a = new ImageResize(realpath('firework.jpg'),800,600); |
| 42 | + |
| 43 | +/* |
| 44 | +* Add text to image |
| 45 | +* The font size is 1 - 5 and the position only supports bottom-left, bottom-right, top-left, top-right |
| 46 | +*/ |
| 47 | + |
| 48 | +// use font size 5, color #ffffff and place at bottom-right with margin 10px |
| 49 | +$a->addTextMark("Author:Rytia", 5, "#ffffff", "right", "bottom",10); |
| 50 | +// use font size 4, color #ccccc and place at bottom-left with margin 15px |
| 51 | +$a->addTextMark("Blog:www.zzfly.net", 4, "#cccccc", "left", "bottom",15); |
| 52 | + |
| 53 | + |
| 54 | +/* |
| 55 | +* Add water mark to image |
| 56 | +* The position only supports bottom-left, bottom-right, top-left, top-right |
| 57 | +*/ |
| 58 | +$a->addImageMark(realpath('mark.jpg'),100,80,"right","bottom",50); |
| 59 | + |
| 60 | +// Save to firework2.png; |
| 61 | +$a->save("firework.png"); |
| 62 | + |
| 63 | +// or send as HTTP response |
| 64 | +$a->render(); |
| 65 | + |
| 66 | +``` |
| 67 | + |
| 68 | + |
0 commit comments