/**
  *
  */
 public function postUpload()
 {
     $rules = ['file' => 'required|image|max:' . $this->imageSizeLimit];
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator->errors())->withInput();
     }
     DB::transaction(function () {
         $userImage = new UserImage();
         $userImage->user_id = Auth::id();
         $userImage->save();
         // resize
         $path = tempnam(storage_path('images'), 'image');
         $image = Image::make(Input::file('file'));
         $image->fit($this->imageWidth, $this->imageHeight);
         $image->save($path);
         /** @var \Aws\S3\S3Client $s3 */
         $s3 = AWS::get('s3');
         $s3->putObject(['Bucket' => $this->imageBucket, 'Key' => '/demo/' . $userImage->id . '.jpg', 'SourceFile' => $path]);
         $image->destroy();
         File::delete($path);
     });
     return Redirect::to('/');
 }
示例#2
0
 public static function getUserPersonalImage($user_id, $image_size = "small", $cache = true)
 {
     //if(isset(self::$u_image[$user_id]))
     //	return self::$u_image[$user_id];
     $image_exists = false;
     $image_details = array();
     $user_imageInfo = UserImage::whereRaw('user_id = ? ', array($user_id))->first();
     if (count($user_imageInfo) > 0) {
         $image_exists = true;
         $image_details["image_id"] = $user_imageInfo->image_id;
         $image_details["image_ext"] = $user_imageInfo->image_ext;
         $image_details["image_name"] = $user_imageInfo->image_name;
         $image_details["image_server_url"] = $user_imageInfo->image_server_url;
         $image_details["image_large_width"] = $user_imageInfo->large_width;
         $image_details["image_large_height"] = $user_imageInfo->large_height;
         $image_details["image_small_width"] = $user_imageInfo->small_width;
         $image_details["image_small_height"] = $user_imageInfo->small_height;
         $image_details["image_thumb_width"] = $user_imageInfo->thumb_width;
         $image_details["image_thumb_height"] = $user_imageInfo->thumb_height;
         $image_details["image_folder"] = Config::get("generalConfig.user_image_folder");
     }
     $image_path = "";
     $image_url = "";
     $image_attr = "";
     if ($image_exists) {
         $image_path = URL::asset(Config::get("generalConfig.user_image_folder")) . "/";
     }
     $cfg_user_img_large_width = Config::get("user_image_large_width");
     $cfg_user_img_large_height = Config::get("user_image_large_height");
     $cfg_user_img_thumb_width = Config::get("user_image_thumb_width");
     $cfg_user_img_thumb_height = Config::get("user_image_thumb_height");
     $cfg_user_img_small_width = Config::get("user_image_small_width");
     $cfg_user_img_small_height = Config::get("user_image_small_height");
     switch ($image_size) {
         case 'large':
             $image_url = URL::asset("packages/agriya/webshoppack/images/no_image") . '/userno-180.jpg';
             $image_attr = CUtil::TPL_DISP_IMAGE($cfg_user_img_large_width, $cfg_user_img_large_height, $cfg_user_img_large_width, $cfg_user_img_large_height);
             if ($image_exists) {
                 $image_url = $image_path . $image_details["image_name"] . "_L." . $image_details["image_ext"];
                 $image_attr = CUtil::TPL_DISP_IMAGE($cfg_user_img_large_width, $cfg_user_img_large_height, $image_details["image_large_width"], $image_details["image_large_height"]);
             }
             break;
         case "thumb":
             $image_url = URL::asset("packages/agriya/webshoppack/images/no_image") . '/userno-62.jpg';
             $image_attr = CUtil::TPL_DISP_IMAGE($cfg_user_img_thumb_width, $cfg_user_img_thumb_height, $cfg_user_img_thumb_width, $cfg_user_img_thumb_height);
             if ($image_exists) {
                 $image_url = $image_path . $image_details["image_name"] . "_T." . $image_details["image_ext"];
                 $image_attr = CUtil::TPL_DISP_IMAGE($cfg_user_img_thumb_width, $cfg_user_img_thumb_height, $image_details["image_thumb_width"], $image_details["image_thumb_height"]);
             }
             break;
         case "small":
             $image_url = URL::asset("packages/agriya/webshoppack/images/no_image") . '/userno-30.jpg';
             $image_attr = CUtil::TPL_DISP_IMAGE($cfg_user_img_small_width, $cfg_user_img_small_height, $cfg_user_img_small_width, $cfg_user_img_small_height);
             if ($image_exists) {
                 $image_url = $image_path . $image_details["image_name"] . "_S." . $image_details["image_ext"];
                 $image_attr = CUtil::TPL_DISP_IMAGE($cfg_user_img_small_width, $cfg_user_img_small_height, $image_details["image_small_width"], $image_details["image_small_height"]);
             }
             break;
         default:
             $image_url = URL::asset("packages/agriya/webshoppack/images/no_image") . '/userno-62.jpg';
             $image_attr = CUtil::TPL_DISP_IMAGE(52, 52, 62, 62);
             if ($image_exists) {
                 $image_url = $image_path . $image_details["image_name"] . "_T." . $image_details["image_ext"];
                 $image_attr = CUtil::TPL_DISP_IMAGE(52, 52, $image_details["image_thumb_width"], $image_details["image_thumb_height"]);
             }
     }
     $image_details['image_url'] = $image_url;
     $image_details['image_attr'] = $image_attr;
     self::$u_image[$user_id] = $image_details;
     return self::$u_image[$user_id];
 }
 public function uploadUserImage($file, $image_ext, $image_name, $destinationpath, $user_id = 0)
 {
     $config_path = Config::get('generalConfig.user_image_folder');
     $this->chkAndCreateFolder($config_path);
     $logged_user_id = $user_id;
     if (!$logged_user_id && isset(getAuthUser()->id)) {
         $logged_user_id = getAuthUser()->id;
     }
     // open file a image resource
     Image::make($file->getRealPath())->save(Config::get("generalConfig.user_image_folder") . $image_name . '_O.' . $image_ext);
     list($width, $height) = getimagesize($file);
     list($upload_img['width'], $upload_img['height']) = getimagesize(base_path() . '/public/' . $config_path . $image_name . '_O.' . $image_ext);
     $large_width = Config::get('generalConfig.user_image_large_width');
     $large_height = Config::get('generalConfig.user_image_large_height');
     if (isset($large_width) && isset($large_height)) {
         $img_size = CUtil::DISP_IMAGE($large_width, $large_height, $upload_img['width'], $upload_img['height'], true);
         Image::make($file->getRealPath())->resize($large_width, $large_height, true, false)->save($config_path . $image_name . '_L.' . $image_ext);
     }
     $small_width = Config::get("generalConfig.user_image_small_width");
     $small_height = Config::get("generalConfig.user_image_small_height");
     if (isset($small_width) && isset($small_height)) {
         $simg_size = CUtil::DISP_IMAGE($small_width, $small_height, $upload_img['width'], $upload_img['height'], true);
         Image::make($file->getRealPath())->resize($small_width, $small_height, true, false)->save($config_path . $image_name . '_S.' . $image_ext);
     }
     $thumb_width = Config::get("generalConfig.user_image_thumb_width");
     $thumb_height = Config::get("generalConfig.user_image_thumb_height");
     if (isset($thumb_width) && isset($thumb_height)) {
         $timg_size = CUtil::DISP_IMAGE($thumb_width, $thumb_height, $upload_img['width'], $upload_img['height'], true);
         Image::make($file->getRealPath())->resize($thumb_width, $thumb_height, true, false)->save($config_path . $image_name . '_T.' . $image_ext);
     }
     $img_path = Request::root() . '/' . $config_path;
     list($upload_input['small_width'], $upload_input['small_height']) = getimagesize($img_path . $image_name . '_S.' . $image_ext);
     list($upload_input['thumb_width'], $upload_input['thumb_height']) = getimagesize($img_path . $image_name . '_T.' . $image_ext);
     list($upload_input['large_width'], $upload_input['large_height']) = getimagesize($img_path . $image_name . '_L.' . $image_ext);
     $user_image = new UserImage();
     $user_data = array('image_ext' => $image_ext, 'image_name' => $image_name, 'image_server_url' => $destinationpath, 'large_height' => $upload_input['large_height'], 'large_width' => $upload_input['large_width'], 'small_width' => $upload_input['small_width'], 'small_height' => $upload_input['small_height'], 'thumb_width' => $upload_input['thumb_width'], 'thumb_height' => $upload_input['thumb_height']);
     $user_image_details = UserImage::where('user_id', $logged_user_id)->first();
     if (count($user_image_details) > 0) {
         $this->deleteImageFiles($user_image_details->image_name, $user_image_details->image_ext, $config_path);
         UserImage::where('user_id', $logged_user_id)->update($user_data);
         $id = $user_image_details->image_id;
     } else {
         $user_data['date_added'] = new DateTime();
         $user_data['user_id'] = $logged_user_id;
         $id = $user_image->insertGetId($user_data);
     }
     return $id;
 }
 protected function createUserImageSeeds()
 {
     UserImage::create(['user_id' => '1']);
     UserImage::create(['user_id' => '1']);
 }