Skip to content

Commit

Permalink
added wepb option
Browse files Browse the repository at this point in the history
  • Loading branch information
prodixx committed Feb 22, 2023
1 parent 0e32266 commit 4eabfe4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class ProductCrudController extends CrudController
'image_height' => 600,
'mimes' => 'image/*',
'max_file_size' => 5, // MB
'webp' => true, // (optional) also save webp version
'view_namespace' => 'prodixx.dropzone-field-for-backpack::fields',
'thumb_prefix' => '',
// 'hint' => 'Some info', // (optional) some text that is shown under the field
Expand Down Expand Up @@ -89,6 +90,7 @@ cp -i vendor/prodixx/dropzone-field-for-backpack/src/resources/views/fields/drop
'image_height' => 600,
'mimes' => 'image/*',
'max_file_size' => 5, // MB
'webp' => true,
- 'view_namespace' => 'prodixx.dropzone-field-for-backpack::fields'
'thumb_prefix' => '',
// 'hint' => 'Some info', // (optional) some text that is shown under the field
Expand Down
1 change: 1 addition & 0 deletions resources/views/fields/dropzone.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
slug : "{{ $crud->entry->slug ?? '' }}",
image_width : "{{ $field['image_width'] ?? 500 }}",
image_height : "{{ $field['image_height'] ?? 500 }}",
webp : "{{ $field['webp'] ?? false }}",
entry : "{{ $crud->entry->id }}"
},
url: "{{ route( Str::lower(str_replace(config('backpack.base.route_prefix').'/', '', $crud->route)) . '.dropzone-add') }}",
Expand Down
11 changes: 9 additions & 2 deletions src/Traits/DropzoneTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,15 @@ public function dropzoneUpload(DropzoneRequest $request)

$big_image = \Image::make($image)->fit($request->image_width, $request->image_height, function ($constraint) {
$constraint->upsize();
})->stream();
});

\Storage::disk($request->disk)->put($file_path, $big_image->__toString());
\Storage::disk($request->disk)->put($file_path, (string) $big_image->stream());

if ($request->webp) {
$webp_file_path = $request->destination_path . '/' . $request->entry . '/' . pathinfo($filename, PATHINFO_FILENAME) . '.webp';

\Storage::disk($request->disk)->put($webp_file_path, (string) $big_image->encode('webp', 70)->stream());
}

return response()->json([
'success' => true,
Expand All @@ -64,6 +70,7 @@ public function dropzoneDelete(Request $request)

\Storage::disk($request->disk)->delete([
$request->destination_path . '/' . $request->entry . '/' . $request->image_path,
$request->destination_path . '/' . $request->entry . '/' . pathinfo($request->image_path, PATHINFO_FILENAME) . '.webp',
]);

return response()->json(['success' => true]);
Expand Down

0 comments on commit 4eabfe4

Please sign in to comment.