public function testResizeMethodScalesLayerAndAdjustItsPosition() { $adapter = $this->getMockBuilder('Phower\\Image\\Adapter\\AdapterInterface')->getMock(); $adapter->method('resize')->willReturn(true); $adapter->method('getWidth')->willReturn(100); $adapter->method('getHeight')->willReturn(100); $layer = new Layer($adapter); $layer->resize(100, 100, 10, 15); $this->assertEquals(100, $layer->getWidth()); $this->assertEquals(100, $layer->getHeight()); $this->assertEquals(10, $layer->getPosX()); $this->assertEquals(15, $layer->getPosY()); }
/** * Import file into a new layer * * @param string $file * @param int $mode * @return \Phower\Image\Image * @throws InvalidArgumentException */ public function import($file, $mode = LayersStack::APPEND_TOP, $position = LayerInterface::POSITION_MIDDLE_CENTER) { if (!is_readable($file)) { throw new InvalidArgumentException('Unable to import source: ' . $file); } /* @var $adapter \Phower\Image\Adapter\AdapterInterface */ $callback = $this->getDefaultAdapter() . '::fromFile'; $adapter = call_user_func_array($callback, [$file]); $layer = new Layer($adapter); if (($this->width === null || $this->height === null) && $this->layers->count() === 0) { $this->width = $layer->getWidth(); $this->height = $layer->getHeight(); } else { $layer->align($this->width, $this->height, $position); } $this->layers->append($layer, $mode); return $this; }