質問編集履歴
3
不要な<script>タグを削除しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -18,6 +18,8 @@
|
|
18
18
|
成功させるためにはどうしたらいいのかご教授くださいm(_ _)m
|
19
19
|
|
20
20
|
また、リサイズした画像をphpで表示する方法も教えて頂きたいです。
|
21
|
+
|
22
|
+
|
21
23
|
(他 .map ファイル4種)
|
22
24
|
bootstrap.css bootstrap.min.css
|
23
25
|
bootstrap-theme.css bootstrap-theme.min.css
|
@@ -104,7 +106,7 @@
|
|
104
106
|
```
|
105
107
|
```javascript
|
106
108
|
// app/routes.php
|
107
|
-
|
109
|
+
|
108
110
|
use Illuminate\Http\Request;
|
109
111
|
use Intervention\Image\ImageManagerStatic as Image;
|
110
112
|
|
@@ -142,5 +144,5 @@
|
|
142
144
|
: ['response' => false];
|
143
145
|
|
144
146
|
});
|
145
|
-
|
147
|
+
|
146
148
|
```
|
2
ファイル構成を追加しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -18,11 +18,21 @@
|
|
18
18
|
成功させるためにはどうしたらいいのかご教授くださいm(_ _)m
|
19
19
|
|
20
20
|
また、リサイズした画像をphpで表示する方法も教えて頂きたいです。
|
21
|
+
(他 .map ファイル4種)
|
22
|
+
bootstrap.css bootstrap.min.css
|
23
|
+
bootstrap-theme.css bootstrap-theme.min.css
|
24
|
+
----css{ bootstrap.js bootstrap.min.js npm.js
|
25
|
+
フォルダ構成 |
|
26
|
+
boot_test -------js { bootstrap.js bootstrap.min.js npm.js
|
27
|
+
|
|
28
|
+
----img
|
29
|
+
|
|
30
|
+
---app { routes.php
|
31
|
+
|
|
32
|
+
----fonts
|
21
33
|
|
22
|
-
|
23
|
-
|
34
|
+
```html
|
24
|
-
|
25
|
-
|
35
|
+
<!-- boot_test/index.html -->
|
26
36
|
<!DOCTYPE html>
|
27
37
|
<html lang="en">
|
28
38
|
<head>
|
@@ -92,8 +102,8 @@
|
|
92
102
|
</html>
|
93
103
|
|
94
104
|
```
|
105
|
+
```javascript
|
95
|
-
|
106
|
+
// app/routes.php
|
96
|
-
//
|
97
107
|
<script>
|
98
108
|
use Illuminate\Http\Request;
|
99
109
|
use Intervention\Image\ImageManagerStatic as Image;
|
1
ほぼ丸写しですが、コードを追加しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -17,4 +17,120 @@
|
|
17
17
|
ボタンアクションの中にアラートを入れてみると反応はあったので、最後の処理が失敗しているため反応がないのではと思うのですが…
|
18
18
|
成功させるためにはどうしたらいいのかご教授くださいm(_ _)m
|
19
19
|
|
20
|
-
また、リサイズした画像をphpで表示する方法も教えて頂きたいです。
|
20
|
+
また、リサイズした画像をphpで表示する方法も教えて頂きたいです。
|
21
|
+
|
22
|
+
|
23
|
+
※追加
|
24
|
+
|
25
|
+
```boot_test/index.html
|
26
|
+
<!DOCTYPE html>
|
27
|
+
<html lang="en">
|
28
|
+
<head>
|
29
|
+
<meta charset="utf-8">
|
30
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
31
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
32
|
+
<title>Bootstrap 101 Template</title>
|
33
|
+
<!-- Bootstrap -->
|
34
|
+
<link href="css/bootstrap.min.css" rel="stylesheet">
|
35
|
+
<!-- CSS -->
|
36
|
+
<link href="https://cdnjs.cloudflare.com/ajax/libs/cropper/1.0.0/cropper.min.css" rel="stylesheet" type="text/css" media="all"/>
|
37
|
+
<!-- JS -->
|
38
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
|
39
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/cropper/1.0.0/cropper.min.js"></script>
|
40
|
+
<!--[if lt IE 9]>
|
41
|
+
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
|
42
|
+
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
43
|
+
<![endif]-->
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
<h3><i class="fa fa-crop"></i> cropperのデモ </h3>
|
47
|
+
<!-- 切り抜きボタン -->
|
48
|
+
<a id="getData" class="btn btn-primary">Get Data</a><br><br>
|
49
|
+
|
50
|
+
<div class="cropper-example-1">
|
51
|
+
<!-- bladeテンプレートを使用していれば asset()や url() 関数が使えます -->
|
52
|
+
<img id="img" class="img-responsive" src="./img/art.jpg" alt="">
|
53
|
+
</div>
|
54
|
+
|
55
|
+
<script type="text/javascript">
|
56
|
+
// init
|
57
|
+
// class='cropper-example-1のimgタグに適用'
|
58
|
+
var $image = $('.cropper-example-1 > img'),replaced;
|
59
|
+
|
60
|
+
//crop options
|
61
|
+
// id='imgに適用'
|
62
|
+
$('#img').cropper({
|
63
|
+
aspectRatio: 4 / 4 // ここでアスペクト比の調整 ワイド画面にしたい場合は 16 / 9
|
64
|
+
});
|
65
|
+
|
66
|
+
$('#getData').on('click', function(){
|
67
|
+
alert('こんにちは!');
|
68
|
+
// crop のデータを取得
|
69
|
+
var data = $('#img').cropper('getData');
|
70
|
+
// 切り抜きした画像のデータ
|
71
|
+
// このデータを元にして画像の切り抜きが行われます
|
72
|
+
var image = {
|
73
|
+
width: Math.round(data.width),
|
74
|
+
height: Math.round(data.height),
|
75
|
+
x: Math.round(data.x),
|
76
|
+
y: Math.round(data.y),
|
77
|
+
_token: 'jf89ajtr234534829057835wjLA-SF_d8Z' // csrf用
|
78
|
+
};
|
79
|
+
// post 処理
|
80
|
+
$.post('/cropper', image, function(res){
|
81
|
+
// 成功すれば trueと表示されます
|
82
|
+
console.log(res);
|
83
|
+
});
|
84
|
+
});
|
85
|
+
|
86
|
+
</script>
|
87
|
+
|
88
|
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
|
89
|
+
<script src="js/bootstrap.min.js"></script>
|
90
|
+
|
91
|
+
</body>
|
92
|
+
</html>
|
93
|
+
|
94
|
+
```
|
95
|
+
```app/routes.php
|
96
|
+
//
|
97
|
+
<script>
|
98
|
+
use Illuminate\Http\Request;
|
99
|
+
use Intervention\Image\ImageManagerStatic as Image;
|
100
|
+
|
101
|
+
$app->post('/cropper', function(Request $request){
|
102
|
+
|
103
|
+
$str = str_random(7);
|
104
|
+
|
105
|
+
$crop = value(function() use ($request, $str) {
|
106
|
+
|
107
|
+
// Laravelの場合は public_path()ヘルパー関数、Facadeが使えます
|
108
|
+
$image = Image::make('../public/img/art.jpg')
|
109
|
+
->crop(
|
110
|
+
$request->get('width'),
|
111
|
+
$request->get('height'),
|
112
|
+
$request->get('x'),
|
113
|
+
$request->get('y')
|
114
|
+
)
|
115
|
+
->resize(256,256) // 256 * 256にリサイズ
|
116
|
+
// 画像の保存
|
117
|
+
->save('../public/img/'. $str . '.jpg')
|
118
|
+
->resize(128,128) //サムネイル用にリサイズ
|
119
|
+
->save('../public/img/'. $str . '_t' . '.jpg');
|
120
|
+
|
121
|
+
// 必要があれば元のファイルも消す
|
122
|
+
/* Lumenの場合は bootstrap/app.phpに以下のコードを追加
|
123
|
+
* class_alias('Illuminate\Support\Facades\File', 'File');
|
124
|
+
*/
|
125
|
+
// \File::delete('Your image File);
|
126
|
+
|
127
|
+
return $image ?: false;
|
128
|
+
|
129
|
+
});
|
130
|
+
|
131
|
+
return $crop ? ['response' => true, 'img' => $str . '.jpg']
|
132
|
+
: ['response' => false];
|
133
|
+
|
134
|
+
});
|
135
|
+
</script>
|
136
|
+
```
|