@@ -24,18 +24,15 @@ public function getCrop()
2424
2525 /**
2626 * Crop the image (called via ajax).
27+ *
28+ * @param bool $overWrite
2729 */
2830 public function getCropimage ($ overWrite = true )
2931 {
3032 $ image_name = request ('img ' );
33+ $ target_name = $ image_name ;
3134 $ image_path = $ this ->lfm ->setName ($ image_name )->path ('absolute ' );
3235
33- if (! $ overWrite ) {
34- $ fileParts = explode ('. ' , $ image_name );
35- $ fileParts [count ($ fileParts ) - 2 ] = $ fileParts [count ($ fileParts ) - 2 ] . '_cropped_ ' . time ();
36- $ crop_name = implode ('. ' , $ fileParts );
37- }
38-
3936 event (new ImageIsCropping ($ image_path ));
4037
4138 $ crop_info = request ()->only ('dataWidth ' , 'dataHeight ' , 'dataX ' , 'dataY ' );
@@ -46,19 +43,24 @@ public function getCropimage($overWrite = true)
4643 ->stream ()
4744 ->detach ();
4845
49- if (! $ overWrite ) {
50- $ this ->lfm ->setName ($ crop_name )->storage ->put ($ croppedImage );
51- // make new thumbnail
52- $ this ->lfm ->makeThumbnail ($ crop_name );
53- } else {
54- $ this ->lfm ->setName ($ image_name )->storage ->put ($ croppedImage );
55- // make new thumbnail
56- $ this ->lfm ->makeThumbnail ($ image_name );
46+ // Overwrite
47+ if (!$ overWrite ) {
48+ $ fileParts = explode ('. ' , $ image_name );
49+ $ fileParts [count ($ fileParts ) - 2 ] = $ fileParts [count ($ fileParts ) - 2 ] . '_cropped_ ' . time ();
50+ $ target_name = implode ('. ' , $ fileParts );
5751 }
5852
53+ // Replace or create new image
54+ $ this ->lfm ->setName ($ target_name )->storage ->put ($ croppedImage , 'public ' );
55+ // make new thumbnail
56+ $ this ->lfm ->makeThumbnail ($ target_name );
57+
5958 event (new ImageWasCropped ($ image_path ));
6059 }
6160
61+ /**
62+ * Crop the image (called via ajax).
63+ */
6264 public function getNewCropimage ()
6365 {
6466 $ this ->getCropimage (false );
0 commit comments