Exemplo n.º 1
0
 /**
  * Puts another image into this image.
  * @param  Image
  * @param  mixed  x-coordinate in pixels or percent
  * @param  mixed  y-coordinate in pixels or percent
  * @param  int  opacity 0..100
  * @return self
  */
 public function place(Image $image, $left = 0, $top = 0, $opacity = 100)
 {
     $opacity = max(0, min(100, (int) $opacity));
     if (substr($left, -1) === '%') {
         $left = round(($this->getWidth() - $image->getWidth()) / 100 * $left);
     }
     if (substr($top, -1) === '%') {
         $top = round(($this->getHeight() - $image->getHeight()) / 100 * $top);
     }
     if ($opacity === 100) {
         imagecopy($this->image, $image->getImageResource(), $left, $top, 0, 0, $image->getWidth(), $image->getHeight());
     } elseif ($opacity != 0) {
         imagecopymerge($this->image, $image->getImageResource(), $left, $top, 0, 0, $image->getWidth(), $image->getHeight(), $opacity);
     }
     return $this;
 }
Exemplo n.º 2
0
 /**
  * Puts another image into this image.
  * @param  Image
  * @param  mixed  x-coordinate in pixels or percent
  * @param  mixed  y-coordinate in pixels or percent
  * @param  int  opacity 0..100
  * @return self
  */
 public function place(Image $image, $left = 0, $top = 0, $opacity = 100)
 {
     $opacity = max(0, min(100, (int) $opacity));
     if (is_string($left) && substr($left, -1) === '%') {
         $left = (int) round(($this->getWidth() - $image->getWidth()) / 100 * $left);
     }
     if (is_string($top) && substr($top, -1) === '%') {
         $top = (int) round(($this->getHeight() - $image->getHeight()) / 100 * $top);
     }
     if ($opacity === 100) {
         imagecopy($this->image, $image->getImageResource(), $left, $top, 0, 0, $image->getWidth(), $image->getHeight());
     } elseif ($opacity != 0) {
         $cutting = imagecreatetruecolor($image->getWidth(), $image->getHeight());
         imagecopy($cutting, $this->image, 0, 0, $left, $top, $image->getWidth(), $image->getHeight());
         imagecopy($cutting, $image->getImageResource(), 0, 0, 0, 0, $image->getWidth(), $image->getHeight());
         imagecopymerge($this->image, $cutting, $left, $top, 0, 0, $image->getWidth(), $image->getHeight(), $opacity);
     }
     return $this;
 }