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