+ /**
+ * Read the image file data for a single image in the system.
+ * The returned response will be a stream of image data instead of a JSON response.
+ */
+ public function readData(string $id)
+ {
+ $image = Image::query()->scopes(['visible'])->findOrFail($id);
+
+ return $this->imageService->streamImageFromStorageResponse('gallery', $image->path);
+ }
+
+ /**
+ * Read the image file data for a single image in the system, using the provided URL
+ * to identify the image instead of its ID, which is provided as a "URL" query parameter.
+ * The returned response will be a stream of image data instead of a JSON response.
+ */
+ public function readDataForUrl(Request $request)
+ {
+ $data = $this->validate($request, $this->rules()['readDataForUrl']);
+ $basePath = url('/uploads/images/');
+ $imagePath = str_replace($basePath, '', $data['url']);
+
+ if (!$this->imageService->pathAccessible($imagePath)) {
+ throw (new NotFoundException(trans('errors.image_not_found')))
+ ->setSubtitle(trans('errors.image_not_found_subtitle'))
+ ->setDetails(trans('errors.image_not_found_details'));
+ }
+
+ return $this->imageService->streamImageFromStorageResponse('gallery', $imagePath);
+ }
+