Exemplo n.º 1
0
 /**
  * Places an image on top of the current resource. If the width and height are supplied,
  * will perform a resize before placing the image.
  *
  * @param mixed $image Path to an image on filesystem or an Imanee Object
  * @param int $place_constant One of the Imanee::IM_POS constants, defaults to IM_POS_TOP_LEFT (top left corner)
  * @param int $width (optional) specifies a width for the placement
  * @param int $height (optional) specifies a height for the placement
  * @param int $transparency (optional) specifies the transparency of the placed image.
  * 0 for fully opaque (default), 100 for fully transparent
  *
  * @return $this
  *
  * @throws UnsupportedMethodException
  * @throws UnsupportedFormatException
  */
 public function placeImage($image, $place_constant = Imanee::IM_POS_TOP_LEFT, $width = null, $height = null, $transparency = 0)
 {
     if (!$this->resource instanceof ImageComposableInterface) {
         throw new UnsupportedMethodException("This method is not supported by the ImageResource in use.");
     }
     if (!is_object($image)) {
         $img = clone $this;
         $img->load($image);
         $image = $img;
     }
     if (!$image instanceof \Imanee\Imanee) {
         throw new UnsupportedFormatException('Object not supported. It must be an instance of Imanee');
     }
     if ($width and $height) {
         $image->resize($width, $height);
     }
     list($coordX, $coordY) = PixelMath::getPlacementCoordinates($image->getSize(), ['width' => $this->getWidth(), 'height' => $this->getHeight()], $place_constant);
     $this->resource->compositeImage($image, $coordX, $coordY, 0, 0, $transparency);
     return $this;
 }
Exemplo n.º 2
0
 /**
  * @dataProvider coordinatesProvider
  */
 public function testShouldReturnCorrectCoordinatesForEachPosition(array $resourceSize, array $size, $position, $expectedCoordinates)
 {
     $this->assertEquals($expectedCoordinates, $this->pixelMath->getPlacementCoordinates($resourceSize, $size, $position));
 }