/** * Resizes image to fit into a square container * * Manual: http://code.google.com/p/zend-image/wiki/Quick_Start * * @param int $imagePath Original image path * @param int $newPath Transformed image path * @param int $fitInDimension Container size (square) the transformed image should fit in * @return boolean True on save success, false on failure */ public static function resizeImage($imagePath, $newPath, $fitInDimensionX, $fitInDimensionY = 0) { if (substr($imagePath, 0, 1) != '/') { $imagePath = '/' . $imagePath; } if (substr($newPath, 0, 1) != '/') { $newPath = '/' . $newPath; } if ($fitInDimensionY == 0) { $fitInDimensionY = $fitInDimensionX; } $img = new Zend_Image(Admin_View_Helper_ImageControls::_getPublicPath() . $imagePath, new Zend_Image_Driver_Gd()); $transformed = new Zend_Image_Transform($img); $resized = $transformed->fitIn($fitInDimensionX, $fitInDimensionY); $resized->save(Admin_View_Helper_ImageControls::_getPublicPath() . $newPath); return file_exists(Admin_View_Helper_ImageControls::_getPublicPath() . $newPath); }
public function testCanFitInto() { $zendImage = new Zend_Image_Transform(dirname(__FILE__) . '/' . $this->_file300x431, new Zend_Image_Driver_Gd()); $this->assertEquals(md5($zendImage->fitIn(100, 100)->getBinary()), md5_file(dirname(__FILE__) . '/' . $this->_file70x100)); }
public function testCanFitIntoFrameByHeight() { $this->_driverMock->expects($this->any(2))->method('getSize')->will($this->returnValue(array(500, 1000))); $this->_driverMock->expects($this->once())->method('resize')->with(25, 50); $transform = new Zend_Image_Transform('doesnt-matter.jpg', $this->_driverMock); $transform->fitIn(50, 50); }