| 1 |
<?php |
| 2 |
|
| 3 |
namespace Intervention\Image; |
| 4 |
|
| 5 |
class Constraint |
| 6 |
{ |
| 7 |
/** |
| 8 |
* Bit value of aspect ratio constraint |
| 9 |
*/ |
| 10 |
const ASPECTRATIO = 1; |
| 11 |
|
| 12 |
/** |
| 13 |
* Bit value of upsize constraint |
| 14 |
*/ |
| 15 |
const UPSIZE = 2; |
| 16 |
|
| 17 |
/** |
| 18 |
* Constraint size |
| 19 |
* |
| 20 |
* @var \Intervention\Image\Size |
| 21 |
*/ |
| 22 |
private $size; |
| 23 |
|
| 24 |
/** |
| 25 |
* Integer value of fixed parameters |
| 26 |
* |
| 27 |
* @var int |
| 28 |
*/ |
| 29 |
private $fixed = 0; |
| 30 |
|
| 31 |
/** |
| 32 |
* Create a new constraint based on size |
| 33 |
* |
| 34 |
* @param Size $size |
| 35 |
*/ |
| 36 |
public function __construct(Size $size) |
| 37 |
{ |
| 38 |
$this->size = $size; |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Returns current size of constraint |
| 43 |
* |
| 44 |
* @return \Intervention\Image\Size |
| 45 |
*/ |
| 46 |
public function getSize() |
| 47 |
{ |
| 48 |
return $this->size; |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Fix the given argument in current constraint |
| 53 |
* |
| 54 |
* @param int $type |
| 55 |
* @return void |
| 56 |
*/ |
| 57 |
public function fix($type) |
| 58 |
{ |
| 59 |
$this->fixed = ($this->fixed & ~(1 << $type)) | (1 << $type); |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Checks if given argument is fixed in current constraint |
| 64 |
* |
| 65 |
* @param int $type |
| 66 |
* @return boolean |
| 67 |
*/ |
| 68 |
public function isFixed($type) |
| 69 |
{ |
| 70 |
return (bool) ($this->fixed & (1 << $type)); |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Fixes aspect ratio in current constraint |
| 75 |
* |
| 76 |
* @return void |
| 77 |
*/ |
| 78 |
public function aspectRatio() |
| 79 |
{ |
| 80 |
$this->fix(self::ASPECTRATIO); |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* Fixes possibility to size up in current constraint |
| 85 |
* |
| 86 |
* @return void |
| 87 |
*/ |
| 88 |
public function upsize() |
| 89 |
{ |
| 90 |
$this->fix(self::UPSIZE); |
| 91 |
} |
| 92 |
} |
| 93 |
|