Exemplo n.º 1
0
 public function post_new_city()
 {
     $rules = array('city' => 'required|unique:photos', 'picture' => 'required');
     $v = Validator::make(Input::all(), $rules);
     if ($v->fails()) {
         return Redirect::to('admin/cityphotos')->with_errors($v)->with_input();
     } else {
         $new_photo = array('city' => ucwords(Input::get('city')));
         $photo = new Photo($new_photo);
         if ($photo->save()) {
             $upload_path = path('public') . Photo::$upload_path_city . $photo->city;
             if (!File::exists($upload_path)) {
                 File::mkdir($upload_path);
             }
             $filename = $photo->city . '.jpg';
             $path_to_file = $upload_path . '/' . $filename;
             $dynamic_path = '/' . Photo::$upload_path_city . $photo->city . '/' . $filename;
             $success = Resizer::open(Input::file('picture'))->resize(1024, 724, 'auto')->save($path_to_file, 75);
             if ($success) {
                 $new_photo = Photo::find($photo->id);
                 $new_photo->location = $dynamic_path;
                 $new_photo->save();
             }
             return Redirect::to('admin/cityphotos')->with('msg', '<div class="alert alert-success"><strong>City foto is geupload!</strong></div>');
         } else {
             return Redirect::to('admin/cityphotos')->with('msg', '<div class="alert alert-error"><strong>Er is iets mis gegaan bij het toevoegen.</strong></div>');
         }
     }
 }
Exemplo n.º 2
0
 public static function upload($model, $modelName, $name, $attribute, $removePastImage = true, $sizes = array())
 {
     $uploadOptions = $attribute["uploadOptions"];
     $path = "public";
     $beforeImage = $model->{$name};
     if (isset($uploadOptions["sizes"])) {
         $sizes = $uploadOptions["sizes"];
     }
     if (isset($uploadOptions["path"])) {
         $path = $uploadOptions["path"];
     }
     $files = Input::file($name);
     if ($files["name"] == "") {
         return false;
     }
     $extension = File::extension($files["name"]);
     $directory = path($path) . $uploadOptions["directory"];
     $nameFile = sha1(Session::has("token_user") . microtime());
     $filename = "{$nameFile}.{$extension}";
     $fullPath = $directory . "/" . $filename;
     $defaultImage = $directory . "/" . $filename;
     $defaultImageName = $filename;
     $successUpload = Input::upload($name, $directory, $filename);
     if ($successUpload === false) {
         return false;
     }
     if (File::exists($directory . "/" . $beforeImage)) {
         File::delete($directory . "/" . $beforeImage);
     }
     var_dump($beforeImage);
     $beforeExtension = File::extension($beforeImage);
     $preg = $directory . "/" . preg_replace("/\\.{$beforeExtension}/", "", $beforeImage);
     if (!empty($beforeImage)) {
         foreach (glob("{$preg}*", GLOB_ONLYDIR) as $key => $dir) {
             File::rmdir($dir);
         }
     }
     foreach ($sizes as $key => $size) {
         if (!preg_match("/\\d*x\\d*/", $size)) {
             throw new Exception("Size doesnt have a valid format valid for {$size} example: ddxdd", 1);
         }
         if (!class_exists("Resizer")) {
             throw new Exception("Bundle Resizer must be installed <br> Please got to <a href='http://bundles.laravel.com/bundle/resizer'>http://bundles.laravel.com/bundle/resizer</a>", 1);
         }
         $filename = $nameFile . "_{$key}.{$extension}";
         $sizeOptions = preg_split("/x/", $size);
         $fullPath = $directory . "/{$nameFile}{$key}/" . $filename;
         $beforeImageWithSize = $directory . "/{$nameFile}{$key}/" . $beforeImage;
         if (!is_dir($directory . "/" . $nameFile . $key)) {
             mkdir($directory . "/" . $nameFile . $key, 0777);
         }
         $success = Resizer::open($defaultImage)->resize($sizeOptions[0], $sizeOptions[1], 'fit')->save($fullPath, 90);
         if ($success === false) {
             return false;
         }
     }
     return array("fullPath" => $defaultImage, "fileName" => $defaultImageName);
 }
