Created
February 11, 2016 16:38
-
-
Save rubemlrm/62f367b86619e2f8ee66 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static function saveImage($file,$height = null, $width = "400"){ | |
| if ($file) { | |
| $destinationPath = public_path() . '/uploads/images/'; | |
| $ext = $file->getClientOriginalExtension(); // Get real extension according to mime type | |
| $fullname = $file->getClientOriginalName(); // Client file name, including the extension of the client | |
| $hashname = md5($fullname . time()) . '.' .$ext; // Hash processed file name, including the real extension | |
| $uploadSuccess = $file->move($destinationPath, $hashname); | |
| $imagePath = $destinationPath . $hashname; | |
| $img = \Image::make($imagePath); | |
| $img->resize($height, $width, function ($constraint) { | |
| $constraint->aspectRatio(); | |
| }); | |
| $thumbPath = public_path() . '/uploads/images/bin_' . $hashname; | |
| try { | |
| $img->save($thumbPath); | |
| } catch (\Intervention\Image\Exception\NotWritableException $e) { | |
| $this->logger->writeLog("error", "user " . $this->userRepository->getCurrentUserName() . " tried upload image <b>" . $thumbPath . "</b> and got the following error <code>". $e . "</code> ", "settings"); | |
| return back()->withInput()->withErrors(['errors'=>'Ocorreu um erro ao enviar a imagem relativa ao twittercard']); | |
| } | |
| return $hashname; | |
| } | |
| return null; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment