Exemplo n.º 1
0
 public function renderJson()
 {
     $images = $this->upload->getImages();
     $arr = array();
     foreach ($images as $image) {
         $arr[] = array("thumb" => $this->link("//:Service:Thumbnail:default", array('id' => $image->id, 'width' => 100, 'height' => 100, 'crop' => "crop", 'format' => "png")), "image" => $this->link("//:Service:Thumbnail:default", array('id' => $image->id, 'width' => 600, 'format' => "jpg")), "title" => $image['title'], "alt" => $image['alt']);
     }
     $this->sendResponse(new \Nette\Application\Responses\JsonResponse($arr));
 }
Exemplo n.º 2
0
 protected function createComponentClanek()
 {
     $form = new Form();
     $form->addHidden("id");
     $form->addText("titulek", "Titulek")->addRule(Form::MAX_LENGTH, "Titulek je příliš dlouhý", 64);
     $form->addText("autor", "Autor")->addRule(Form::MAX_LENGTH, "Autor je příliš dlouhý", 64);
     $form->addSelect("kategorie_id", "Kategorie", $this->kategorie->getPairs());
     $form->addTextArea("perex", "Perex");
     $form->addSelect("obrazek_id", "Obrázek", $this->upload->getPairs())->setPrompt("-- bez obrázku --");
     $form->addTextArea("text", "Text");
     $form->addTextArea("stitky_text", "Štítky");
     $form->addText("skupina", "Skupina");
     $form->addSubmit("save", "Uložit");
     $form->onSuccess[] = $this->saveClanek;
     return $form;
 }
 public function renderDefault($id, $width = "", $height = "", $format = null, $crop = null)
 {
     if (!empty($width) && !preg_match('/^\\d+$/', $width)) {
         $this->terminate();
     }
     if (!empty($height) && !preg_match('/^\\d+$/', $height)) {
         $this->terminate();
     }
     if ($width > 2000 || $height > 2000) {
         $this->reminate();
     }
     if (!in_array($format, array("jpg", "jpeg", "png"))) {
         $this->terminate();
     }
     if (!empty($crop)) {
         $crop = true;
     } else {
         $crop = false;
     }
     $image = $this->upload->get($id);
     $filename = THUMBS_DIR;
     if (!empty($width)) {
         $filename .= "/w" . $width;
     }
     if (!empty($height)) {
         $filename .= "/h" . $height;
     }
     if ($crop) {
         $filename .= "/crop";
     }
     if (!file_exists($filename)) {
         mkdir($filename, 0755, true);
     }
     $filename .= "/" . $id . "." . $format;
     $inputfile = UPLOAD_DIR . "/" . $image['id'] . "." . $image["extension"];
     if (!file_exists($inputfile)) {
         throw new \Nette\Application\BadRequestException();
     }
     try {
         $img = \Nette\Image::fromFile($inputfile);
     } catch (\Nette\Utils\UnknownImageFileException $e) {
         throw new \Nette\Application\BadRequestException();
     }
     if (!empty($width) && !empty($height)) {
         if (!empty($crop)) {
             if ($img->getHeight() / $img->getWidth() > $height / $width) {
                 $img->resize($width, null);
                 $img->crop(0, ($img->getHeight() - $height) / 2, $width, $height);
             } else {
                 $img->resize(null, $height);
                 $img->crop(($img->getWidth() - $width) / 2, 0, $width, $height);
             }
         } else {
             $img->resize($width, $height);
         }
     } elseif (!empty($width)) {
         $img->resize($width, null);
     } elseif (!empty($height)) {
         $img->resize(null, $height);
     }
     $img->save($filename);
     $img->send();
     $this->terminate();
 }
Exemplo n.º 4
0
 public function renderDefault()
 {
     $this->template->upload = $this->upload->getAll();
 }