/** * @param $form * @param $values */ public function uploadImgFormSucceeded($form, $values) { $values = $form->getValues(); foreach ($values->img as $img) { // ActiveRow if ($img->isOk()) { $row = $this->imagesRepository->findAll()->insert(array('users_id' => $this->user->id, 'title' => $photoName = Strings::webalize($img->getName(), '.'), 'origin' => 'noSet', 'created_at' => new \DateTime())); $photo = Image::fromFile($img); $photoID = $row->getPrimary(); $photoX = $photo->height; $photoY = $photo->width; $path = __DIR__ . '/../../../web/images/' . $photoID; //mkdir('/var/www/m/' . $photoID, 0755, true); //mkdir('/var/www/skeleton/web/images/aaannn', 0755, true); if ($photoX > 102 or $photoY > 768) { $photo->resize(1024, 768, Image::SHRINK_ONLY); } mkdir($path, 0755, TRUE); $photo->save($path . '/' . $photoName); //$photoXGA = $photo->resize(1024, 768, Image::SHRINK_ONLY); //$photoSVGA->resize(800, 600, Image::SHRINK_ONLY); //$photoSVGA->resize(800, 600, Image::SHRINK_ONLY); //$imgName = $img->name; $this->flashMessage($this->translator->translate('ui.your-image-has-been-sent'), 'alert alert-success'); } } }
public function actionImage() { if (substr($this->url, 0, 7) === self::DIRECTORY_CACHE . '/') { $this->cached = true; $this->url = substr($this->url, 7); } if (($entity = $this->fileRepository->findOneBy(array('path' => $this->url))) === null) { throw new \Nette\Application\BadRequestException(sprintf('File \'%s\' does not exist.', $this->url)); } $image = Image::fromFile($entity->getFilePath()); $this->session->close(); // resize if ($this->size && $this->size !== 'default') { if (strpos($this->size, 'x') !== false) { $format = explode('x', $this->size); $width = $format[0] !== '?' ? $format[0] : null; $height = $format[1] !== '?' ? $format[1] : null; $image->resize($width, $height, $this->format !== 'default' ? $this->format : Image::FIT); } } if (!$this->type) { $this->type = substr($entity->getName(), strrpos($entity->getName(), '.')); } $type = $this->type === 'jpg' ? Image::JPEG : $this->type === 'gif' ? Image::GIF : Image::PNG; $file = sprintf('%s/%s/%s/%s/%s/%s', $this->cacheDir, self::DIRECTORY_CACHE, $this->size, $this->format, $this->type, $entity->getPath()); $dir = dirname($file); umask(00); @mkdir($dir, 0777, true); $image->save($file, 90, $type); $image->send($type, 90); }
function dropUploadFormSucceeded(\Nette\Forms\BootstrapUIForm $form) { if (!empty($_FILES)) { $ds = DIRECTORY_SEPARATOR; $storeFolder = 'media/' . $form->values->pages_id; \App\Model\IO::directoryMake(APP_DIR . $ds . $storeFolder, 0755); $tempFile = $_FILES['file']['tmp_name']; $realFile = $_FILES['file']['name']; $targetPath = APP_DIR . $ds . $storeFolder . $ds; $targetFile = $targetPath . $_FILES['file']['name']; move_uploaded_file($tempFile, $targetFile); chmod($targetFile, 0644); $fileSize = filesize($targetFile); $checkImage = $this->database->table("media")->where(array('name' => $realFile, 'pages_id' => $form->values->id)); // Thumbnail for images if (\App\Model\IO::isImage($targetFile)) { \App\Model\IO::directoryMake(APP_DIR . $ds . $storeFolder . $ds . 'tn', 0755); // thumbnails $image = \Nette\Utils\Image::fromFile($targetFile); $image->resize(400, 250, \Nette\Utils\Image::SHRINK_ONLY); $image->sharpen(); $image->save(APP_DIR . '/media/' . $form->values->pages_id . '/tn/' . $realFile); chmod(APP_DIR . '/media/' . $form->values->pages_id . '/tn/' . $realFile, 0644); } if ($checkImage->count() == 0) { $this->database->table("media")->insert(array('name' => $realFile, 'pages_id' => $form->values->pages_id, 'filesize' => $fileSize, 'file_type' => 1, 'date_created' => date("Y-m-d H:i:s"))); } else { echo "Nejsem reálný soubor"; } } exit; }
private function loadImages() { $imageDir = WWW_DIR . "/layouts/" . $this->name . "/images/"; $i = 0; if (is_dir($imageDir)) { $dirs_or_files = array_diff(scandir($imageDir), array('.', '..')); foreach ($dirs_or_files as $dir_or_file) { if (is_file($imageDir . "/" . $dir_or_file)) { $image = Image::fromFile($imageDir . $dir_or_file); // ignore images bigger than XXX px if ($image->getWidth() <= 800) { // first image is main image if ($i === 0) { $this->mainImage = "../layouts/" . $this->name . "/images/" . $dir_or_file; // other images } else { $this->images[] = "../layouts/" . $this->name . "/images/" . $dir_or_file; } $i++; } else { unset($image); } } } } else { throw new Exception("'" . $this->path . "' is not a directory!"); } }
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; }
public function uploadProductPhotos($images, $id_product) { $product = $this->database->findById('product', $id_product); if ($product) { // projedu vsechny fotografie foreach ($images as $img) { // priprava pro vlozeni do db $image = $this->prepareImageForUpload($img); $values['name'] = $this->generateHash(); $values['extension'] = $image['extension']; $values['id_product'] = $product->id; $values['added'] = $this->now; // upravy obrazku, zmena velikosti a dostreni $img_tmp = Nette\Utils\Image::fromFile($img); if ($img_tmp->width > 800) { $img_tmp->resize(800, null); } // w = 800px, h = auto $img_tmp->sharpen(); // doostreni obrazku // vlozeni fotografie do db $row = $this->database->insert('image', $values); // upload fotografie na server $img->move($this->root_img_dir . 'products/' . $product->id . '_' . $row->id . '_' . $values['name'] . '.' . $values['extension']); } } }
public function renderPreview($image, $width = null, $height = null, $sharpen = false) { //nazev preview $previewName = explode('.', $image); $postfix = $previewName[count($previewName) - 1]; unset($previewName[count($previewName) - 1]); $previewName = implode('.', $previewName) . '_' . $width . '_' . $height . '.' . $postfix; //slouzim routu do normalniho tvaru $prefixDir = substr($image, 0, 4); if (!is_dir($this->context->parameters['wwwDir'] . '/images/preview/' . $prefixDir)) { mkdir($this->context->parameters['wwwDir'] . '/images/preview/' . $prefixDir); chmod($this->context->parameters['wwwDir'] . '/images/preview/' . $prefixDir, 0777); } if (file_exists($this->context->parameters['wwwDir'] . '/images/preview/' . $prefixDir . '/' . $previewName)) { $image = Image::fromFile($this->context->parameters['wwwDir'] . '/images/preview/' . $prefixDir . '/' . $previewName); } else { $image = Image::fromFile($this->context->parameters['wwwDir'] . '/images/upload/' . $prefixDir . '/' . $image); $image->resize($width, $height); if ($sharpen) { $image->sharpen(); } $image->save($this->context->parameters['wwwDir'] . '/images/preview/' . $prefixDir . '/' . $previewName); } $image->send(Image::PNG); $this->terminate(); }
public function createThumb($filename) { $image = \Nette\Utils\Image::fromFile($filename); $this->thumbResize($image, self::THUMB_LIST); $this->thumbResize($image, self::THUMB_SMALL); // $this->thumbResize($image, self::THUMB_PRG); // exit; }
/** * @param IFile $file * @param string $path * @throws \Nette\Utils\UnknownImageFileException */ public function apply(IFile $file, $path) { $image = Image::fromFile($path); if ($image->getWidth() > $this->width || $image->getHeight() > $this->height || $this->resizeSmallPicture) { $image->resize($this->width, $this->height, $this->crop ? Image::EXACT : Image::FIT); } $image->save($path, 85); }
/** * @param \Nette\Http\IRequest * @param \Nette\Http\IResponse */ public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse) { if ($this->image instanceof Nette\Utils\Image) { $image = $this->image; } else { $image = Nette\Utils\Image::fromFile($this->image); } $image->send(); }
$values->avatar = $this->_uploadTitleImage($values->avatar); if (is_file("www/" . $this->avatar_path . $values->old_avatar)) { unlink($this->www_dir . "/www/" . $this->avatar_path . $values->old_avatar); } $this->hlavne_menu->uloz(["avatar" => $values->avatar], $values->id); } else { throw new Database\DriverException('Pre titulný obrázok nebol použitý obrázok a tak nebol uložený!' . $e->getMessage()); } } else { throw new Database\DriverException('Pri pokuse o uloženie došlo k chybe! Pravdepodobná príčina je:' . $this->presenter->upload_error[$values->avatar->error] . $e->getMessage()); } } catch (Database\DriverException $e) {
/** * @param string $name * @param string $resolution * @param int $method * @return ImagePath */ public function createImagePath($name, $resolution, $method) { $thumbFile = $this->path->getFilesystem($name, $resolution, $method); if (is_file($thumbFile)) { return new ImagePath($this->getPathUrl($name, $resolution, $method), $thumbFile); } $sourceImage = $this->path->getSourceDir($name); if (!is_file($sourceImage)) { return $this->placehold->createImagePath($resolution); } return $this->saveFile(Utils\Image::fromFile($sourceImage), $name, $resolution, $method); }
/** * @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; }
private function storePhotos($values) { $now = DateTimeUtils::getNow(); $filepath = Strings::webalize(Passwords::hash($now->format(DateTimeUtils::DB_DATETIME_FORMAT))) . $values->filepath->name; $photo = Image::fromFile($values->filepath); $photo->resize(748, 490, Image::STRETCH); $photo->save("img/articles/" . $filepath); $photo->resize(359, 235, Image::STRETCH); $photo->save("img/articles/midiatures/" . $filepath); $photo->resize(130, 130, Image::STRETCH); $photo->save("img/articles/miniatures/" . $filepath); return $filepath; }
public function formPhotoSubmitted(Nette\Application\UI\Form $form) { $fd = $form->getValues(); foreach ($fd->img as $img) { $name = date("Y_m_d_H_i_s_") . Nette\Utils\Random::generate(10); $img = \Nette\Utils\Image::fromFile($img); $img->save("./data/photo/original/" . $name . ".jpg"); $img->resize(200, 200); create_square_image("./data/photo/original/" . $name . ".jpg", "./data/photo/thumb/" . $name . ".jpg", 200); // $img->save("./data/photo/thumb/". $name.".jpg"); } $this->flashMessage("Moc děkujem za fotky :-)", "success"); $this->redirect("this"); }
/** * @param InputInterface $input * @param \SplFileInfo $file * @return bool */ private function resizeImage(InputInterface $input, \SplFileInfo $file) { $size = $input->getOption('size'); $path = $file->getPathname(); $image = \Nette\Utils\Image::fromFile($path, $format); if ($image->getWidth() <= $size && $image->getHeight() <= $size) { return TRUE; } $image->resize($size, $size, $image::FIT | $image::SHRINK_ONLY); if ($input->getOption('backup')) { copy($path, $path . '.backup'); } return $image->save($path, $input->getOption('quality'), $format); }
/** * @param Service $thumbator * @param string $original * @param string $thumb * @param int $width * @param int $height * @param int $method * @return void */ public function resize($thumbator, $original, $thumb, $width, $height, $method) { try { $image = Image::fromFile($original); } catch (UnknownImageFileException $e) { throw new InvalidStateException("Image: loading image error!"); } // Create dirs Helpers::mkdir(dirname($thumb)); // Resize image $image->resize($width, $height, $method); // Save thumb $image->save($thumb); }
/** * Get Image from source * @param mixed $source Source of image * @return array|NULL ["image" => Nette\Utils\Image, "filename" => string] */ public function getImageInfo($source) { if (is_string($source)) { foreach ($this->dirs as $dir) { if (file_exists($dir . $source)) { $path_parts = pathinfo($source); $filename = $path_parts['filename']; return ["image" => Image::fromFile($dir . $source), "filename" => $filename, "lazy" => TRUE, "params" => ["dir" => $path_parts['dirname'], "ext" => $path_parts['extension']]]; } elseif (Validators::isUrl($source)) { return ["image" => Image::fromFile($source), "filename" => basename($source)]; } } } }
$form->addSubmit('cancel', 'Cancel')->setAttribute('class', 'btn btn-default')->setValidationScope(FALSE); return $form; } /** Spracovanie vstupov z formulara * @param Nette\Forms\Controls\SubmitButton $button Data formulara */ public function editSliderFormSubmitted($button) { $values = $button->getForm()->getValues(); $data = $this->slider->find($values->id); //Nacitanie editovanej polozky if ($values->zobrazenie_null) { $values->zobrazenie = NULL; } unset($values->zobrazenie_null); if ($this->slider_i['odkaz']) { $values->id_hlavne_menu = (int) $values->id_hlavne_menu > 0 ? (int) $values->id_hlavne_menu : NULL; if ($values->id_hlavne_menu !== NULL) { //Kontrola exzistencie id_hlavne_menu if ($this->hlavne_menu->find($values->id_hlavne_menu) == FALSE) { $button->addError('Zadali ste nesprávne číslo článku. Skúste znovu!'); return; } } } if ($values->subor && $values->subor->name != "") { if ($values->subor->isImage()) { $slider_dir = $this->wwwDir . "/www/files/slider/"; $finalFileName = $this->_imageFileName($slider_dir, $values->subor->getSanitizedName()); $image_name = $slider_dir . $finalFileName; $values->subor->move($image_name); $image = Image::fromFile($image_name); $image->resize($this->slider_i['x'], $this->slider_i['y'], Image::SHRINK_ONLY | Image::EXACT); $image->save($image_name, 80); if (is_file('www/files/slider/' . $data['subor'])) { unlink($slider_dir . $data['subor']); } $values->subor = $finalFileName; } else { $button->addError('Zadali ste nesprávne číslo článku. Skúste znovu!'); unset($values->subor); return; } } else { unset($values->subor); } try {
/** * * @param \Nette\Http\FileUpload $file * @return string */ private function getImageBase64(\Nette\Http\FileUpload $file) { $type = $file->getContentType(); $img = Image::fromFile($file); $img->resize(100, 100, Image::EXACT); $img_string = ""; switch ($type) { case 'image/png': $img_string = $img->toString(Image::PNG); break; case 'image/jpeg': $img_string = $img->toString(Image::JPEG); break; case 'image/gif': $img_string = $img->toString(Image::GIF); break; } return 'data:' . $type . ';base64,' . base64_encode($img_string); }
/** * vykresli obrazek * @param type $image nazev obrazku * @param type $width sirka * @param type $height vyska * @param type $sharpen zaostreni * @param type $exact presna velikost (oreze zbytek) */ public function renderPreview($image, $width = null, $height = null, $sharpen = false, $exact = true) { /*$this->getHttpResponse()->setExpiration(strtotime('+ 1 year', time())); $this->getHttpResponse()->setHeader('Pragma', 'cache');*/ //nazev preview $previewName = explode('.', $image); $postfix = $previewName[count($previewName) - 1]; unset($previewName[count($previewName) - 1]); $previewName = implode('.', $previewName) . '_' . $width . '_' . $height; if ($sharpen) { $previewName .= '_sharpen'; } if ($exact) { $previewName .= '_exact'; } $previewName .= '.' . $postfix; //slouzim routu do normalniho tvaru $prefixDir = substr($image, 0, 4); if (!is_dir($this->context->parameters['wwwDir'] . '/images/preview/' . $prefixDir)) { mkdir($this->context->parameters['wwwDir'] . '/images/preview/' . $prefixDir); chmod($this->context->parameters['wwwDir'] . '/images/preview/' . $prefixDir, 0777); } if (file_exists($this->context->parameters['wwwDir'] . '/images/preview/' . $prefixDir . '/' . $previewName)) { $this->getHttpResponse()->setHeader('Content-Type', 'image/png'); echo file_get_contents($this->context->parameters['wwwDir'] . '/images/preview/' . $prefixDir . '/' . $previewName); exit; } else { $image = Image::fromFile($this->context->parameters['wwwDir'] . '/images/upload/' . $prefixDir . '/' . $image); if ($exact) { $image->resize($width, $height, Image::EXACT); } else { $image->resize($width, $height, Image::SHRINK_ONLY); } if ($sharpen) { $image->sharpen(); } $image->save($this->context->parameters['wwwDir'] . '/images/preview/' . $prefixDir . '/' . $previewName, 100, Image::JPEG); $image->send(Image::JPEG); } $this->terminate(); }
/** * @param string $imageName * @param string $imageFormatName * @throws BadRequestException */ public function __invoke($imageName, $imageFormatName) { $image = $this->imageProvider->findOneByName($imageName); if (!$image) { throw new BadRequestException('Image not found.', 404); } $imageFormat = $this->imageFormatProvider->findOneByName($imageFormatName); if (!$imageFormat) { throw new BadRequestException('Image format not found.', 404); } $originalImagePath = $this->storage->getPath($image); if (!file_exists($originalImagePath)) { \Tracy\Debugger::log(new \Nette\InvalidStateException('File not found in the storage.')); throw new BadRequestException('Image not found.', 404); } $path = $this->storage->getPath($image, $imageFormat); if (!file_exists($path)) { $this->storage->createFormatedImage($image, $imageFormat); } Image::fromFile($path)->send(); }
function uploadFormSucceeded(\Nette\Forms\BootstrapUIForm $form) { $fileDirectory = APP_DIR . '/media/' . $form->values->id; \App\Model\IO::directoryMake($fileDirectory, 0755); if (strlen($_FILES["the_file"]["tmp_name"]) > 1) { $imageExists = $this->database->table("media")->where(array('name' => $_FILES["the_file"]["name"], 'pages_id' => $form->values->id)); $fileName = $fileDirectory . '/' . $_FILES["the_file"]["name"]; \App\Model\IO::remove($fileName); copy($_FILES["the_file"]["tmp_name"], $fileName); chmod($fileName, 0644); if ($imageExists->count() == 0) { $this->database->table("media")->insert(array('name' => $_FILES["the_file"]["name"], 'pages_id' => $form->values->id, 'description' => $form->values->description, 'filesize' => filesize($fileDirectory . '/' . $_FILES["the_file"]["name"]), 'file_type' => 1, 'date_created' => date("Y-m-d H:i:s"))); } // thumbnails $image = \Nette\Utils\Image::fromFile($fileName); $image->resize(400, 250, \Nette\Utils\Image::SHRINK_ONLY); $image->sharpen(); $image->save(APP_DIR . '/media/' . $form->values->id . '/tn/' . $_FILES["the_file"]["name"]); chmod(APP_DIR . '/media/' . $form->values->id . '/tn/' . $_FILES["the_file"]["name"], 0644); } $this->redirect(this, array("id" => $form->values->id, "category" => $form->values->category)); }
/** * @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; }
/** * @return void */ protected function createThumb() { set_time_limit(1800); $finfo = new \SplFileInfo($this->src); $ext = Nette\Utils\Strings::lower($finfo->getExtension()); if ($ext === 'gif' and class_exists(\Imagick::class)) { $image = new \Imagick($this->src); $image = $image->coalesceImages(); foreach ($image as $frame) { if ($this->crop) { $frame->cropThumbnailImage($this->width, $this->height); } else { $frame->thumbnailImage($this->width, $this->height, TRUE); } $frame->setPage($this->width, $this->height, 0, 0); } $image = $image->deconstructImages(); $image->writeImages($this->desc, TRUE); } else { $image = Nette\Utils\Image::fromFile($this->src); $image->resize($this->width, $this->height, $this->crop ? Nette\Utils\Image::EXACT : Nette\Utils\Image::FIT); $image->save($this->desc); } }
public function uploadPhotoFormSucceeded($button) { $values = $button->getForm()->getValues(true); $id = (int) $this->getParameter('id'); $values['id_property'] = $id; $images = $values['img']; // ulozim si pole s obrazky do pomocne promene unset($values['img']); // unsetnu formularove pole s obrazky, abych mohl beztrestne vkladat data do db $citac = 0; foreach ($images as $img) { // operace pro nahrani fota k nemovitosti if ($img->isOk() && $img->isImage()) { // citac pouzivam k modifikaci nazvu, abych nenahral dve fotografie se stejnym timestampem // je jasne ze 100. uploadovana fotka nebude mit stejny timestamp jako prvni $citac++; if ($citac > 99) { $citac = 0; } $timestamp = date('YmdHis', time()); $typ = substr($img->getName(), -4); // umisteni fotografie ../id_nemovitosti/citac×tamp.typ $values['name'] = $citac . $timestamp . $typ; // pomoci nette si obrazek zmensim a ulozim na server j*z zmenseny, z duvodu setreni mista, neni duvod ukladat vetsi rozliseni nez vyuziji // kdybych se rozhodl, ze chci obr v plne velikosti, smazu radky az po $img->move a odkomentuji $img->move $img_tmp = Nette\Utils\Image::fromFile($img); // pokud nahravany obrazek presahuje velikosti 800px, tak ho upravim if ($img_tmp->width > 800) { $img_tmp->resize(800, null); } // w = 342px, h = auto $img_tmp->sharpen(); // doostreni obrazku if (!is_dir(WWW_DIR . "/images/auction/" . $id . "/")) { mkdir(WWW_DIR . "/images/auction/" . $id . "/", 0700); // vytvorení složky chmod(WWW_DIR . "/images/auction/" . $id . "/", 0777); // nastaveni atributu } $img_tmp->save(WWW_DIR . "/images/auction/" . $id . "/" . $values['name']); //$img->move(WWW_DIR . "/images/auction/". $id . "/" . $values['name']); $this->database->insert('photo', $values); } } $this->flashMessage('Fotografie byly nahrány.'); $this->redirect('Nemovitosti:detailNemovitosti', $id); }
/** * Saves photo * @param string $name * @return type */ private function savePhoto($name) { $www = __DIR__ . '/../../www/user-photo/'; $image = Image::fromFile($name['temp']); $image->save($www . $name['name']); $image->resize(80, NULL); $image->save($www . $name['nameMin']); return $name['name']; }
private function getImageColorInfo($filename) { $filenameSample = $filename . '.sample.jpg'; if (file_exists($filename)) { if (!file_exists($filenameSample)) { $imageFile = Image::fromFile($filename); $imageFile->resize(200, 200, Image::FILL); $imageFile->save($filenameSample, 100, Image::JPEG); } $client = new Client(); $image = $client->loadJpeg($filenameSample); $palette = $image->extract(6); $dominantColor = ColorThief::getColor($filenameSample); $dominantColor = \Aprila\Utils\Colors::rgbToHex($dominantColor); $color = new Color($dominantColor); $isDark = $color->isDark(); $imageColorInfo = ['main' => $dominantColor, 'palette' => $palette, 'isDark' => $isDark]; FileSystem::delete($filenameSample); return $imageColorInfo; } return []; }
/** * @param string $image * @param null $size * @param null $flags * @param bool $strictMode * @return string * @throws \Nette\Latte\CompileException * @throws FileNotFoundException; */ 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; }
/** * Returns the image. * @return Nette\Utils\Image * @throws Nette\Utils\ImageException */ public function toImage() { return Nette\Utils\Image::fromFile($this->tmpName); }