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
 /**
  * @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;
 }