public function thumbate(FileUpload $file, Thumb $thumb) { /** @var $image Image */ $image = $file->toImage(); $dimension = $thumb->getDimension(); // Resize to thumb dimension $image->resize($dimension->getWidth(), $dimension->getHeight(), $dimension->getFlag()); // Image name $imagename = $thumb->getImagename(); // File name $filename = $imagename . '.' . Utils::ext($file->name); // Gets properly directory $path = Utils::dirs($this->repository, $thumb->getPath(), $filename); // Store image data $this->images[] = ArrayHash::from(['path' => Utils::dirs($this->repository, $thumb->getPath()), 'fullpath' => $path, 'filename' => $filename, 'name' => $imagename, 'ext' => Utils::ext($file->name)]); // Save to file $image->save($path); }
public function process(\Nette\Forms\Form $form) { if ($form->isSuccess()) { /** @var Thumbnailer */ $thumbator = $this->context->thumbator; $thumb1 = new Thumb(100, 200, './'); $thumb2 = new Thumb(400, 500, './', Thumb::FILENAME_FORMAT_ORIGINAL); $thumb3 = new Thumb(200, 100, './', Thumb::FILENAME_FORMAT_DIMENSION); $thumb4 = new Thumb(40, 50, './', Thumb::FILENAME_FORMAT_ORIGINAL | Thumb::FILENAME_FORMAT_DIMENSION); $thumb5 = new Thumb(300, 800, './', Thumb::FILENAME_FORMAT_VALUE); $thumb5->setFilename('felix the caT!!'); $thumbator->addThumb($thumb1); $thumbator->addThumb($thumb2); $thumbator->addThumb($thumb3); $thumbator->addThumb($thumb4); $thumbator->addThumb($thumb5); // Success handler $thumbator->onSuccess[] = function ($t) { Debugger::barDump('Sucess handler'); }; $thumbator->process($form->values->picture); Debugger::barDump($form->values); } }