1<?php
2
3
4namespace splitbrain\slika;
5
6/**
7 * Factory to process an image using an available Adapter
8 */
9class Slika
10{
11    /** rotate an image counter clock wise */
12    const ROTATE_CCW = 8;
13    /** rotate an image clock wise */
14    const ROTATE_CW = 6;
15    /** rotate on it's head */
16    const ROTATE_TOPDOWN = 3;
17
18    /** these can be overwritten using the options array in run() */
19    const DEFAULT_OPTIONS = [
20        'quality' => 92,
21        'imconvert' => '/usr/bin/convert',
22    ];
23
24    /**
25     * This is a factory only, thus the constructor is private
26     */
27    private function __construct()
28    {
29        // there is no constructor.
30    }
31
32    /**
33     * Start processing the image
34     *
35     * @param string $imagePath
36     * @param array $options
37     * @return Adapter
38     * @throws Exception
39     */
40    public static function run($imagePath, $options = [])
41    {
42        $options = array_merge(self::DEFAULT_OPTIONS, $options);
43
44        if (is_executable($options['imconvert'])) {
45            return new ImageMagickAdapter($imagePath, $options);
46        }
47
48        if (function_exists('gd_info')) {
49            return new GdAdapter($imagePath, $options);
50        }
51
52        throw new Exception('No suitable Adapter found');
53    }
54
55}
56