Beispiel #1
0
 /**
  * Kép feltöltés
  */
 private function _uploadPicture($files_array)
 {
     $upload_path = Config::get('blogphoto.upload_path');
     $width = Config::get('blogphoto.width', 600);
     $height = Config::get('blogphoto.height', 400);
     $image = new Uploader($files_array);
     // új filenév
     $newfilename = 'blog_' . md5(uniqid());
     // nagy kép
     $image->allowed(array('image/*'));
     $image->cropToSize($width, $height);
     $image->save($upload_path, $newfilename);
     $filename = $image->getDest('filename');
     if ($image->checkError()) {
         Message::set('error', $image->getError());
         return false;
     } else {
         // nézőkép
         $thumb_width = Config::get('blogphoto.thumb_width', 150);
         $thumb_height = $image->calcHeight($thumb_width);
         $image->cropToSize($thumb_width, $thumb_height);
         $image->save($upload_path, $newfilename . '_thumb');
     }
     $image->cleanTemp();
     // kép neve
     return $filename;
 }
Beispiel #2
0
 /**
  * 	A felhasználó képét tölti fel a szerverre, és készít egy kisebb méretű képet is.
  *
  * 	Ez a metódus kettő XHR kérést dolgoz fel.
  * 	Meghívásakor kap egy id nevű paramétert melynek értékei upload vagy crop
  * 		upload paraméterrel meghívva: feltölti a kiválasztott képet
  * 		crop paraméterrel meghívva: megvágja az eredeti képet és feltölti	
  */
 public function client_img_upload()
 {
     if ($this->request->is_ajax()) {
         // feltöltés helye
         $upload_path = Config::get('clientphoto.upload_path');
         if ($this->request->has_params('upload')) {
             //képkezelő objektum létrehozása (a kép a szerveren a tmp könyvtárba kerül)
             $image = new Uploader($this->request->getFiles('img'));
             $tempfilename = 'temp_' . uniqid();
             $width = Config::get('clientphoto.width', 150);
             $image->allowed(array('image/*'));
             $image->resize($width, null);
             $image->save($upload_path, $tempfilename);
             if ($image->checkError()) {
                 $this->response->json(array("status" => 'error', "message" => $image->getError()));
             } else {
                 $this->response->json(array("status" => 'success', "url" => $upload_path . $image->getDest('filename'), "width" => $image->getDest('width'), "height" => $image->getDest('height')));
             }
         } else {
             if ($this->request->has_params('crop')) {
                 // a croppic js küldi ezeket a POST adatokat
                 $imgUrl = $this->request->get_post('imgUrl');
                 // original sizes
                 $imgInitW = $this->request->get_post('imgInitW');
                 $imgInitH = $this->request->get_post('imgInitH');
                 // resized sizes
                 //kerekítjük az értéket, mert lebegőpotos számot is kaphatunk és ez hibát okozna a kép generálásakor
                 $imgW = round($this->request->get_post('imgW'));
                 $imgH = round($this->request->get_post('imgH'));
                 // offsets
                 // megadja, hogy mennyit kell vágni a kép felső oldalából
                 $top_crop = $this->request->get_post('imgY1');
                 // megadja, hogy mennyit kell vágni a kép bal oldalából
                 $left_crop = $this->request->get_post('imgX1');
                 // crop box
                 $cropW = $this->request->get_post('cropW');
                 $cropH = $this->request->get_post('cropH');
                 // rotation angle
                 //$angle = $this->request->get_post('rotation'];
                 //a $right_crop megadja, hogy mennyit kell vágni a kép jobb oldalából
                 $right_crop = $imgW - $left_crop - $cropW;
                 //a $bottom_crop megadja, hogy mennyit kell vágni a kép aljából
                 $bottom_crop = $imgH - $top_crop - $cropH;
                 //képkezelő objektum létrehozása (a feltöltött kép elérése a paraméter)
                 $image = new Uploader($imgUrl);
                 $newfilename = 'client_' . md5(uniqid());
                 $image->resize($imgW, null);
                 $image->crop(array($top_crop, $right_crop, $bottom_crop, $left_crop));
                 $image->save($upload_path, $newfilename);
                 if ($image->checkError()) {
                     $this->response->json(array("status" => 'error', "message" => $image->getError()));
                 } else {
                     // temp kép törlése
                     DI::get('file_helper')->delete($imgUrl);
                     $this->response->json(array("status" => 'success', "url" => $upload_path . $image->getDest('filename')));
                 }
             }
         }
     }
     //is_ajax
 }
 /**
  * Kép feltöltés
  * @param array $files_array - $_FILES['valami']
  * @return string
  */
 private function _uploadImage($files_array)
 {
     $upload_path = Config::get('photogallery.upload_path');
     $photo_width = Config::get('photogallery.width', 800);
     $photo_height = Config::get('photogallery.height', 600);
     $image = new Uploader($files_array);
     $newfilename = md5(uniqid());
     $image->allowed(array('image/*'));
     $image->cropToSize($photo_width, $photo_height);
     $image->save($upload_path, $newfilename);
     $dest_filename = $image->getDest('filename');
     if ($image->checkError()) {
         Message::set('error', $image->getError());
         return false;
     } else {
         $thumb_width = Config::get('photogallery.thumb_width', 320);
         $thumb_height = Config::get('photogallery.thumb_height', 240);
         $image->cropToSize($thumb_width, $thumb_height);
         $image->save($upload_path, $newfilename . '_thumb');
     }
     // visszatér a kép nevével
     return $dest_filename;
 }