Beispiel #1
0
 public function createComponentRegisterForm($name)
 {
     $form = new Form($this, $name);
     $form->onSuccess[] = callback($this, $name . 'Submitted');
     $login = $this->getContext()->config->get('user.login');
     $form->addText('name', 'Jméno')->setRequired('Prosím vyplňte své jméno');
     $form->addText('surname', 'Přijímení')->setRequired('Prosím vyplňte své přijímení');
     if ($login === 'username') {
         $form->addText('username', 'Uživatelské jméno:')->setRequired('Prosím vyplňte své uživatelské jméno.');
     }
     // we want the email anyway...
     $form->addText('email', 'E-mail:')->addRule(Form::EMAIL, 'Prosím vyplňte validní emailovou adresu.')->setRequired('Prosím vyplňte svou emailovou adresu.');
     $form->addPassword('password', 'Heslo:')->setRequired('Prosím vyplňte své heslo')->addRule(Form::MIN_LENGTH, 'Vaše heslo musí být dlouhé nejméně %d znaků.', $this->context->config->get('security.password.minLength', 6));
     $form->addPassword('passwordCheck', 'Heslo znovu pro kontrolu:')->setRequired('Prosím vyplňte své druhé helso pro kontrolu.')->addRule(Form::EQUAL, 'Vyplněná hesla se neshodují', $form['password']);
     $form->addCheckbox('newsletter', 'Mám zájem o pravidelné zasílání novinek')->setDefaultValue(true);
     \PavelMaca\Captcha\CaptchaControl::register();
     $form['captcha'] = new \PavelMaca\Captcha\CaptchaControl();
     $form['captcha']->caption = 'Security code:';
     $form['captcha']->setTextColor(Nette\Image::rgb(48, 48, 48));
     $form['captcha']->setBackgroundColor(Nette\Image::rgb(232, 234, 236));
     $form['captcha']->setRequired('Prosím opište bezpečnostní kód z obrázku');
     $form['captcha']->addRule($form["captcha"]->getValidator(), 'Bezpečnostní kód se neshoduje. Prosím zkuste to znovu.');
     $form->addSubmit('s', 'Registrovat!');
 }
Beispiel #2
0
 public function resizeAndSaveImage($imagePath, $dimensions, $cutToFit = false)
 {
     // first check on s3 service
     if (!$this->awsService->isFile($imagePath)) {
         return array($imagePath, null, null);
     }
     $info = pathinfo($imagePath);
     $imageDir = $info['dirname'] . '/';
     $imageName = basename($imagePath);
     ////////////////////////////////////////
     // read dimensions
     ////////////////////////////////////////
     $dim = explode('x', $dimensions);
     $newWidth = isset($dim[0]) ? $dim[0] : null;
     $newHeight = isset($dim[1]) ? $dim[1] : null;
     try {
         $resizedImageName = Strings::webalize(basename($imagePath, '.' . $info['extension'])) . '-' . $newWidth . 'x' . $newHeight . '.' . $info['extension'];
         $resizedImagePath = $imageDir . $resizedImageName;
         // check if resized image is already on s3, if yes, return, if not, generate and save
         if ($this->awsService->isFile($resizedImagePath)) {
             $resizedImagePath = $this->baseUrl . $resizedImagePath;
             $result = array($resizedImagePath, $newWidth, $newHeight);
             return $result;
         }
         // need to download the original image and convert the sizes
         $tempImagePath = $this->tempDir . $imageName;
         // download image from s3 to temporary directory
         $this->awsService->downloadFile($imagePath, $tempImagePath);
         // load and resize image
         $image = Image::fromFile($tempImagePath);
         if ($cutToFit) {
             if ($image->height > $image->width) {
                 $image->resize($newWidth, $newHeight, Image::FILL);
                 $image->sharpen();
                 $blank = Image::fromBlank($newWidth, $newHeight, Image::rgb(255, 255, 255));
                 $blank->place($image, 0, '20%');
                 $image = $blank;
             } else {
                 $image->resize($newWidth, $newHeight, Image::FILL | Image::EXACT);
                 $image->sharpen();
             }
         } else {
             $image->resize((int) $newWidth, (int) $newHeight, Image::SHRINK_ONLY);
             $image->sharpen();
         }
         // generate new image
         $image->save($tempImagePath, 85);
         // 85% quality
         // upload file to s3 storage
         $this->awsService->uploadFile($tempImagePath, $resizedImagePath);
         $result = array($this->baseUrl . $resizedImagePath, $image->width, $image->height);
         // free memory
         $image = null;
         unset($image);
         // remove temporary file
         if (file_exists($tempImagePath)) {
             unlink($tempImagePath);
         }
         return $result;
     } catch (\Exception $e) {
         //$this->logger->logError($e);
         return array($this->baseUrl . $imagePath, null, null);
     }
 }
