當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Image::save方法代碼示例

本文整理匯總了PHP中app\Image::save方法的典型用法代碼示例。如果您正苦於以下問題:PHP Image::save方法的具體用法?PHP Image::save怎麽用?PHP Image::save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\Image的用法示例。


在下文中一共展示了Image::save方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $files = Input::file('images');
     $input = $request->all();
     $rules = array('file' => 'image|max:3000');
     $validator = Validator::make($files, $rules);
     if ($validator->fails()) {
         Session::flash('flash_message', 'Ошибка записи файлов!');
         return redirect()->back();
     } else {
         $destinationPath = 'uploads/images/';
         foreach ($files as $key => $file) {
             $filename[$key] = str_random(15) . '_' . substr($file->getClientOriginalName(), 0, strpos($file->getClientOriginalName(), ".")) . '.' . $file->getClientOriginalExtension();
             $upload_success = $file->move($destinationPath, $filename[$key]);
         }
     }
     foreach ($filename as $fname) {
         $image = new Image();
         $image->prod_id = $input['prod_id'];
         $image->path = $destinationPath . $fname;
         $image->save();
     }
     Session::flash('flash_message', 'Картинки успешно добавлены!');
     return redirect()->back();
 }
開發者ID:vitaloldos,項目名稱:shop,代碼行數:31,代碼來源:ImagesController.php

示例2: addImage

 public static function addImage($product_id, $image)
 {
     $data = new Image();
     $data->product_id = $product_id;
     $data->path = $image;
     $data->save();
 }
開發者ID:nhunght,項目名稱:mork_SmartOSC,代碼行數:7,代碼來源:Image.php

示例3: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     //
     // Validation //
     /*
           $validation = Validator::make($request->all(), [
              'caption'     => 'required|regex:/^[A-Za-z ]+$/',
              'userfile'     => 'required|image|mimes:jpeg,png|min:1|max:250'
           ]);
     
           // Check if it fails //
           if( $validation->fails() ){
              return redirect()->back()->withInput()
                               ->with('errors', $validation->errors() );
           }
     */
     $image = new Image();
     // upload the image //
     $file = $request->file('userfile');
     $destination_path = 'uploads/';
     $filename = str_random(6) . '_' . $file->getClientOriginalName();
     $file->move($destination_path, $filename);
     // save image data into database //
     $image->file = $destination_path . $filename;
     $image->caption = $request->input('nome');
     //$image->description = $request->input('description');
     $image->produto_id = $request->input('produto_id');
     $image->isexist = "true";
     $image->save();
     return redirect('/')->with('message', 'You just uploaded an image!');
 }
開發者ID:tedyivan,項目名稱:cultura,代碼行數:36,代碼來源:ImageController.php

示例4: UploadImage

 public static function UploadImage($oriFilePath, $fileName, User $user, $diskName = null)
 {
     $fs = Storage::disk($diskName);
     $fileContent = $fs->get($oriFilePath);
     $mimeType = $fs->mimeType($oriFilePath);
     if (!str_is('image/*', $mimeType)) {
         $fs->delete($oriFilePath);
         throw new RequestValidationException(RequestValidationException::FileIsNotImage);
     }
     $fileModel = self::saveFileByFileContent($fileContent, $fileName, $mimeType, $user, $diskName);
     $fs->delete($oriFilePath);
     $image = Image::make($fileContent);
     $thumbnail = Image::make($fileContent)->widen(300)->encode($fileModel->mime);
     $thumbnailFileModel = FileManager::saveFileByFileContent($thumbnail->encoded, $fileModel->name . '-thumbnail.' . $fileModel->ext, $thumbnail->mime(), $user);
     if ($image->getWidth() > 1500) {
         $highResolution = Image::make($fileContent)->widen(1500)->encode($fileModel->mime);
         $highResolutionFileModel = FileManager::saveFileByFileContent($highResolution->encoded, $fileModel->name . '-high-resolution.' . $fileModel->ext, $highResolution->mime(), $user);
     } else {
         $highResolution = Image::make($fileContent)->widen($image->getWidth())->encode($fileModel->mime);
         $highResolutionFileModel = FileManager::saveFileByFileContent($highResolution->encoded, $fileModel->name . '-high-resolution.' . $fileModel->ext, $highResolution->mime(), $user);
     }
     $imageModel = new ImageModel();
     $imageModel->width = $image->getWidth();
     $imageModel->height = $image->getHeight();
     $imageModel->file()->associate($fileModel);
     $imageModel->thumbnailFile()->associate($thumbnailFileModel);
     $imageModel->highResolutionFile()->associate($highResolutionFileModel);
     $imageModel->save();
     return $imageModel;
 }
