質問編集履歴
3
不要な<script>タグを削除しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -38,6 +38,10 @@
|
|
38
38
|
|
39
39
|
また、リサイズした画像をphpで表示する方法も教えて頂きたいです。
|
40
40
|
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
41
45
|
(他 .map ファイル4種)
|
42
46
|
|
43
47
|
bootstrap.css bootstrap.min.css
|
@@ -210,7 +214,7 @@
|
|
210
214
|
|
211
215
|
// app/routes.php
|
212
216
|
|
213
|
-
|
217
|
+
|
214
218
|
|
215
219
|
use Illuminate\Http\Request;
|
216
220
|
|
@@ -286,6 +290,6 @@
|
|
286
290
|
|
287
291
|
});
|
288
292
|
|
289
|
-
|
293
|
+
|
290
294
|
|
291
295
|
```
|
2
ファイル構成を追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -38,15 +38,35 @@
|
|
38
38
|
|
39
39
|
また、リサイズした画像をphpで表示する方法も教えて頂きたいです。
|
40
40
|
|
41
|
-
|
41
|
+
(他 .map ファイル4種)
|
42
|
+
|
42
|
-
|
43
|
+
bootstrap.css bootstrap.min.css
|
44
|
+
|
43
|
-
|
45
|
+
bootstrap-theme.css bootstrap-theme.min.css
|
46
|
+
|
44
|
-
|
47
|
+
----css{ bootstrap.js bootstrap.min.js npm.js
|
48
|
+
|
49
|
+
フォルダ構成 |
|
50
|
+
|
51
|
+
boot_test -------js { bootstrap.js bootstrap.min.js npm.js
|
52
|
+
|
53
|
+
|
|
54
|
+
|
45
|
-
|
55
|
+
----img
|
56
|
+
|
46
|
-
|
57
|
+
|
|
58
|
+
|
47
|
-
|
59
|
+
---app { routes.php
|
60
|
+
|
48
|
-
|
61
|
+
|
|
62
|
+
|
63
|
+
----fonts
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
```html
|
68
|
+
|
49
|
-
|
69
|
+
<!-- boot_test/index.html -->
|
50
70
|
|
51
71
|
<!DOCTYPE html>
|
52
72
|
|
@@ -186,9 +206,9 @@
|
|
186
206
|
|
187
207
|
```
|
188
208
|
|
209
|
+
```javascript
|
210
|
+
|
189
|
-
|
211
|
+
// app/routes.php
|
190
|
-
|
191
|
-
//
|
192
212
|
|
193
213
|
<script>
|
194
214
|
|
1
ほぼ丸写しですが、コードを追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -37,3 +37,235 @@
|
|
37
37
|
|
38
38
|
|
39
39
|
また、リサイズした画像をphpで表示する方法も教えて頂きたいです。
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
※追加
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
```boot_test/index.html
|
50
|
+
|
51
|
+
<!DOCTYPE html>
|
52
|
+
|
53
|
+
<html lang="en">
|
54
|
+
|
55
|
+
<head>
|
56
|
+
|
57
|
+
<meta charset="utf-8">
|
58
|
+
|
59
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
60
|
+
|
61
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
62
|
+
|
63
|
+
<title>Bootstrap 101 Template</title>
|
64
|
+
|
65
|
+
<!-- Bootstrap -->
|
66
|
+
|
67
|
+
<link href="css/bootstrap.min.css" rel="stylesheet">
|
68
|
+
|
69
|
+
<!-- CSS -->
|
70
|
+
|
71
|
+
<link href="https://cdnjs.cloudflare.com/ajax/libs/cropper/1.0.0/cropper.min.css" rel="stylesheet" type="text/css" media="all"/>
|
72
|
+
|
73
|
+
<!-- JS -->
|
74
|
+
|
75
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
|
76
|
+
|
77
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/cropper/1.0.0/cropper.min.js"></script>
|
78
|
+
|
79
|
+
<!--[if lt IE 9]>
|
80
|
+
|
81
|
+
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
|
82
|
+
|
83
|
+
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
84
|
+
|
85
|
+
<![endif]-->
|
86
|
+
|
87
|
+
</head>
|
88
|
+
|
89
|
+
<body>
|
90
|
+
|
91
|
+
<h3><i class="fa fa-crop"></i> cropperのデモ </h3>
|
92
|
+
|
93
|
+
<!-- 切り抜きボタン -->
|
94
|
+
|
95
|
+
<a id="getData" class="btn btn-primary">Get Data</a><br><br>
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
<div class="cropper-example-1">
|
100
|
+
|
101
|
+
<!-- bladeテンプレートを使用していれば asset()や url() 関数が使えます -->
|
102
|
+
|
103
|
+
<img id="img" class="img-responsive" src="./img/art.jpg" alt="">
|
104
|
+
|
105
|
+
</div>
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
<script type="text/javascript">
|
110
|
+
|
111
|
+
// init
|
112
|
+
|
113
|
+
// class='cropper-example-1のimgタグに適用'
|
114
|
+
|
115
|
+
var $image = $('.cropper-example-1 > img'),replaced;
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
//crop options
|
120
|
+
|
121
|
+
// id='imgに適用'
|
122
|
+
|
123
|
+
$('#img').cropper({
|
124
|
+
|
125
|
+
aspectRatio: 4 / 4 // ここでアスペクト比の調整 ワイド画面にしたい場合は 16 / 9
|
126
|
+
|
127
|
+
});
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
$('#getData').on('click', function(){
|
132
|
+
|
133
|
+
alert('こんにちは!');
|
134
|
+
|
135
|
+
// crop のデータを取得
|
136
|
+
|
137
|
+
var data = $('#img').cropper('getData');
|
138
|
+
|
139
|
+
// 切り抜きした画像のデータ
|
140
|
+
|
141
|
+
// このデータを元にして画像の切り抜きが行われます
|
142
|
+
|
143
|
+
var image = {
|
144
|
+
|
145
|
+
width: Math.round(data.width),
|
146
|
+
|
147
|
+
height: Math.round(data.height),
|
148
|
+
|
149
|
+
x: Math.round(data.x),
|
150
|
+
|
151
|
+
y: Math.round(data.y),
|
152
|
+
|
153
|
+
_token: 'jf89ajtr234534829057835wjLA-SF_d8Z' // csrf用
|
154
|
+
|
155
|
+
};
|
156
|
+
|
157
|
+
// post 処理
|
158
|
+
|
159
|
+
$.post('/cropper', image, function(res){
|
160
|
+
|
161
|
+
// 成功すれば trueと表示されます
|
162
|
+
|
163
|
+
console.log(res);
|
164
|
+
|
165
|
+
});
|
166
|
+
|
167
|
+
});
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
</script>
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
|
176
|
+
|
177
|
+
<script src="js/bootstrap.min.js"></script>
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
</body>
|
182
|
+
|
183
|
+
</html>
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
```
|
188
|
+
|
189
|
+
```app/routes.php
|
190
|
+
|
191
|
+
//
|
192
|
+
|
193
|
+
<script>
|
194
|
+
|
195
|
+
use Illuminate\Http\Request;
|
196
|
+
|
197
|
+
use Intervention\Image\ImageManagerStatic as Image;
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
$app->post('/cropper', function(Request $request){
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
$str = str_random(7);
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
$crop = value(function() use ($request, $str) {
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
// Laravelの場合は public_path()ヘルパー関数、Facadeが使えます
|
214
|
+
|
215
|
+
$image = Image::make('../public/img/art.jpg')
|
216
|
+
|
217
|
+
->crop(
|
218
|
+
|
219
|
+
$request->get('width'),
|
220
|
+
|
221
|
+
$request->get('height'),
|
222
|
+
|
223
|
+
$request->get('x'),
|
224
|
+
|
225
|
+
$request->get('y')
|
226
|
+
|
227
|
+
)
|
228
|
+
|
229
|
+
->resize(256,256) // 256 * 256にリサイズ
|
230
|
+
|
231
|
+
// 画像の保存
|
232
|
+
|
233
|
+
->save('../public/img/'. $str . '.jpg')
|
234
|
+
|
235
|
+
->resize(128,128) //サムネイル用にリサイズ
|
236
|
+
|
237
|
+
->save('../public/img/'. $str . '_t' . '.jpg');
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
// 必要があれば元のファイルも消す
|
242
|
+
|
243
|
+
/* Lumenの場合は bootstrap/app.phpに以下のコードを追加
|
244
|
+
|
245
|
+
* class_alias('Illuminate\Support\Facades\File', 'File');
|
246
|
+
|
247
|
+
*/
|
248
|
+
|
249
|
+
// \File::delete('Your image File);
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
return $image ?: false;
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
});
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
return $crop ? ['response' => true, 'img' => $str . '.jpg']
|
262
|
+
|
263
|
+
: ['response' => false];
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
});
|
268
|
+
|
269
|
+
</script>
|
270
|
+
|
271
|
+
```
|