1<?php
2
3
4namespace splitbrain\slika;
5
6
7abstract class Adapter
8{
9    /** @var string path tot he image */
10    protected $imagepath;
11
12    /** @var array Adapter Options */
13    protected $options;
14
15    /**
16     * New Slika Adapter
17     *
18     * @param string $imagepath path to the original image
19     * @param array $options set options
20     * @throws Exception
21     */
22    public function __construct($imagepath, $options = [])
23    {
24        if (!file_exists($imagepath)) {
25            throw new Exception('image file does not exist');
26        }
27
28        if (!is_readable($imagepath)) {
29            throw new Exception('image file is not readable');
30        }
31
32        $this->imagepath = $imagepath;
33        $this->options = array_merge(Slika::DEFAULT_OPTIONS, $options);
34    }
35
36    /**
37     * Rote the image based on the rotation exif tag
38     *
39     * @return Adapter
40     */
41    abstract public function autorotate();
42
43    /**
44     * Rotate and/or flip the image
45     *
46     * This expects an orientation flag as stored in EXIF data. For typical operations,
47     * Slika::ROTATE_* constants are defined.
48     *
49     * @param int $orientation Exif rotation flags
50     * @return Adapter
51     * @see https://stackoverflow.com/a/53697440 for info on the rotation constants
52     */
53    abstract public function rotate($orientation);
54
55    /**
56     * Resize to make image fit the given dimension (maintaining the aspect ratio)
57     *
58     * You may omit one of the dimensions to auto calculate it based on the aspect ratio
59     *
60     * @param int|string $width in pixels or %
61     * @param int|string $height in pixels or %
62     * @return Adapter
63     */
64    abstract public function resize($width, $height);
65
66
67    /**
68     * Resize to the given dimension, cropping the image as needed
69     *
70     * You may omit one of the dimensions to use a square area
71     *
72     * @param int|string $width in pixels or %
73     * @param int|string $height in pixels or %
74     * @return Adapter
75     */
76    abstract public function crop($width, $height);
77
78    /**
79     * Save the new file
80     *
81     * @param string $path
82     * @param string $extension The type of image to save, empty for original
83     * @return void
84     */
85    abstract public function save($path, $extension = '');
86
87}
88