Beispiel #1
0
 /**
  * Saves image to the file.
  *
  * @param  string $filename
  * @param  int    $quality 0..100 (for JPEG and PNG)
  * @param  string $type    image type
  * @return bool TRUE on success or FALSE on failure.
  */
 public function save($file = NULL, $quality = NULL, $type = NULL)
 {
     if (!is_null($file)) {
         $this->full_path = $file;
         $parts = explode(DIRECTORY_SEPARATOR, $file);
         $name = array_pop($parts);
         $this->name = $name;
     }
     return parent::save($file, $quality ? $quality : $this->getQuality(), $type ? $type : $this->getNetteImageType());
 }
Beispiel #2
0
 /**
  * @param Utils\Image $image
  * @param string $path
  * @param string $extension
  * @return Image
  */
 public function saveImage(Utils\Image $image, $path, $extension)
 {
     do {
         $relativePath = self::addSlashPath($path) . md5(microtime()) . '.' . strtolower($extension);
         $filename = $this->path->getSourceDir($relativePath);
     } while (is_file($filename));
     if ($this->maxSize) {
         $image->resize($this->maxSize['width'], $this->maxSize['height'], Utils\Image::SHRINK_ONLY);
     }
     Utils\FileSystem::createDir(dirname($filename));
     $image->save($filename);
     return new Image($this->path->getSourceDir(''), $relativePath);
 }
Beispiel #3
0
 /**
  * @param string $file
  * @param int    $width
  * @param int    $height
  * @param string $fileType
  * @param int    $quality  on percentage scale from 0 to 100 (only for JPEG and PNG)
  *
  * @return string Thumbnail image path
  */
 public static function thumbnalize($file, $width = null, $height = null, $fileType = self::TYPE_PNG, $quality = self::QUALITY_MEDIUM)
 {
     $file = static::$wwwDir . '/' . $file;
     if (!is_file($file)) {
         return;
     }
     switch ($fileType) {
         case self::TYPE_JPEG:
             $type = Image::JPEG;
             break;
         case self::TYPE_PNG:
             $type = Image::PNG;
             break;
         case self::TYPE_GIF:
             $type = Image::GIF;
             break;
         default:
             $type = Image::PNG;
             break;
     }
     $fileName = self::getFileName($file, $fileType);
     $destinationDir = $width . '_' . $height . '/' . $fileType . '/' . $quality;
     $thumbDir = static::$wwwDir . static::$thumbDir;
     if (file_exists($thumbDir . '/' . $destinationDir . '/' . $fileName)) {
         return static::$thumbDir . '/' . $destinationDir . '/' . $fileName;
     }
     static::$image = Image::fromFile($file);
     if (static::isWidthSet($width) && static::isHeightSet($height)) {
         static::resizeImageExactly($width, $height);
     } elseif (static::isWidthSet($width)) {
         static::resizeImageProportionally($width, $height);
     } else {
         static::resizeImageProportionally(static::$image->getWidth(), $height);
     }
     FileSystem::createDir($thumbDir . '/' . $destinationDir);
     static::$image->save($thumbDir . '/' . $destinationDir . '/' . $fileName, $quality, $type);
     return static::$thumbDir . '/' . $destinationDir . '/' . $fileName;
 }
Beispiel #4
0
 /**
  * @param Entities\Person $person
  * @param Nette\Utils\Image $image
  * @param string $source Zdroj obrazku (napr. Flick, atd.)
  * @return boolean
  */
 public function setPersonAvatar($person, $image, $source = NULL)
 {
     //odstranit puvodni obr vcetne nahledu
     $this->deletePersonAvatar($person);
     //vytvorit nahled a ulozit novy obr
     $imageName = $person->id . '_' . $person->getWebalizeName() . '.jpg';
     $thumbnail = 'avatar' . '_' . $imageName;
     $resImg = $image->save($this->wwwDirUser . $imageName);
     if (!$resImg) {
         return FALSE;
     }
     if (empty($source)) {
         $source = NULL;
     }
     $myImage = new Entities\Image($imageName, $source);
     $myImage->thumbnail = $thumbnail;
     $person->setAvatar($myImage);
     $image->resize(100, NULL, \Nette\Utils\Image::SHRINK_ONLY);
     $resImg2 = $image->save($this->wwwDirUser . $thumbnail, 50);
     return $resImg && $resImg2;
 }
 /**
  * @param  Image
  * @param  int
  * @param  int|NULL (for JPEG, PNG)
  * @param  string|NULL
  * @return string  filepath (namespace/file.ext)
  * @throws ImageStorageException
  */
 public function save(Image $image, $format, $quality = NULL, $namespace = NULL)
 {
     $ext = NULL;
     if ($format === Image::JPEG) {
         $ext = 'jpg';
     } elseif ($format === Image::PNG) {
         $ext = 'png';
     } elseif ($format === Image::GIF) {
         $ext = 'gif';
     } else {
         throw new ImageStorageException("Unknow format '{$format}'.");
     }
     $sanitizedName = Random::generate(5) . '.' . $ext;
     $file = $this->generateFilePath($sanitizedName, $namespace);
     $path = $this->getPath($file);
     @mkdir(dirname($path), 0777, TRUE);
     // @ - adresar muze existovat
     $image->save($path, $quality, $format);
     return $file;
 }
 /**
  * @param \Carrooi\ImagesManager\Image\Image $image
  * @param \Nette\Utils\Image $thumbnail
  * @param int|null $width
  * @param int|null $height
  * @param int|null $resizeFlag
  * @param int|null $quality
  */
 public function tryStoreThumbnail(Image $image, NetteImage $thumbnail, $width = null, $height = null, $resizeFlag = null, $quality = null)
 {
     $path = $this->getRealPath($image, $width, $height, $resizeFlag);
     $thumbnail->save($path, $quality);
 }