Exemple #1
0
 function getImageResource()
 {
     if ($this->file !== NULL) {
         if (!$this->isTemporary) {
             $this->execute("convert -strip %input %output", self::PNG);
         }
         $this->setImageResource(imagecreatefrompng($this->file));
         if ($this->isTemporary) {
             unlink($this->file);
         }
         $this->file = NULL;
     }
     return parent::getImageResource();
 }
Exemple #2
0
	/**
	 * Puts another image into this image.
	 * @param  NImage
	 * @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(NImage $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->getImageResource(), $image->getImageResource(),
				$left, $top, 0, 0, $image->getWidth(), $image->getHeight()
			);

		} elseif ($opacity <> 0) {
			imagecopymerge(
				$this->getImageResource(), $image->getImageResource(),
				$left, $top, 0, 0, $image->getWidth(), $image->getHeight(),
				$opacity
			);
		}
		return $this;
	}