/** * @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; }
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(); }
function toImage() { return NImage::fromFile($this->tmpName); }
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); }
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; } }