Beispiel #3
0
/**
 * Nette\Image drawing example.
 * @author     David Grudl
 */


require __DIR__ . '/../../Nette/loader.php';

use Nette\Image,
	Nette\Diagnostics\Debugger;


Debugger::enable();



$image = Image::fromBlank(300, 300);

// white background
$image->filledRectangle(0, 0, 299, 299, Image::rgb(255, 255, 255));

// black border
$image->rectangle(0, 0, 299, 299, Image::rgb(0, 0, 0));

// three ellipses
$image->filledEllipse(100, 75, 150, 150, Image::rgb(255, 255, 0, 75));
$image->filledEllipse(120, 168, 150, 150, Image::rgb(255, 0, 0, 75));
$image->filledEllipse(187, 125, 150, 150, Image::rgb(0, 0, 255, 75));

$image->send();
Beispiel #4
0
 public function createComponentRetrievePasswordForm($name)
 {
     $form = new Form();
     $form->addProtection();
     $form->addText('email', 'E-mail:')->setEmptyValue('@')->addRule(Form::EMAIL, 'Zadaná e-mailová adresa není platná')->setRequired('Prosím vyplňte e-mail zadaný při registraci');
     \PavelMaca\Captcha\CaptchaControl::register();
     $form['captcha'] = new \PavelMaca\Captcha\CaptchaControl();
     $form['captcha']->caption = 'Bezpečnosntí kód:';
     $form['captcha']->setTextColor(Nette\Image::rgb(48, 48, 48));
     $form['captcha']->setBackgroundColor(Nette\Image::rgb(232, 234, 236));
     $form['captcha']->addRule(Form::FILLED, 'Přepište prosím bezpečnosntí kód');
     $form['captcha']->addRule($form["captcha"]->getValidator(), 'Zadaný bezpečnostní kód není správný. Přepište jej prosím pečlivě z obrázku vlevo.');
     $form->addSubmit('send', 'Zaslat heslo');
     $form->onSuccess[] = callback($this, $name . 'Submitted');
     $form->onError[] = callback($this, 'sendNewCaptcha');
     $form->onError[] = callback($this, 'ajaxFormErrors');
     return $form;
 }
Beispiel #5
0
 /**
  * @param array red 0-255, green 0-255, blue 0-255
  * @return CaptchaControl provides a fluent interface
  * @throws \Nette\InvalidArgumentException
  */
 public function setBackgroundColor($rgb)
 {
     if (!isset($rgb["red"]) || !isset($rgb["green"]) || !isset($rgb["blue"])) {
         throw new \Nette\InvalidArgumentException("BackgroundColor must be valid rgb array, see Nette\\Image::rgb()");
     }
     $this->backgroundColor = Image::rgb($rgb["red"], $rgb["green"], $rgb["blue"]);
     return $this;
 }
Beispiel #6
0
 private function _createTinyPlaceholderForGallery($galleryId, $fontFile, $fontSize)
 {
     $config = $this->getConfig();
     $pattern = $config['tinyPlaceholderPattern'];
     $placeholderFilename = sprintf($pattern, $galleryId);
     $placeholderFilePath = $this->getTempDir() . '/' . $placeholderFilename;
     if (!is_file($placeholderFilePath)) {
         // create placeholder
         $folder = $this->getFolder($galleryId);
         $filename = $this->getGalleryIconPath($galleryId);
         $image = Nette\Image::fromFile($filename);
         $blank = Nette\Image::fromBlank(350, 100, Nette\Image::rgb(220, 220, 220));
         $blank->place($image, 8, 8);
         $rgb = $blank->rgb(0, 0, 0);
         $imageResource = $blank->getImageResource();
         $color = imagecolorallocatealpha($imageResource, $rgb['red'], $rgb['green'], $rgb['blue'], $rgb['alpha']);
         $x = 100;
         $y = 8 + $fontSize;
         $text = 'Galerie';
         imagettftext($imageResource, $fontSize, 0, $x, $y, $color, $fontFile, $text);
         $x = 100;
         $y = 8 + 3 * $fontSize;
         $text = $folder['name'];
         imagettftext($imageResource, $fontSize, 0, $x, $y, $color, $fontFile, $text);
         $resultImage = new Nette\Image($imageResource);
         $resultImage->save($placeholderFilePath);
     }
     return $this->getTempPath() . '/' . $placeholderFilename;
 }