/** * Checks image is within height range. * * @param T_Image_Gd $value image to filter * @return mixed filtered value */ protected function doTransform($value) { if (!is_null($this->min) && $value->getHeight() < $this->min) { $msg = "is too small an image. The minimum height is {$this->min} pixels"; throw new T_Exception_Filter($msg); } if (!is_null($this->max) && $value->getHeight() > $this->max) { $msg = "is too big an image. The maximum height is {$this->max} pixels"; throw new T_Exception_Filter($msg); } return $value; }
/** * Checks image is square. * * @param T_Image_Gd $value image to filter * @return mixed filtered value */ protected function doTransform($value) { if ($value->getWidth() !== $value->getHeight()) { $msg = "must be square (i.e. width equal to height)"; throw new T_Exception_Filter($msg); } return $value; }
/** * Checks image is within width range. * * @param T_Image_Gd $value image to filter * @return mixed filtered value */ protected function doTransform($value) { $aspect = $value->getWidth() / $value->getHeight(); if (!is_null($this->min) && $aspect < $this->min) { $min = round($this->min, 2); $msg = "has too small an aspect ratio (width/height). The minimum is {$min}"; throw new T_Exception_Filter($msg); } if (!is_null($this->max) && $aspect > $this->max) { $max = round($this->max, 2); $msg = "has too large an aspect ratio (width/height). The minimum is {$max}"; throw new T_Exception_Filter($msg); } return $value; }
function testWidthAndHeightSetInConstructor() { $im = new T_Image_Gd(100, 200); $this->assertSame($im->getWidth(), 100); $this->assertSame($im->getHeight(), 200); }