開發者ID:lialosiu,項目名稱:amaoto-core,代碼行數:30,代碼來源:FileManager.php

示例5: store

 /**
  * Store a newly created resource in storage.
  *
  * @param Request $request
  *
  * @return Response
  */
 public function store(Request $request)
 {
     try {
         if (!$request->hasFile('photo')) {
             return $this->respondWithError('No photo is selected');
         }
         $file = $request->file('photo');
         // Create Eloquent object
         $image = new Image();
         $image->point_id = $request->id;
         $image->filename = $this->generate_random_string();
         $image->mime_type = $file->getClientMimeType();
         $image->base_64 = $this->convert_to_base_64($file);
         $image->created_by = Auth::user()->id;
         $image->updated_by = Auth::user()->id;
         if (!$image->save()) {
             // If creation fails
             // Return error response
             return $this->respondInternalError();
         }
         // Select latest row from DB
         $resp = $image->orderBy('id', 'DESC')->first();
         // return with Fractal
         return Fractal::item($resp, new \App\Transformers\ImageTransformer())->responseJson(200);
     } catch (Exception $e) {
         return $this->respondInternalError();
     }
 }
開發者ID:arelstone,項目名稱:Gps-RESTfull,代碼行數:35,代碼來源:ImageController.php

示例6: store

 /**
  * Store a newly uploaded resource in storage.
  *
  * @return Response
  */
 public function store(ImageRequest $request)
 {
     $input = $request->all();
     if (Auth::user()->image != null) {
         $image = Auth::user()->image;
         $file = Input::file('image');
         $name = time() . '-' . $file->getClientOriginalName();
         $image->filePath = $name;
         $file->move(public_path() . '/images/', $name);
     } else {
         // Store records process
         $image = new Image();
         $this->validate($request, ['title' => 'required', 'image' => 'required']);
         $image->title = $request->title;
         $image->description = $request->description;
         $image->user_id = Auth::user()->id;
         if ($request->hasFile('image')) {
             $file = Input::file('image');
             $name = time() . '-' . $file->getClientOriginalName();
             $image->filePath = $name;
             $file->move(public_path() . '/images/', $name);
         }
     }
     $image->save();
     $user = Auth::user();
     return redirect('/' . $user->username);
 }
開發者ID:jdeugarte,項目名稱:twitter,代碼行數:32,代碼來源:ImageController.php

示例7: makeImage

 protected function makeImage($file, $height, $width, $randomFilename, $thumbnail = null)
 {
     $md5 = md5_file($file->getRealPath());
     $img = Image::make($file)->fit($height, $width);
     $path = 'images/';
     if ($thumbnail != null) {
         $path = 'images/thumb/';
     }
     $image = Images::where('md5_hash', $md5)->first();
     if ($image === null or $image->thumbnail_file == null) {
         Clockwork::info('Storing on Filesystem');
         $img->save(storage_path() . '/app/' . $path . $randomFilename . '.png', 90);
     }
     if ($image === null and $thumbnail === null) {
         Clockwork::info('New Image');
         $image = new Images();
         $image->user_id = Auth::user()->id;
         $image->filename = $file->getClientOriginalName();
         $image->file = $randomFilename . '.png';
         $image->height = $height;
         $image->width = $width;
         $image->md5_hash = $md5;
     } elseif ($thumbnail != null and $image->thumbnail_file == null) {
         Clockwork::info('Thumbnail Updated');
         $image->thumbnail_file = $randomFilename . '.png';
     }
     $image->save();
     return $image;
 }
開發者ID:becast,項目名稱:GameReviewSite,代碼行數:29,代碼來源:ImageController.php

示例8: store

 /**
  * Store a newly created resource in storage.
  *
  * @param integer $item_id
  * @param ImageFormRequest $request
  *
  * @return Response
  */
 public function store($item_id, ImageFormRequest $request)
 {
     $imageName = uniqid('img') . '.' . $request->file('image')->getClientOriginalExtension();
     $image = new Image(['item_id' => $item_id, 'image' => $imageName]);
     $image->save();
     $request->file('image')->move(base_path() . '/public/img/catalog/', $imageName);
     return redirect()->route('items.images.create', ['items' => $item_id])->with('status', 'Your image has been uploaded!');
 }
