示例#1
0
文件: Image.php 项目: sqrt-pro/image
 /** Наложение водяного знака */
 protected function doWatermark($file, $x, $y)
 {
     if (is_null($x)) {
         $x = 'center';
     }
     if (is_null($y)) {
         $y = 'center';
     }
     try {
         $watermark = new Image($file);
     } catch (Ex $e) {
         throw new Ex($e->getMessage(), Ex::WATERMARK);
     }
     $width = $watermark->getWidth();
     $height = $watermark->getHeight();
     list($new_x, $new_y) = static::CalculateOffset($x, $y, $this->getWidth(), $this->getHeight(), $width, $height);
     if (!imagecopy($this->getImage(), $watermark->getImage(), $new_x, $new_y, 0, 0, $width, $height)) {
         Ex::ThrowError(Ex::WATERMARK);
     }
     return $this;
 }
示例#2
0
 /**
  * @dataProvider dataOffset
  */
 function testCropResized($x, $y)
 {
     $width = 150;
     $height = 100;
     $path = $this->path_to_save . '/crop_resized_' . $x . '_' . $y . '_vertical.jpg';
     $img = new Image($this->vertical);
     $img->cropResized($width, $height, $x, $y);
     $img->save($path);
     $new = new Image($path);
     $this->assertEquals($width, $new->getWidth(), 'Ширина вертикальной');
     $this->assertEquals($height, $new->getHeight(), 'Высота вертикальной');
     $path = $this->path_to_save . '/crop_resized_' . $x . '_' . $y . '_horizontal.jpg';
     $img = new Image($this->bike);
     $img->cropResized($width, $height, $x, $y);
     $img->save($path);
     $new = new Image($path);
     $this->assertEquals(149, $new->getWidth(), 'Ширина горизонтальной');
     $this->assertEquals($height, $new->getHeight(), 'Высота горизонтальной');
     $path = $this->path_to_save . '/crop_resized_' . $x . '_' . $y . '_square.jpg';
     $img = new Image($this->watermark);
     $img->cropResized($width, $height, $x, $y);
     $img->save($path);
     $new = new Image($path);
     $this->assertEquals($width, $new->getWidth(), 'Ширина квадратной');
     $this->assertEquals($height, $new->getHeight(), 'Высота квадратной');
     $this->markTestSkipped('Нужна визуальная проверка правильности обрезки');
 }