Constraint.php 1.6 KB

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