Esempio n. 1
0
 public function setImagenAttribute($imagen)
 {
     if (!empty($imagen)) {
         $this->attributes['imagen'] = \Carbon::now()->second . $imagen->getClientOriginalName();
         $filename = \Carbon::now()->second . $imagen->getClientOriginalName();
         \Storage::disk('local')->put($filename, \File::get($imagen));
         $thumb = \Image::make(\File::get($imagen));
         $ruta = public_path() . '/uploads/noticias/thumbs/';
         $thumb->resize(160, 100);
         $thumb->save($ruta . 'thumb_' . $filename);
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $photo = Request::file('image');
     $notes = Request::input('notes');
     $image = new App\Image();
     $image->make($photo, $notes);
     $image->name = $image->getName();
     $image->latitude = $image->getLatitude();
     $image->longitude = $image->getLongitude();
     $image->date = $image->getDate();
     $image->time = $image->getTime();
     $image->notes = $notes;
     $image->created_at = Carbon::now();
     $image->updated_at = Carbon::now();
     $image->save();
     return redirect()->action('AlleyController@create');
 }
Esempio n. 3
0
 public function setProfileImage($image)
 {
     $img = \Image::make($image);
     // resize image
     $img->fit(600, 600);
     // save image
     $path = 'public/assets/images/profiles/' . $user->id . $user->name . '.jpg';
     $img->save($path);
     return $path;
 }
Esempio n. 4
0
 public function resizeImage($filename, $maxWidth = 1024, $quality = 90)
 {
     $img = \Image::make($filename);
     if ($img->width() > $maxWidth) {
         $img->resize($maxWidth, null, function ($constraint) {
             $constraint->aspectRatio();
         });
         $img->save($filename, $quality);
     }
 }
Esempio n. 5
0
 public static function storeCMPicture($img_url)
 {
     // post save
     $post = \App\Post::create(array('user_id' => \Auth::user()->id, 'content' => ''));
     $post->postGroups()->attach(\Auth::user()->postGroups()->first()->id);
     // photo save
     $types = array('_s.', '_m.', '_l.');
     $sizes = array(100, 300, 600);
     $original_file_name = $img_url;
     $file_ext = 'jpg';
     $target_path = base_path() . '/public/imgs/';
     $hashSeed = "post" . $post->id . $original_file_name;
     while (1) {
         $file_name = \Func::getHashedValue($hashSeed);
         if (!\File::exists($target_path . \Func::getImgPath($file_name))) {
             break;
         }
         $hashSeed .= rand();
     }
     $target_path .= \Func::getImgPath($file_name) . '/';
     if (!\File::exists($target_path)) {
         \File::makeDirectory($target_path, 0775, true);
     }
     foreach ($types as $key => $type) {
         $new_name = $file_name . $type . $file_ext;
         $img = \Image::make($img_url);
         $img->resize($sizes[$key], null, function ($constraint) {
             $constraint->aspectRatio();
             $constraint->upsize();
         })->save($target_path . $new_name);
         $img->destroy();
     }
     \App\Photo::create(array('post_id' => $post->id, 'sequence' => 1, 'img_path' => $file_name . '.' . $file_ext));
 }
Esempio n. 6
0
 protected function makeThumbnail()
 {
     Image::make($this->filePath())->fit(200)->save($this->thumbnailPath());
 }
Esempio n. 7
0
 public function uploadFiles($idFr, $img_profile)
 {
     $fileSystem = new Filesystem();
     $countProfileImg = count($img_profile);
     //creo la extructura de carpetas para el doctor
     //for profile_img
     if (!empty($img_profile)) {
         $destinationPath = public_path() . "/upload/flores_regalos/{$idFr}/";
         $file = str_replace('data:image/png;base64,', '', $img_profile);
         $img = str_replace(' ', '+', $file);
         $data = base64_decode($img);
         $filename = date('ymdhis') . '_croppedImage' . ".png";
         $file = $destinationPath . $filename;
         $success = file_put_contents($file, $data);
         // THEN RESIZE IT
         $returnData = "upload/flores_regalos/{$idFr}/" . $filename;
         $image = Image::make(file_get_contents(URL::asset($returnData)));
         $image = $image->resize(300, 300)->save($destinationPath . $filename);
         if (!$success) {
             return false;
         }
     } else {
         $filename = "";
     }
     return array('img_profile_name' => $filename);
 }
Esempio n. 8
0
 /**
  * Create record based on input and save untouched file in storage/images
  * @param UploadedFile $file
  * @return static
  * @throws Exception
  */
 public static function createFromInput(UploadedFile $file)
 {
     if (!in_array($file->getMimeType(), static::$allowedMimes)) {
         throw new Exception("Invalid mime type");
     }
     $newFileName = static::count() . md5(str_random());
     $newExtension = $file->guessExtension();
     $img = ImageLib::make($file)->save(storage_path('images') . DIRECTORY_SEPARATOR . $newFileName . '.' . $newExtension);
     try {
         $dbImage = new Image(['original' => $file->getClientOriginalName(), 'hash' => $newFileName, 'extension' => $newExtension, 'width' => $img->width(), 'height' => $img->height()]);
         $dbImage->save();
     } catch (\Exception $ex) {
         dd($ex);
     }
     return $dbImage;
 }