Exemplo n.º 3
0
 public function post_new()
 {
     $rules = array('title' => 'required|min:5|max:128', 'street' => 'required', 'postalcode' => 'required|match:#^[1-9][0-9]{3}\\h*[A-Z]{2}$#i', 'city' => 'required', 'type' => 'required', 'surface' => 'required|integer', 'price' => 'required|numeric|max:1500|min:100', 'date' => 'required|after:' . date('d-m-Y'), 'pictures' => 'required|image|max:3000', 'register' => 'required', 'email' => 'required|email|same:email2', 'description' => 'required|min:30', 'captchatest' => 'laracaptcha|required', 'terms' => 'accepted');
     $v = Validator::make(Input::all(), $rules, Room::$messages);
     if ($v->fails()) {
         return Redirect::to('kamer-verhuren')->with_errors($v)->with('msg', '<div class="alert alert-error"><strong>Verplichte velden zijn niet volledig ingevuld</strong><br />Loop het formulier nogmaals na.</div>')->with_input();
     } else {
         if (Auth::check()) {
             $status = 'publish';
         } else {
             $status = 'pending';
         }
         $new_room = array('title' => ucfirst(Input::get('title')), 'street' => ucwords(Input::get('street')), 'housenr' => Input::get('housenr'), 'postalcode' => Input::get('postalcode'), 'city' => ucwords(Input::get('city')), 'type' => Input::get('type'), 'surface' => Input::get('surface'), 'price' => Input::get('price'), 'available' => date("Y-m-d", strtotime(Input::get('date'))), 'gender' => Input::get('gender'), 'pets' => Input::get('pets'), 'smoking' => Input::get('smoking'), 'toilet' => Input::get('toilet'), 'shower' => Input::get('shower'), 'kitchen' => Input::get('kitchen'), 'register' => Input::get('register'), 'social' => Input::get('social'), 'email' => strtolower(Input::get('email')), 'description' => ucfirst(Input::get('description')), 'status' => $status, 'url' => Str::slug(Input::get('city')), 'delkey' => Str::random(32, 'alpha'), 'del_date' => date('y-m-d', strtotime('+2 months')));
         $room = new Room($new_room);
         if ($room->save()) {
             $upload_path = path('public') . Photo::$upload_path_room . $room->id;
             if (!File::exists($upload_path)) {
                 File::mkdir($upload_path);
                 chmod($upload_path, 0777);
             }
             $photos = Photo::getNormalizedFiles(Input::file('pictures'));
             foreach ($photos as $photo) {
                 $filename = md5(rand()) . '.jpg';
                 $path_to_file = $upload_path . '/' . $filename;
                 $dynamic_path = '/' . Photo::$upload_path_room . $room->id . '/' . $filename;
                 $success = Resizer::open($photo)->resize(800, 533, 'auto')->save($path_to_file, 80);
                 chmod($path_to_file, 0777);
                 if ($success) {
                     $new_photo = new Photo();
                     $new_photo->location = $dynamic_path;
                     $new_photo->room_id = $room->id;
                     $new_photo->save();
                 }
             }
             Message::send(function ($message) use($room) {
                 $message->to($room->email);
                 $message->from('*****@*****.**', 'Kamergenood');
                 $message->subject('In afwachting op acceptatie: "' . $room->title . '"');
                 $message->body('view: emails.submit');
                 $message->body->id = $room->id;
                 $message->body->title = $room->title;
                 $message->body->price = $room->price;
                 $message->body->type = $room->type;
                 $message->body->surface = $room->surface;
                 $message->body->available = $room->available;
                 $message->body->description = $room->description;
                 $message->body->url = $room->url;
                 $message->body->delkey = $room->delkey;
                 $message->html(true);
             });
             if (Message::was_sent()) {
                 return Redirect::to('kamer-verhuren')->with('msg', '<div class="alert alert-success"><strong>Hartelijk dank voor het vertrouwen in Kamergenood!</strong> De kameradvertentie zal binnen 24 uur worden gecontroleerd en geplaatst.</div>');
             }
         } else {
             return Redirect::to('kamer-verhuren')->with('msg', '<div class="alert alert-error"><strong>Er is iets mis gegaan bij het toevoegen.</strong> Probeer het later nog eens.</div>')->with_input();
         }
     }
 }
