예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function compositeImage($image, $coordX, $coordY, $width = 0, $height = 0, $transparency = 0)
 {
     if (!is_object($image)) {
         $image = new Imanee($image, new GDResource());
     }
     if (!$image instanceof \Imanee\Imanee) {
         throw new \Exception('Object not supported. It must be an instance of Imanee');
     }
     if ($width and $height) {
         $dimensions = PixelMath::getBestFit($width, $height, $image->getWidth(), $image->getHeight());
         $width = $dimensions['width'];
         $height = $dimensions['height'];
     } else {
         $width = $image->getWidth();
         $height = $image->getHeight();
     }
     /* TODO: implement pixel per pixel transparency */
     return imagecopyresampled($this->getResource(), $image->getResource()->getResource(), $coordX, $coordY, 0, 0, $width, $height, $image->getWidth(), $image->getHeight());
 }
예제 #2
0
파일: Imanee.php 프로젝트: robth82/imanee
 /**
  * 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;
 }
예제 #3
0
 /**
  * @dataProvider coordinatesProvider
  */
 public function testShouldReturnCorrectCoordinatesForEachPosition(array $resourceSize, array $size, $position, $expectedCoordinates)
 {
     $this->assertEquals($expectedCoordinates, $this->pixelMath->getPlacementCoordinates($resourceSize, $size, $position));
 }