Installing Watimage is pretty easy if you use composer:
composer require elboletaire/watimage:~2.0.0
After installing Watimage, ensure you’re loading composer’s autoloader:
// In your main project's file or wherever you wanna load Watimage
require_once 'vendor/autoload.php';
Since that moment, simply init the classes:
use Elboletaire\Watimage\Image;
use Elboletaire\Watimage\Watermark;
$image = new Image('image.jpeg');
$watermark = new Watermark('watermark.png');
Without composer
Composer is the recommended and easiest way, but there are some times where you won’t use it.
If not using composer you can add Watimage however you want, but I recommend you using git submodules:
git submodule add https://github.com/elboletaire/Watimage.git vendor/Watimage
After that you’ll need to manually add each required file:
require_once 'vendor/Watimage/src/Image.php';
require_once 'vendor/Watimage/src/Watermark.php';
require_once 'vendor/Watimage/src/Exception/ExtensionNotLoadedException.php';
require_once 'vendor/Watimage/src/Exception/FileNotExistException.php';
require_once 'vendor/Watimage/src/Exception/InvalidArgumentException.php';
require_once 'vendor/Watimage/src/Exception/InvalidExtensionException.php';
require_once 'vendor/Watimage/src/Exception/InvalidMimeException.php';
// any other required class
Just load those needed by you (e.g. if you are not gonna use the Watermark
class you can skip it).
Since you’ve loaded Watimage you can start using it:
use Elboletaire\Watimage\Image;
use Elboletaire\Watimage\Watermark;
$image = new Image('tripi.jpg');
$image
->pixelate(5, true)
->generate('pixelated-tripi.jpg');
Using Watimage with PHP 5.4
If you’re running PHP 5.4 you need to define the following constants in order to
get Watimage properly working (are required by the flip
method):
define('IMG_FLIP_HORIZONTAL', 1);
define('IMG_FLIP_VERTICAL', 2);
define('IMG_FLIP_BOTH', 3);
About the header image
For the header image the following code has been executed:
$image = new Image('el-carmel-viewpoint.jpg');
$image
->contrast(-5)
->brightness(-60)
->colorize(['r' => 100, 'g' => 70, 'b' => 50, 'a' => 0])
->brightness(-30)
->contrast(-5)
->generate()
;
Both the image and the original can be found under
gh-pages
branch,
inside images
folder.