File indexing completed on 2025-01-26 05:29:15

0001 <?php
0002 
0003 namespace Intervention\Image;
0004 
0005 class Constraint
0006 {
0007     /**
0008      * Bit value of aspect ratio constraint
0009      */
0010     const ASPECTRATIO = 1;
0011 
0012     /**
0013      * Bit value of upsize constraint
0014      */
0015     const UPSIZE = 2;
0016 
0017     /**
0018      * Constraint size
0019      *
0020      * @var \Intervention\Image\Size
0021      */
0022     private $size;
0023 
0024     /**
0025      * Integer value of fixed parameters
0026      *
0027      * @var int
0028      */
0029     private $fixed = 0;
0030 
0031     /**
0032      * Create a new constraint based on size
0033      *
0034      * @param Size $size
0035      */
0036     public function __construct(Size $size)
0037     {
0038         $this->size = $size;
0039     }
0040 
0041     /**
0042      * Returns current size of constraint
0043      *
0044      * @return \Intervention\Image\Size
0045      */
0046     public function getSize()
0047     {
0048         return $this->size;
0049     }
0050 
0051     /**
0052      * Fix the given argument in current constraint
0053      *
0054      * @param  int $type
0055      * @return void
0056      */
0057     public function fix($type)
0058     {
0059         $this->fixed = ($this->fixed & ~(1 << $type)) | (1 << $type);
0060     }
0061 
0062     /**
0063      * Checks if given argument is fixed in current constraint
0064      *
0065      * @param  int  $type
0066      * @return boolean
0067      */
0068     public function isFixed($type)
0069     {
0070         return (bool) ($this->fixed & (1 << $type));
0071     }
0072 
0073     /**
0074      * Fixes aspect ratio in current constraint
0075      *
0076      * @return void
0077      */
0078     public function aspectRatio()
0079     {
0080         $this->fix(self::ASPECTRATIO);
0081     }
0082 
0083     /**
0084      * Fixes possibility to size up in current constraint
0085      *
0086      * @return void
0087      */
0088     public function upsize()
0089     {
0090         $this->fix(self::UPSIZE);
0091     }
0092 }