Example #1
0
 public function images(Shop $shop, Product $product, Request $request)
 {
     $user = Auth::user();
     $this->validate($request, ['inputImage' => 'required | image']);
     $file = $request->file('inputImage');
     $data = $request->input('cropper_json');
     $data = json_decode(stripslashes($data));
     $imageName = $shop->id . str_random(20) . '.' . $file->getClientOriginalExtension();
     $file->move(public_path() . '/img/files/shop/' . $shop->id . '/', $imageName);
     $real_name = $file->getClientOriginalName();
     $size = $file->getClientSize() / (1024 * 1024);
     //calculate the file size in MB
     $src = public_path() . '/img/files/shop/' . $shop->id . '/' . $imageName;
     //        $imageName = $this->addImage($file, $shop, $product);
     $img = Image::make($src);
     $img->rotate($data->rotate);
     $img->crop(intval($data->width), intval($data->height), intval($data->x), intval($data->y));
     $img->resize(400, 400);
     $img->save($src, 90);
     $product->files()->create(['user_id' => $user->id, 'real_name' => $real_name, 'name' => $shop->id . '/' . $imageName, 'size' => $size]);
     $user->usage->add(filesize(public_path() . '/img/files/shop/' . $shop->id . '/' . $imageName) / (1024 * 1024));
     // storage add
     return redirect()->back();
 }