Skip to content

Commit 7a7f283

Browse files
committed
Resizing image
1 parent 9da1398 commit 7a7f283

File tree

6 files changed

+46
-18
lines changed

6 files changed

+46
-18
lines changed

src/controllers/CropController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@ public function getCropimage()
5151
$thumb_img->fit(200, 200)
5252
->save(base_path() . "/" . Config::get('lfm.images_dir') . $dir . "/thumbs/" . basename($img));
5353
}
54-
}
54+
55+
}
Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
* Class ScaleController
1111
* @package Tsawler\Laravelfilemanager\controllers
1212
*/
13-
class ScaleController extends Controller {
13+
class ResizeController extends Controller {
1414

1515
/**
1616
* Dipsplay image for resizing
1717
*
1818
* @return mixed
1919
*/
20-
public function getScale()
20+
public function getResize()
2121
{
2222
$ratio = 1.0;
2323
$image = Input::get('img');
@@ -48,7 +48,7 @@ public function getScale()
4848
$scaled = true;
4949
}
5050

51-
return View::make('laravel-filemanager::scale')
51+
return View::make('laravel-filemanager::resize')
5252
->with('img', Config::get('lfm.images_url') . $dir . "/" . $image)
5353
->with('dir', $dir)
5454
->with('image', $image)
@@ -59,4 +59,27 @@ public function getScale()
5959
->with('scaled', $scaled)
6060
->with('ratio', $ratio);
6161
}
62+
63+
64+
public function performResize()
65+
{
66+
$img = Input::get('img');
67+
$dir = Input::get('dir');
68+
$dataX = Input::get('dataX');
69+
$dataY= Input::get('dataY');
70+
$height = Input::get('dataHeight');
71+
$width = Input::get('dataWidth');
72+
73+
try
74+
{
75+
Image::make(public_path() . $img)->resize($width, $height)->save();
76+
return "OK";
77+
} catch (Exception $e)
78+
{
79+
return "width : " . $width . " height: " . $height;
80+
return $e;
81+
}
82+
83+
}
84+
6285
}

src/routes.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
Route::get('/laravel-filemanager/rename', 'Tsawler\Laravelfilemanager\controllers\RenameController@getRename');
2929

3030
// scale/resize
31-
Route::get('/laravel-filemanager/scale', 'Tsawler\Laravelfilemanager\controllers\ScaleController@getScale');
31+
Route::get('/laravel-filemanager/resize', 'Tsawler\Laravelfilemanager\controllers\ResizeController@getResize');
32+
Route::get('/laravel-filemanager/doresize', 'Tsawler\Laravelfilemanager\controllers\ResizeController@performResize');
3233

3334
// download
3435
Route::get('/laravel-filemanager/download', 'Tsawler\Laravelfilemanager\controllers\DownloadController@getDownload');

src/views/images.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class="btn btn-default btn-xs">
5959
<li><a href="javascript:download('{!! basename($file) !!}')">Download</a></li>
6060
<li class="divider"></li>
6161
<li><a href="javascript:notImp()">Rotate</a></li>
62-
<li><a href="javascript:scaleImage('{!! basename($file) !!}')">Scale</a></li>
62+
<li><a href="javascript:resizeImage('{!! basename($file) !!}')">Resize</a></li>
6363
<li><a href="javascript:cropImage('{!! basename($file) !!}')">Crop</a></li>
6464
<li class="divider"></li>
6565
<li><a href="javascript:trash('{!! basename($file) !!}')">Delete</a></li>

src/views/index.blade.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class="fa fa-list"></i> List</a>
9999
{!! Form::label('file_to_upload', 'Choose File', array('class' => 'control-label')); !!}
100100
<div class="controls">
101101
<div class="input-group" style="width: 100%">
102-
<input type="file" name="file_to_upload">
102+
<input type="file" id="file_to_upload" name="file_to_upload">
103103
</div>
104104
</div>
105105
</div>
@@ -172,6 +172,7 @@ function showResponse(responseText, statusText, xhr, $form) {
172172
if (responseText != "OK"){
173173
notify(responseText);
174174
}
175+
$("#file_to_upload").val('');
175176
loadImages();
176177
}
177178
@@ -390,11 +391,11 @@ function notify(x) {
390391
bootbox.alert(x);
391392
}
392393
393-
function scaleImage(x) {
394+
function resizeImage(x) {
394395
$.ajax({
395396
type: "GET",
396397
dataType: "text",
397-
url: "/laravel-filemanager/scale",
398+
url: "/laravel-filemanager/resize",
398399
data: "img="
399400
+ x
400401
+ "&dir=" + $("#working_dir").val(),
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
</tbody>
4040
</table>
4141

42-
<button class="btn btn-primary" onclick="doScale()">Scale</button>
42+
<button class="btn btn-primary" onclick="doResize()">Resize</button>
4343
<button class="btn btn-info" onclick="loadImages()">Cancel</button>
4444

4545
<input type="hidden" name="ratio" value="{!! $ratio !!}"><br>
@@ -70,25 +70,27 @@
7070
});
7171
});
7272
73-
function performScale() {
73+
function doResize() {
7474
7575
$.ajax({
7676
type: "GET",
7777
dataType: "text",
78-
url: "/laravel-filemanager/cropimage",
78+
url: "/laravel-filemanager/doresize",
7979
data: {
80-
img: $("#img").val(),
80+
img: '{!! $img !!}',
8181
dir: $("#dir").val(),
8282
dataX: $("#dataX").val(),
8383
dataY: $("#dataY").val(),
84-
dataHeight: $("#dataHeight").val(),
85-
dataWidth: $("#dataWidth").val()
84+
dataHeight: $("#height").val(),
85+
dataWidth: $("#width").val()
8686
},
8787
cache: false
8888
}).done(function (data) {
89-
loadImages();
89+
if (data == "OK") {
90+
loadImages();
91+
} else {
92+
notify(data);
93+
}
9094
});
91-
92-
//$("#cropForm").submit();
9395
}
9496
</script>

0 commit comments

Comments
 (0)