Constraint.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 int
  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. *
  46. * @param int $type
  47. * @return void
  48. */
  49. public function fix($type)
  50. {
  51. $this->fixed = ($this->fixed & ~(1 << $type)) | (1 << $type);
  52. }
  53. /**
  54. * Checks if given argument is fixed in current constraint
  55. *
  56. * @param int $type
  57. * @return boolean
  58. */
  59. public function isFixed($type)
  60. {
  61. return (bool) ($this->fixed & (1 << $type));
  62. }
  63. /**
  64. * Fixes aspect ratio in current constraint
  65. *
  66. * @return void
  67. */
  68. public function aspectRatio()
  69. {
  70. $this->fix(self::ASPECTRATIO);
  71. }
  72. /**
  73. * Fixes possibility to size up in current constraint
  74. *
  75. * @return void
  76. */
  77. public function upsize()
  78. {
  79. $this->fix(self::UPSIZE);
  80. }
  81. }