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