- $imageUpload->move($storagePath, $storageName);
- // Create and save image object
- $this->image->name = $name;
- $this->image->url = $imagePath . $storageName;
- $this->image->created_by = auth()->user()->id;
- $this->image->updated_by = auth()->user()->id;
- $this->image->save();
- $this->loadSizes($this->image);
- return response()->json($this->image);
+
+ return response()->json($image);
+ }
+
+ /**
+ * Generate a sized thumbnail for an image.
+ * @param $id
+ * @param $width
+ * @param $height
+ * @param $crop
+ * @return \Illuminate\Http\JsonResponse
+ */
+ public function getThumbnail($id, $width, $height, $crop)
+ {
+ $this->checkPermission('image-create-all');
+ $image = $this->imageRepo->getById($id);
+ $thumbnailUrl = $this->imageRepo->getThumbnail($image, $width, $height, $crop == 'false');
+ return response()->json(['url' => $thumbnailUrl]);