| 1 |
<?php |
| 2 |
|
| 3 |
namespace Depicter\Media\Image; |
| 4 |
|
| 5 |
|
| 6 |
use Depicter\Media\File as MediaFile; |
| 7 |
|
| 8 |
class File extends MediaFile |
| 9 |
{ |
| 10 |
|
| 11 |
/** |
| 12 |
* Resized width in pixels. |
| 13 |
* |
| 14 |
* @var int |
| 15 |
*/ |
| 16 |
protected $resized_w; |
| 17 |
|
| 18 |
/** |
| 19 |
* Resized height in pixels. |
| 20 |
* |
| 21 |
* @var int |
| 22 |
*/ |
| 23 |
protected $resized_h; |
| 24 |
|
| 25 |
/** |
| 26 |
* Crop width in pixels. |
| 27 |
* |
| 28 |
* @var int |
| 29 |
*/ |
| 30 |
protected $crop_w; |
| 31 |
|
| 32 |
/** |
| 33 |
* Crop height in pixels. |
| 34 |
* |
| 35 |
* @var int |
| 36 |
*/ |
| 37 |
protected $crop_h; |
| 38 |
|
| 39 |
/** |
| 40 |
* Focal points |
| 41 |
* |
| 42 |
* @example [50, 50] or ["center", "center"] |
| 43 |
* |
| 44 |
* @var array |
| 45 |
*/ |
| 46 |
protected $focal = [0.5, 0.5]; |
| 47 |
|
| 48 |
/** |
| 49 |
* Set focal point |
| 50 |
* |
| 51 |
* @param string|float $x |
| 52 |
* @param string|float $y |
| 53 |
* |
| 54 |
* @return $this |
| 55 |
*/ |
| 56 |
public function setFocal( $x, $y ){ |
| 57 |
$this->focal = [ $x, $y ]; |
| 58 |
|
| 59 |
return $this; |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Generates a name suffix for focal point if is not default focal |
| 64 |
* |
| 65 |
* @return string |
| 66 |
*/ |
| 67 |
protected function focalPointSuffix(){ |
| 68 |
if( $this->focal[0] == 0.5 && $this->focal[0] == 0.5 ){ |
| 69 |
return ''; |
| 70 |
} |
| 71 |
return round( $this->focal[0] * 1000 ) . round( $this->focal[1] * 1000 ) . '-'; |
| 72 |
} |
| 73 |
|
| 74 |
} |
| 75 |
|