Esempio n. 1
0
	/**
	 * Saves image to the file.
	 * @param  string  filename
	 * @param  int  quality 0..100 (for JPEG and PNG)
	 * @param  int  optional image type
	 * @return bool TRUE on success or FALSE on failure.
	 */
	public function save($file = NULL, $quality = NULL, $type = NULL)
	{
		if ($this->file === NULL) {
			return parent::save($file, $quality, $type);
		}

		$quality = $quality === NULL ? '' : '-quality ' . max(0, min(100, (int) $quality));
		if ($file === NULL) {
			$this->execute("convert $quality -strip %input %output", $type === NULL ? self::PNG : $type);
			readfile($this->file);

		} else {
			$this->execute("convert $quality -strip %input %output", (string) $file);
		}
		return TRUE;
	}
Esempio n. 2
0
 private function _createTinyPlaceholderForGallery($galleryId, $fontFile, $fontSize)
 {
     $config = $this->getConfig();
     $pattern = $config['tinyPlaceholderPattern'];
     $placeholderFilename = sprintf($pattern, $galleryId);
     $placeholderFilePath = $this->getTempDir() . '/' . $placeholderFilename;
     if (!is_file($placeholderFilePath)) {
         // create placeholder
         $folder = $this->getFolder($galleryId);
         $filename = $this->getGalleryIconPath($galleryId);
         $image = Nette\Image::fromFile($filename);
         $blank = Nette\Image::fromBlank(350, 100, Nette\Image::rgb(220, 220, 220));
         $blank->place($image, 8, 8);
         $rgb = $blank->rgb(0, 0, 0);
         $imageResource = $blank->getImageResource();
         $color = imagecolorallocatealpha($imageResource, $rgb['red'], $rgb['green'], $rgb['blue'], $rgb['alpha']);
         $x = 100;
         $y = 8 + $fontSize;
         $text = 'Galerie';
         imagettftext($imageResource, $fontSize, 0, $x, $y, $color, $fontFile, $text);
         $x = 100;
         $y = 8 + 3 * $fontSize;
         $text = $folder['name'];
         imagettftext($imageResource, $fontSize, 0, $x, $y, $color, $fontFile, $text);
         $resultImage = new Nette\Image($imageResource);
         $resultImage->save($placeholderFilePath);
     }
     return $this->getTempPath() . '/' . $placeholderFilename;
 }