Exemplo n.º 4
0
 protected function _field($obj)
 {
     if (empty($obj[$this->get_name()])) {
         return '<td>no image</td>';
     }
     $path = $obj[$this->get_name()];
     if (!is_null($this->_resize)) {
         $path = Resizer::thumb($path, $this->_resize);
     }
     return '<td>' . Html::image($path) . '</td>';
 }
Exemplo n.º 5
0
 public static function upload_slideshow($image, $directory, $filename)
 {
     if (!is_dir($directory)) {
         mkdir($directory, 0777, true);
     }
     $img = Input::file($image);
     $success1 = Resizer::open($img)->resize(600, 300, 'exact')->save($directory . DS . 'medium.png', 100);
     $success2 = Resizer::open($img)->resize(230, 150, 'exact')->save($directory . DS . 'small.png', 100);
     if ($success1 && $success2) {
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 6
0
 public function post_upload($galleryID)
 {
     $path = path('public') . 'images/' . $galleryID;
     Fineuploader::init($path);
     $name = Fineuploader::getName();
     $fuResponse = Fineuploader::upload($name);
     if (isset($fuResponse['success']) && $fuResponse['success'] == true) {
         $file = Fineuploader::getUploadName();
         Bundle::start('resizer');
         $success = Resizer::open($file)->resize(300, 300, 'landscape')->save($path . '/thumbs/' . $name, 90);
         Images::create($galleryID, $name);
     }
     return Response::json($fuResponse);
 }
Exemplo n.º 7
0
 /**
  * Edit item
  * @return Response
  */
 public function post_edit($id = null)
 {
     if (!Auth::can('edit_items')) {
         Vsession::cadd('y', __('site.not_allowed'))->cflash('status');
         return Redirect::to_action('item@list');
     }
     // Input ID
     if (!$id || !$this->item_exists($id, 'items')) {
         return Redirect::to_action('item@list');
     }
     $id = trim(filter_var($id, FILTER_SANITIZE_NUMBER_INT));
     if (Input::get('submit')) {
         $rules = array('name' => 'required|max:200', 'category' => 'required|cat_exists', 'code' => 'required|max:50|code_unique:' . $id, 'part_num' => 'required|max:20', 'buying_price' => 'numeric', 'selling_price' => 'numeric', 'location' => 'max:200');
         if (Auth::can('upload_item_images')) {
             $rules['image'] = 'image|mimes:jpg,png,gif';
         }
         $input = Input::all();
         $validation = Validator::make($input, $rules);
         if ($validation->fails()) {
             Vsession::cadd('r', $validation->errors->first())->cflash('status');
         } else {
             foreach ($input as $key => $value) {
                 $input[$key] = $value !== '' ? trim(filter_var($value, FILTER_SANITIZE_STRING)) : null;
             }
             $date = new \DateTime();
             DB::table('items')->where('id', '=', $id)->update(array('name' => $input['name'], 'categories_id' => $input['category'], 'code' => $input['code'], 'part_num' => $input['part_num'], 'buying_price' => $input['buying_price'], 'selling_price' => $input['selling_price'], 'location' => $input['location'], 'description' => $input['description'], 'created_at' => $date, 'updated_at' => $date));
             if (Auth::can('upload_item_images')) {
                 if (Input::file('image') !== null && Input::file('image.name') !== '') {
                     $path = Config::get('application.upload_path') . DS . 'images' . DS . 'items' . DS . $id . '.' . File::extension(Input::file('image.name'));
                     // Starting resizer
                     Bundle::start('resizer');
                     $success = Resizer::open(Input::file('image'))->resize(500, 500, 'crop')->save($path, 90);
                 }
             }
             Vsession::cadd('g', __('site.st_item_saved'))->cflash('status');
             return Redirect::to_action('item@edit/' . $id);
         }
     }
     return $this->get_edit($id);
 }
Exemplo n.º 8
0
 /**
  * Store image into cache, create resized image if necessary.
  *
  * @param string $imageName
  * @param array  $options
  */
 private function generateAndStoreImage($imageName, array $options)
 {
     // if both axles set to 0 we simply store default image
     if ($options['width'] === 0 && $options['height'] === 0) {
         $this->imageMap->insert($imageName, $imageName, 0, 0, 1);
     } else {
         $resizer = new Resizer();
         // first we need the default image to be loaded
         $default = new SimpleImage($this->basedir, $this->fileName);
         // resize image with given options and store it onto disk
         $this->image = $resizer->resizeImage($default->image, $options);
         // generate cached image file name
         list($width, $height) = Resizer::getDimensions($this->image);
         $fileName = $this->generateFileName($this->fullPath, $width, $height);
         $this->storeImage($this->image, $fileName);
         // insert entry into cache
         $this->imageMap->insert($imageName, $fileName, $width, $height, $resizer->keepAspectRatio());
     }
 }
Exemplo n.º 9
0
 public function action_do_edit($modpack_id)
 {
     if (empty($modpack_id)) {
         return Redirect::to('dashboard');
     }
     $modpack = Modpack::find($modpack_id);
     if (empty($modpack_id)) {
         return Redirect::to('dashboard');
     }
     $rules = array('name' => 'required|unique:modpacks,name,' . $modpack->id, 'slug' => 'required|unique:modpacks,slug,' . $modpack->id);
     $messages = array('name_required' => 'You must enter a modpack name.', 'slug_required' => 'You must enter a modpack slug');
     $validation = Validator::make(Input::all(), $rules, $messages);
     if ($validation->fails()) {
         return Redirect::back()->with_errors($validation->errors);
     }
     $url = Config::get('solder.repo_location') . Input::get('slug') . '/resources/';
     $modpack->name = Input::get('name');
     $oldSlug = $modpack->slug;
     $modpack->slug = Input::get('slug');
     $modpack->icon_md5 = UrlUtils::get_remote_md5($url . 'icon.png');
     $modpack->logo_md5 = UrlUtils::get_remote_md5($url . 'logo_180.png');
     $modpack->background_md5 = UrlUtils::get_remote_md5($url . 'background.jpg');
     $modpack->hidden = Input::get('hidden') ? true : false;
     $modpack->private = Input::get('private') ? true : false;
     $modpack->save();
     $useS3 = Config::get('solder.use_s3');
     if ($useS3) {
         $resourcePath = path('storage') . 'resources/' . $modpack->slug;
     } else {
         $resourcePath = path('public') . 'resources/' . $modpack->slug;
     }
     /* Create new resources directory for modpack */
     if (!file_exists($resourcePath)) {
         mkdir($resourcePath);
     }
     /* If slug changed, move resources and delete old slug directory */
     if ($oldSlug != $modpack->slug) {
         $oldPath = path('public') . 'resources/' . $oldSlug;
         if (Config::get('solder.use_s3')) {
             try {
                 S3::copyObject(Config::get('solder.bucket'), 'resources/' . $oldSlug . '/logo.png', Config::get('solder.bucket'), 'resources/' . $modpack->slug . '/logo.png', S3::ACL_PUBLIC_READ);
                 S3::copyObject(Config::get('solder.bucket'), 'resources/' . $oldSlug . '/background.png', Config::get('solder.bucket'), 'resources/' . $modpack->slug . '/background.png', S3::ACL_PUBLIC_READ);
                 S3::copyObject(Config::get('solder.bucket'), 'resources/' . $oldSlug . '/icon.png', Config::get('solder.bucket'), 'resources/' . $modpack->slug . '/icon.png', S3::ACL_PUBLIC_READ);
                 S3::deleteObject(Config::get('solder.bucket'), 'resources/' . $oldSlug . '/logo.png');
                 S3::deleteObject(Config::get('solder.bucket'), 'resources/' . $oldSlug . '/background.png');
                 S3::deleteObject(Config::get('solder.bucket'), 'resources/' . $oldSlug . '/icon.png');
             } catch (Exception $e) {
             }
             $oldPath = path('storage') . 'resources/' . $oldSlug;
         }
         if (file_exists($oldPath . "/logo.png")) {
             copy($oldPath . "/logo.png", $resourcePath . "/logo.png");
             unlink($oldPath . "/logo.png");
         }
         if (file_exists($oldPath . "/background.png")) {
             copy($oldPath . "/background.png", $resourcePath . "/background.png");
             unlink($oldPath . "/background.png");
         }
         if (file_exists($oldPath . "/icon.png")) {
             copy($oldPath . "/icon.png", $resourcePath . "/icon.png");
             unlink($oldPath . "/icon.png");
         }
         rmdir($oldPath);
     }
     /* Image dohickery */
     $logo = Input::file('logo');
     if (!empty($logo['name'])) {
         $success = Resizer::open(Input::file('logo'))->resize(180, 110, 'exact')->save($resourcePath . "/logo.png", 90);
         if ($useS3) {
             S3::putObject(S3::inputFile($resourcePath . '/logo.png', false), Config::get('solder.bucket'), 'resources/' . $modpack->slug . '/logo.png', S3::ACL_PUBLIC_READ);
         }
         if ($success) {
             $modpack->logo = true;
             $modpack->logo_md5 = md5_file($resourcePath . "/logo.png");
         }
     }
     $background = Input::file('background');
     if (!empty($background['name'])) {
         $success = Resizer::open(Input::file('background'))->resize(880, 520, 'exact')->save($resourcePath . "/background.png", 90);
         if ($useS3) {
             S3::putObject(S3::inputFile($resourcePath . '/background.png', false), Config::get('solder.bucket'), 'resources/' . $modpack->slug . '/background.png', S3::ACL_PUBLIC_READ);
         }
         if ($success) {
             $modpack->background = true;
             $modpack->background_md5 = md5_file($resourcePath . "/background.png");
         }
     }
     $icon = Input::file('icon');
     if (!empty($icon['name'])) {
         $success = Resizer::open(Input::file('icon'))->resize(50, 50, 'exact')->save($resourcePath . "/icon.png", 90);
         if ($useS3) {
             S3::putObject(S3::inputFile($resourcePath . '/icon.png', false), Config::get('solder.bucket'), 'resources/' . $modpack->slug . '/icon.png', S3::ACL_PUBLIC_READ);
         }
         if ($success) {
             $modpack->icon = true;
             $modpack->icon_md5 = md5_file($resourcePath . "/icon.png");
         }
     }
     $modpack->save();
     Cache::forget('modpack.' . $modpack->slug);
     Cache::forget('modpacks');
     /* Client Syncing */
     $clients = Input::get('clients');
     $modpack->clients()->sync($clients);
     return Redirect::to('modpack/view/' . $modpack->id)->with('success', 'Modpack edited');
 }
Exemplo n.º 10
0
 private function imageSizer($im, $cat)
 {
     //Creating a temp image for background making it full white and 800x800
     $imageBG = imagecreatetruecolor(800, 800);
     $background = imagecolorallocate($imageBG, 255, 255, 255);
     imagefill($imageBG, 0, 0, $background);
     //Getting the image
     $info = pathinfo($im['name']);
     $xplode = explode(".", $im['name']);
     $name = $xplode[0] . ".jpg";
     //TODO::Add This to Config!
     $size = array("800" => "800", "500" => "500", "300" => "300", "200" => "200", "80" => "80", "40" => "40");
     $extension = strtolower($info['extension']);
     if (in_array($extension, array('jpg', 'jpeg', 'png', 'gif'))) {
         switch ($extension) {
             case 'jpg':
                 $topImage = imagecreatefromjpeg($im['tmp_name']);
                 break;
             case 'jpeg':
                 $topImage = imagecreatefromjpeg($im['tmp_name']);
                 break;
             case 'png':
                 $topImage = imagecreatefrompng($im['tmp_name']);
                 break;
             case 'gif':
                 $topImage = imagecreatefromgif($im['tmp_name']);
                 break;
             default:
                 $topImage = imagecreatefromjpeg($im['tmp_name']);
         }
         // load image and get image size
     }
     // Get image dimensions
     $baseWidth = imagesx($imageBG);
     $baseHeight = imagesy($imageBG);
     $topWidth = imagesx($topImage);
     $topHeight = imagesy($topImage);
     $destX = ($baseWidth - $topWidth) / 2;
     $destY = ($baseHeight - $topHeight) / 2;
     if ($topWidth <= 800 && $topHeight <= 800) {
         imagecopy($imageBG, $topImage, $destX, $destY, 0, 0, $topWidth, $topHeight);
         imagejpeg($imageBG, 'upload/' . $name);
     } else {
         $success = Resizer::open($im)->resize(800, 800, 'fit')->save('upload/' . $name, 90);
         if (!$success) {
             return false;
         }
     }
     // Release memory
     imagedestroy($imageBG);
     imagedestroy($topImage);
     //Begin Resize and save the images!!!
     $fileDirectory = "public/img/products/" . $cat->getDescriptions->alias . '/';
     $createBrandDir = File::mkdir($fileDirectory);
     $randomid = uniqid(mt_rand());
     foreach ($size as $k => $v) {
         $prodimgName = $randomid . ".jpg";
         File::mkdir($fileDirectory . $k);
         $success = Resizer::open("upload/" . $name)->resize($k, $v, 'fit')->save($fileDirectory . $k . "/" . $prodimgName, 100);
         if (!$success) {
             echo 'error';
             return false;
         }
     }
     return $randomid;
 }
Exemplo n.º 11
0
 public function post_edit_marker($id)
 {
     $input = Input::all();
     $file = Input::file('img_input');
     $rules = array('name' => 'required|max:150', 'address' => 'required|max:200', 'lat' => 'required|numeric', 'lng' => 'required|numeric', 'type' => 'required|alpha', 'img_input' => 'mimes:jpg,gif,png,jpeg|image');
     $v = Validator::make($input, $rules);
     if ($v->fails()) {
         return Redirect::to_action('home@edit_marker/' . $id)->with_errors($v);
     } else {
         // save thumbnail
         if (!empty($file['name'])) {
             $success = Resizer::open($file)->resize(120, 100, 'landscape')->save('public/img/uploads/' . $file['name'], 90);
         }
         URLify::add_chars(array('á' => '&aacute;', 'à' => '&agrave;', 'ä' => '&auml;', 'Á' => '&Aacute;', 'À' => '&Agrave;', 'â' => '&acirc;', 'Â' => '&Acirc;', 'ã' => '&atilde;', 'Ã' => '&Atilde;', 'Ä' => '&Auml;', 'Ç' => '&Ccedil;', 'ç' => '&ccedil;', 'é' => '&eacute;', 'É' => '&Eacute;', 'è' => '&egrave;', 'È' => '&Egrave;', 'ê' => '&ecirc;', 'Ê' => '&Ecirc;', 'ë' => '&euml;', 'Ë' => '&Euml;', 'ü' => '&uuml;', 'Ü' => '&Uuml;', 'û' => '&ucirc;', 'Û' => '&Ucirc;', 'ú' => '&uacute;', 'Ú' => '&Uacute;', 'ù' => '&ugrave;', 'Ù' => '&Ugrave;', 'ó' => '&oacute;', 'Ó' => '&Oacute;', 'ò' => '&ograve;', 'Ò' => '&Ograve;', 'ô' => '&ocirc;', 'Ô' => '&Ocirc;', 'ö' => '&ouml;', 'Ö' => '&Ouml;', 'ß' => '&szlig;', 'ÿ' => '&yuml;'));
         $marker = Marker::where('id', '=', $id)->first();
         $marker->name = URLify::downcode($input['name']);
         $marker->address = URLify::downcode($input['address']);
         $marker->lat = $input['lat'];
         $marker->lng = $input['lng'];
         $marker->type = $input['type'];
         $marker->user_id = Auth::user()->group == 2 ? Auth::user()->id : $input['client'];
         $marker->rem1 = URLify::downcode(Input::get('rem1', ''));
         $marker->rem2 = URLify::downcode(Input::get('rem2', ''));
         $marker->rem3 = URLify::downcode(Input::get('rem3', ''));
         $marker->rem4 = URLify::downcode(Input::get('rem4', ''));
         $marker->rem5 = URLify::downcode(Input::get('rem5', ''));
         if (!empty($file['name'])) {
             $marker->img_url = '/img/uploads/' . $file['name'];
         }
         $marker->save();
         return Redirect::to_action('home@edit_marker/' . $id)->with('message', 'Marker updated!');
     }
 }
 /**
  * Create a thumbnail of the uploaded image
  *
  * @param  string $filename Image filename
  * @return boolean
  */
 private function _createThumbnail($filename)
 {
     $img = Resizer::make('public/assets/products/' . $filename)->resize(80, 80, true);
     $img->save('public/assets/products/thumbnails/' . $filename);
 }
Exemplo n.º 13
0
 public function post_edit($id = false)
 {
     if (!$id) {
         return Redirect::to('drivers');
     }
     $input = Input::all();
     $files = Input::file('photo', false);
     //if($files) Input::upload('photo', path('public') . 'photo/', $files['name']);
     // Save a thumbnail
     if (is_array($files) && isset($files['error']) && $files['error'] == 0) {
         $success = Resizer::open($files)->resize(200, 200, 'auto')->save(path('public') . 'photo/' . str_replace(' ', '-', $input['nip']) . '.jpg', 90);
     }
     try {
         $driver = Driver::find($id);
         $driver->name = $input['name'];
         $driver->nip = $input['nip'];
         $driver->ktp = $input['ktp'];
         $driver->sim = $input['sim'];
         $driver->phone = $input['phone'];
         $driver->brith_place = $input['brith_place'];
         $driver->date_of_birth = $input['date_of_birth'];
         $driver->address = $input['address'];
         $driver->kelurahan = $input['kelurahan'];
         $driver->kecamatan = $input['kecamatan'];
         $driver->kota = $input['kota'];
         $driver->fg_blocked = Input::get('fg_blocked', 0);
         $driver->driver_status = Input::get('driver_status', 2);
         $driver->kpp_validthrough = $input['kpp_validthrough'];
         $driver->city_id = $input['city_id'];
         $driver->pool_id = $input['pool_id'];
         $driver->pool_id = $input['pool_id'];
         if ($files) {
             $driver->photo = str_replace(' ', '-', $input['nip']) . '.jpg';
         }
         $driver->save();
         return Redirect::to('drivers/edit/' . $id);
     } catch (Exception $e) {
     }
 }
Exemplo n.º 14
0
 /**
  * Generate a resized image (or pull from cache) and return the file name
  *
  * @param  Model   &$model
  * @param  string  $field
  * @param  string  $size
  * @param  bool    $use_cache
  * @return string
  */
 private static function generate(&$model, $field, $size, $use_cache = true)
 {
     $original_file = $model->get_attribute($field);
     // no image?
     if (!$original_file) {
         return null;
     }
     // did we ask for the original?
     if ($size == 'original') {
         return $original_file;
     }
     // we could pass an array instead of a size
     // in which case we are specifiying directory and format for that particular size
     // cast it all to an array and proceed accordingly
     if (!is_array($size)) {
         $size = array('size' => $size);
     }
     // get the directory, format, method, quality and dimensions
     $directory = array_get($size, 'storage_dir', static::config($model, 'storage_dir', $field));
     $format = array_get($size, 'thumbnail_format', static::config($model, 'thumbnail_format', $field));
     $method = array_get($size, 'resize_method', static::config($model, 'resize_method', $field));
     $quality = array_get($size, 'thumbnail_quality', static::config($model, 'thumbnail_quality', $field));
     $dimensions = array_get($size, 'size', null);
     if (!$dimensions) {
         throw new \Exception("Can not generate thumbnail for {$field}: no dimensions given.", 1);
     }
     if ($format == 'auto') {
         $format = File::extension($original_file);
     }
     $new_file = rtrim($original_file, File::extension($original_file)) . Str::lower($dimensions) . '.' . $format;
     // if we already have a cached copy, return it
     if ($use_cache && File::exists($directory . DS . $new_file)) {
         return $new_file;
     }
     if (!File::exists($directory . DS . $original_file)) {
         throw new \Exception("Can not generate {$dimensions} thumbnail for {$field}: no original.");
     }
     list($dst_width, $dst_height) = explode('x', Str::lower($dimensions));
     Bundle::register('resizer');
     Bundle::start('resizer');
     $success = Resizer::open($directory . DS . $original_file)->resize($dst_width, $dst_height, $method)->save($directory . DS . $new_file, $quality);
     if (!$success) {
         throw new \Exception("Could not generate thumbnail {$new_file}.");
     }
     return $new_file;
 }