Skip to content

Instantly share code, notes, and snippets.

@arif98741
Created September 18, 2022 17:18
Show Gist options
  • Save arif98741/0a2957b88631bff6f9e5f2893cb114eb to your computer and use it in GitHub Desktop.
Save arif98741/0a2957b88631bff6f9e5f2893cb114eb to your computer and use it in GitHub Desktop.
Store Image using S3
if (config('app.env') == 'production') {
$width = $thumbnail_values[1]->value;
$height = $thumbnail_values[0]->value;
$destinationPath = 'images/media/' . $directory . '/';
$thumbnailImage = Image::make($request->file('file'))->resize($width, $height)->stream();
$namethumbnail = $destinationPath . 'thumbnail' . time() . $filename;
Storage::disk('s3')->put($destinationPath . 'thumbnail' . time() . $filename, $thumbnailImage->__toString());
$Path = 'images/media/' . $directory . '/' . 'thumbnail' . time() . $filename;
} else {
$destinationPath = public_path('images/media/' . $directory . '/');
$thumbnailImage = Image::make($request->file('file'), array(
'width' => $thumbnail_values[1]->value,
'height' => $thumbnail_values[0]->value,
'grayscale' => false)
);
$namethumbnail = $thumbnailImage->save($destinationPath . 'thumbnail' . time() . $filename);
$Path = 'images/media/' . $directory . '/' . 'thumbnail' . time() . $filename;
$destinationFile = public_path($Path);
$size = getimagesize($destinationFile);
list($width, $height, $type, $attr) = $size;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment