public function getImage()
 {
     if ($this->xmlrpc) {
         try {
             $data = $this->captcha->getImage($this->getHash());
             $im = imagecreatefromstring($data);
             $img = new NImage($im);
         } catch (Exception $e) {
             $img = NImage::fromBlank(200, 25, NImage::rgb(255, 255, 255));
             $img->imagestring($img, 3, 0, 0, "Nepodarilo se ziskat obrazek", 1);
             $this->addError($e->__toString());
         }
         //$img->send(NImage::GIF);
         return (string) $img;
     } else {
         return $this->image;
     }
 }
Example #2
0
 public static function showImage($src_hash)
 {
     $crypt = new Crypt();
     $crypt->Mode = Crypt::MODE_HEX;
     $crypt->Key = self::_CRYPT;
     list($src, $hash) = explode("|", $src_hash, 2);
     list($hash, $ext) = explode(".", $hash, 2);
     list($width, $height, $flags) = explode("|", $crypt->decrypt($hash));
     //preverenie
     if (strlen($ext) > 5 or strstr($src, '/') or !is_numeric($width) or !is_numeric($width) or !is_numeric($height) or !is_numeric($flags) or $flags > 10) {
         throw new GalleryException('Nastala chyba - nespravny subor.');
     }
     $image = NImage::fromFile(NEnvironment::getConfig()->gallery['dir_abs'] . '/original/' . $src . '.' . $ext);
     //progressive
     $image->interlace(true);
     $image->resize($width, $height, $flags);
     if ($flags == 5) {
         $image->crop("50%", "50%", $width, $height);
     }
     $image->save(self::gURL($src, $ext, $width, $height, $flags, 'dir_abs'));
     $image->send();
 }
Example #3
0
 function toImage()
 {
     return NImage::fromFile($this->tmpName);
 }
Example #4
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;
	}
Example #5
0
 public function vytvorit_nahled($filePath, $novy_nazev = NULL, $x = null, $y = null, $oriznout = TRUE)
 {
     $x = $x ? $x : $this->sirka_nahledu;
     $y = $y ? $y : $this->vyska_nahledu;
     $image = NImage::fromFile($filePath);
     if ($oriznout) {
         $parametry = array(NImage::EXACT, NImage::SHRINK_ONLY);
     } else {
         $parametry = array(NImage::SHRINK_ONLY);
     }
     $image->resize($x, $y, join(' | ', $parametry));
     if (!$novy_nazev) {
         $novy_nazev = $filePath;
     }
     $image->save($novy_nazev);
 }
Example #6
0
 public function newImage(NHttpUploadedFile &$image, $size)
 {
     if ($image->isOk()) {
         $fileName = rand(0, 9999) . '-' . NString::webalize($image->getName(), '.');
         $filePath = WWW_DIR . "/data/" . $fileName;
         $image = NImage::fromFile($image->getTemporaryFile())->resize($size[0], $size[1]);
         //$image->sharpen();
         $image->save($filePath, 90);
         $image = $fileName;
         return TRUE;
     } else {
         return FALSE;
     }
 }
Example #7
0
 /**
  * @access public
  * @param $src_hash
  * @static
  * @ParamType $src_hash
  */
 public static function showImage($src_hash)
 {
     $crypt = new Crypt();
     $crypt->Mode = Crypt::MODE_HEX;
     $crypt->Key = self::_CRYPT;
     list($src, $hash) = explode("|", $src_hash, 2);
     list($hash, $ext) = explode(".", $hash, 2);
     list($width, $height, $flags) = explode("|", $crypt->decrypt($hash));
     //preverenie
     if (strlen($ext) > 5 or strstr($src, '/') or !is_numeric($width) or !is_numeric($width) or !is_numeric($height) or !is_numeric($flags) or $flags > 10) {
         throw new Exception('Nastala chyba - nespravny subor.');
     }
     $image = NImage::fromFile(NEnvironment::getConfig()->file['dir_abs'] . '/original/' . $src . '.' . $ext);
     //progressive
     $image->interlace(true);
     if ($flags != 6) {
         $image->resize($width, $height, $flags);
     }
     if ($flags == 5) {
         $image->crop("50%", "50%", $width, $height);
     }
     if ($flags == 6) {
         $image->resize($width, $height, 1);
         $i_height = $image->getHeight();
         $i_width = $image->getWidth();
         $position_top = (int) (($height - $i_height) / 2);
         $position_left = (int) (($width - $i_width) / 2);
         $color = array('red' => 255, 'green' => 255, 'blue' => 255);
         $blank = NImage::fromBlank($width, $height, $color);
         $blank->place($image, $position_left, $position_top);
         $image = $blank;
         //			$image->crop ( "50%", "50%", $width, $height );
         //			echo 1;
         $image->save(self::gURL($src, $ext, $width, $height, $flags, 'dir_abs'));
         $image->send();
         exit;
     }
     //        var_dump(self::gURL($src, $ext, $width, $height, $flags, 'dir_abs'));
     //        exit;
     $dirUrl = self::gURL($src, $ext, $width, $height, $flags, 'dir_abs');
     $image->save($dirUrl, 80, NImage::JPEG);
     $image->send();
     exit;
 }
 function compressImages()
 {
     // Requires Imagemagik PHP Module.
     $image = new NImage();
     $image->compressJPEGImage($this->large_image, 75);
 }