192a8473aSAndreas Gohr<?php 292a8473aSAndreas Gohr 392a8473aSAndreas Gohr 492a8473aSAndreas Gohrnamespace splitbrain\slika; 592a8473aSAndreas Gohr 6*5c25a071SAndreas Gohr/** 7*5c25a071SAndreas Gohr * Base class for image adapters. Defines what image processing adapters need to provide 8*5c25a071SAndreas Gohr */ 992a8473aSAndreas Gohrabstract class Adapter 1092a8473aSAndreas Gohr{ 1192a8473aSAndreas Gohr /** @var string path tot he image */ 1292a8473aSAndreas Gohr protected $imagepath; 1392a8473aSAndreas Gohr 1492a8473aSAndreas Gohr /** @var array Adapter Options */ 1592a8473aSAndreas Gohr protected $options; 1692a8473aSAndreas Gohr 1792a8473aSAndreas Gohr /** 1892a8473aSAndreas Gohr * New Slika Adapter 1992a8473aSAndreas Gohr * 2092a8473aSAndreas Gohr * @param string $imagepath path to the original image 2192a8473aSAndreas Gohr * @param array $options set options 2292a8473aSAndreas Gohr * @throws Exception 2392a8473aSAndreas Gohr */ 2492a8473aSAndreas Gohr public function __construct($imagepath, $options = []) 2592a8473aSAndreas Gohr { 2692a8473aSAndreas Gohr if (!file_exists($imagepath)) { 2792a8473aSAndreas Gohr throw new Exception('image file does not exist'); 2892a8473aSAndreas Gohr } 2992a8473aSAndreas Gohr 3092a8473aSAndreas Gohr if (!is_readable($imagepath)) { 3192a8473aSAndreas Gohr throw new Exception('image file is not readable'); 3292a8473aSAndreas Gohr } 3392a8473aSAndreas Gohr 3492a8473aSAndreas Gohr $this->imagepath = $imagepath; 3592a8473aSAndreas Gohr $this->options = array_merge(Slika::DEFAULT_OPTIONS, $options); 3692a8473aSAndreas Gohr } 3792a8473aSAndreas Gohr 3892a8473aSAndreas Gohr /** 3992a8473aSAndreas Gohr * Rote the image based on the rotation exif tag 4092a8473aSAndreas Gohr * 4192a8473aSAndreas Gohr * @return Adapter 4292a8473aSAndreas Gohr */ 4392a8473aSAndreas Gohr abstract public function autorotate(); 4492a8473aSAndreas Gohr 4592a8473aSAndreas Gohr /** 4692a8473aSAndreas Gohr * Rotate and/or flip the image 4792a8473aSAndreas Gohr * 4892a8473aSAndreas Gohr * This expects an orientation flag as stored in EXIF data. For typical operations, 4992a8473aSAndreas Gohr * Slika::ROTATE_* constants are defined. 5092a8473aSAndreas Gohr * 5192a8473aSAndreas Gohr * @param int $orientation Exif rotation flags 5292a8473aSAndreas Gohr * @return Adapter 5392a8473aSAndreas Gohr * @see https://stackoverflow.com/a/53697440 for info on the rotation constants 5492a8473aSAndreas Gohr */ 5592a8473aSAndreas Gohr abstract public function rotate($orientation); 5692a8473aSAndreas Gohr 5792a8473aSAndreas Gohr /** 5892a8473aSAndreas Gohr * Resize to make image fit the given dimension (maintaining the aspect ratio) 5992a8473aSAndreas Gohr * 6092a8473aSAndreas Gohr * You may omit one of the dimensions to auto calculate it based on the aspect ratio 6192a8473aSAndreas Gohr * 626cb05674SAndreas Gohr * @param int|string $width in pixels or % 636cb05674SAndreas Gohr * @param int|string $height in pixels or % 6492a8473aSAndreas Gohr * @return Adapter 6592a8473aSAndreas Gohr */ 6692a8473aSAndreas Gohr abstract public function resize($width, $height); 6792a8473aSAndreas Gohr 6892a8473aSAndreas Gohr 6992a8473aSAndreas Gohr /** 7092a8473aSAndreas Gohr * Resize to the given dimension, cropping the image as needed 7192a8473aSAndreas Gohr * 7292a8473aSAndreas Gohr * You may omit one of the dimensions to use a square area 7392a8473aSAndreas Gohr * 746cb05674SAndreas Gohr * @param int|string $width in pixels or % 756cb05674SAndreas Gohr * @param int|string $height in pixels or % 7692a8473aSAndreas Gohr * @return Adapter 7792a8473aSAndreas Gohr */ 7892a8473aSAndreas Gohr abstract public function crop($width, $height); 7992a8473aSAndreas Gohr 8092a8473aSAndreas Gohr /** 8192a8473aSAndreas Gohr * Save the new file 8292a8473aSAndreas Gohr * 8392a8473aSAndreas Gohr * @param string $path 8492a8473aSAndreas Gohr * @param string $extension The type of image to save, empty for original 8592a8473aSAndreas Gohr * @return void 8692a8473aSAndreas Gohr */ 8792a8473aSAndreas Gohr abstract public function save($path, $extension = ''); 8892a8473aSAndreas Gohr 8992a8473aSAndreas Gohr} 90