public function createThumbnail() { $args = array_merge($this->defaults, func_get_args()[0]); $args = ArrayHash::from($args); $storage = $this->media->getStorage($args->storage); if (isset($args->namespace)) { $storage->setNamespace($args->namespace); } $image = $storage->load($args->file); $width = $args->width; $height = $args->height; if ($image !== NULL) { if ($width && $width != $image->width) { $name = $this->createThumbnailName($image, $width, $height); $thumb = $storage->absolutePath . '/' . $name; $src = NULL; if (!file_exists($thumb)) { $image = Image::fromFile($image->absolutePath); if (empty($height)) { $height = $width; } $image->resize($width, $height, constant('Nette\\Image::' . strtoupper($args->flag))); $image->save($thumb); } $image = $storage->load($name); } $src = $storage->getBaseUrl() . '/' . $image->filename; return $src; } }
public function createLink() { $args = array_merge($this->defaults, func_get_args()[0]); $args = ArrayHash::from($args); $storage = $this->media->getStorage($args->storage); if (isset($args->namespace)) { $storage->setNamespace($args->namespace); } $image = $storage->load($args->file); if ($image !== NULL) { return $storage->getBaseUrl() . '/' . $image->filename; } }