public function provideImage($param) { //Check if all necessary variables exist and assign to class variables $this->assignVariables($param); //Contain origin path to image $pathOrigin = $this->wwwDir . '/' . $this->prefix . '/' . $this->namespace . '/' . $this->filename; //First check if exist in cache(it is more common to get resize then origin size) if ($imageString = $this->imageCache->getFromCache($this->namespace, $this->width, $this->height, $this->flag, $this->filename)) { $image = Image::fromString($imageString, $this->type); //then look if height and width is null to provide origin } elseif ($this->height == null && $this->width == null) { $image = Image::fromFile($pathOrigin); //try get image, resize and save to cache } elseif (file_exists($pathOrigin)) { $image = Image::fromFile($pathOrigin); $image = $this->resizeImage($image, $this->width, $this->height, $this->flag); if (!$this->imageCache->saveTocache($image, $this->namespace, $this->width, $this->height, $this->flag, $this->filename)) { throw new BowtieImageException('There is something wrong :('); } //else image not exist throw exception } else { throw new BadRequestException('Required image not found.'); } return $image; }
/** * @param string $name * @param string $resolution * @param int $method * @throws ImageManager\ResolutionIsNotAllowedException * @throws ImageManager\RemoteFileDoesNotExistsException * @return bool */ public function send($name, $resolution, $method) { $this->checkResolution($resolution); $imagePath = $this->createImagePath($name, $resolution, $method); if ($imagePath->fs) { Utils\Image::fromFile($imagePath->fs)->send(); return TRUE; } elseif ($imagePath->url) { Utils\Image::fromString($this->download->loadFromUrl($imagePath->url))->send(); return TRUE; } return FALSE; }
/** * @param Service $thumbator * @param string $original * @param string $filename * @param int $width * @param int $height * @param int $method * @return string */ public function placehold($thumbator, $original, $filename, $width, $height, $method) { try { $data = @file_get_contents(sprintf($this->placeholder, $width, $height)); if ($data) { $image = Image::fromString($data); Helpers::mkdir(dirname($thumbator->config->getStorageDir() . DIRECTORY_SEPARATOR . $original)); $image->save($thumbator->config->getStorageDir() . DIRECTORY_SEPARATOR . $original); return $thumbator->create($original, $width, $height, $method); } } catch (\Exception $e) { // Silent.. } return sprintf($this->placeholder, $width, $height); }
/** * Return ImageNameScript and file for no-image image * @return array */ public function getNoImage($return_image = FALSE) { $script = ImageNameScript::fromIdentifier($this->noimage_identifier); $file = implode('/', [$this->data_path, $script->original]); if (!file_exists($file)) { $identifier = '_storage_no_image/8f/no_image.png'; $new_path = "{$this->data_path}/{$identifier}"; if (!file_exists($new_path)) { $data = base64_decode(require __DIR__ . '/NoImageSource.php'); $_image = Nette\Utils\Image::fromString($data); $_image->save($new_path, $script->quality ?: $this->quality); } if ($return_image) { return new Image($this->friendly_url, $this->data_dir, $this->data_path, $identifier); } $script = ImageNameScript::fromIdentifier($identifier); return [$script, $new_path]; } if ($return_image) { return new Image($this->friendly_url, $this->data_dir, $this->data_path, $this->noimage_identifier); } return [$script, $file]; }
/** * @param string $original * @param int $width * @param int $height * @param null $filename * @param null $method * @return string */ protected function placehold($original, $width, $height, $filename = NULL, $method = NULL) { try { $data = @file_get_contents(sprintf($this->placeholder, $width, $height, $filename, $method)); if ($data) { $image = Image::fromString($data); $image->save($this->getWwwPath() . '/' . $original); return $this->create($filename, $width, $height, $method); } } catch (\Exception $e) { // Silent.. } return sprintf($this->placeholder, $width, $height, $filename, $method); }
/** * @param \Carrooi\ImagesManager\Image\Image $image * @param int|null $width * @param int|null $height * @param int|null $resizeFlag * @return \Nette\Utils\Image */ public function getNetteImage(Image $image, $width = null, $height = null, $resizeFlag = null) { return NetteImage::fromString(base64_decode('R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==')); }