開發者ID:recchia,項目名稱:items,代碼行數:16,代碼來源:ImagesController.php

示例9: storeImage

 public function storeImage($userID, $imageName, $imagePath)
 {
     $storeImg = new Image();
     $storeImg->userID = $userID;
     $storeImg->imageName = $imageName;
     $storeImg->imagePath = $imagePath;
     $storeImg->save();
 }
開發者ID:deferdie,項目名稱:tweet,代碼行數:8,代碼來源:Image.php

示例10: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request, Redirector $redirect)
 {
     $rules = ['name' => 'required', 'path' => 'required'];
     $this->validate($request, $rules);
     //if($id != null)
     //  $image = Image::findOrFail($id);
     //else
     $image = new Image();
     $image->name = $request->input('name');
     $image->save();
     $path = 'imgs/' . $image->id . '.' . $request->file('path')->getClientOriginalExtension();
     $image->path = $path;
     $image->save();
     Storage::disk('public')->put($path, file_get_contents($request->file('path')->getRealPath()));
     return $redirect->route("imagenes.index");
     //Storage::put('file.jpg',$request);
 }
開發者ID:serranozafra,項目名稱:subirImagenes,代碼行數:23,代碼來源:ImageController.php

示例11: create

 public function create(UploadedFile $file, User $user)
 {
     $filename = sha1(rand(11111, 99999));
     $extension = $file->getClientOriginalExtension();
     Storage::put('images/' . $filename . '.' . $extension, file_get_contents($file->getRealPath()));
     $image = new Image(['user_id' => $user->id, 'filename' => $file->getClientOriginalName(), 'path' => $filename . '.' . $extension, 'mime_type' => $file->getMimeType(), 'location' => 'local', 'status' => Image::STATUS_PENDING]);
     $image->save();
     return $image;
 }
開發者ID:phpfour,項目名稱:bangla-ocr,代碼行數:9,代碼來源:ImageRepository.php

示例12: saveImagable

 public function saveImagable()
 {
     $imageable = new Image();
     $imageable->path = $this->getPathWithFile();
     $imageable->imageable_id = $this->model_id;
     $imageable->imageable_type = $this->model_class_path;
     $imageable->r_id = $this->r_id;
     $imageable->save();
     return $imageable;
 }
開發者ID:boybin,項目名稱:n4backend,代碼行數:10,代碼來源:ImageController.php

示例13: addData

 /**
  * Helper untuk melakukan Add new Data ke dalam database
  * 
  */
 private function addData()
 {
     $data = new Image();
     $file = Input::file('gallery');
     $image_name = time() . "-gallery-" . $file->getClientOriginalName();
     $file->move(public_path() . '/upload', $image_name);
     $data->image = $image_name;
     $data->save();
     return true;
 }
開發者ID:semmiverian,項目名稱:webJok,代碼行數:14,代碼來源:aboutController.php

示例14: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['title' => 'required', 'file' => 'required', 'caption' => 'required']);
     $image = new Image($request->except('file'));
     $request->file('file')->move(public_path('uploads/gallery'), $request->file('file')->getClientOriginalName());
     $image->file = $request->file('file')->getClientOriginalName();
     $image->save();
     flash()->success('Gambar telah ditambahkan!');
     return redirect('/dashboard/images');
 }
開發者ID:kobeuu,項目名稱:bpb-sf,代碼行數:15,代碼來源:ImagesController.php

示例15: newPicture

 public function newPicture($fileName, $image)
 {
     $path = public_path('/images/gallery/');
     File::exists($path) or File::makeDirectory($path, 0755, true);
     $image->resize(200, 200)->save($path . $fileName);
     $picture = new Image();
     $picture->user = Auth::user()->name;
     $picture->caption = Input::get('caption');
     $picture->imagePath = 'images/gallery/' . $fileName;
     $picture->save();
 }
開發者ID:mathewsandi,項目名稱:Sezgi,代碼行數:11,代碼來源:DbGalleryRepository.php


注:本文中的app\Image::save方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。