public function request($image, $size = NULL, $flags = NULL, $strictMode = FALSE)
{
$this->checkSettings();
if ($image instanceof ImageProvider) {
$this->setNamespace($image->getNamespace());
$image = $image->getFilename();
} elseif (empty($image)) {
return "#";
}
if ($size === NULL) {
return $this->getPath() . "/" . $this->namespace . $this->originalPrefix . "/" . $image;
}
list($width, $height) = explode("x", $size);
if ($flags == NULL) {
$flags = NImage::FIT;
} elseif (!is_int($flags)) {
switch (strtolower($flags)) {
case "fit":
$flags = NImage::FIT;
break;
case "fill":
$flags = NImage::FILL;
break;
case "exact":
$flags = NImage::EXACT;
break;
case "shrink_only":
$flags = NImage::SHRINK_ONLY;
break;
case "stretch":
$flags = NImage::STRETCH;
break;
}
if (!isset($flags)) {
throw new Nette\Latte\CompileException('Mode is not allowed');
}
}
$thumbPath = "/" . $this->namespace . $flags . "_" . $width . "x" . $height . "/" . $image;
$thumbnailFile = $this->assetsDir . $thumbPath;
$originalFile = $this->assetsDir . "/" . $this->namespace . $this->originalPrefix . "/" . $image;
if (!file_exists($thumbnailFile)) {
$this->mkdir(dirname($thumbnailFile));
if (file_exists($originalFile)) {
$img = NImage::fromFile($originalFile);
if ($flags === "crop") {
$img->crop('50%', '50%', $width, $height);
} else {
$img->resize($width, $height, $flags);
}
$this->onBeforeSaveThumbnail($img, $this->namespace, $image, $width, $height, $flags);
$img->save($thumbnailFile);
} elseif ($strictMode) {
throw new FileNotFoundException();
}
}
$this->namespace = NULL;
return $this->getPath() . $thumbPath;
}