質問編集履歴

4

質問の訂正

2019/12/04 05:41

投稿

popopop
popopop

スコア11

test CHANGED
File without changes
test CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  原因わかりますでしょうか?
4
4
 
5
+ いろいろ試した結果、どの拡張子でも縦長の画像だけwidthが見切れてしまいました
6
+
7
+ ![![イメージ説明](85d9755b9136f923b8e944bf3bb9ef85.jpeg)](8b82eb9a4c2db57fba2d9353d843493a.jpeg)
8
+
5
9
  ```php
6
10
 
7
11
  if (isset($_POST["send"])) {

3

プログラムの修正

2019/12/04 05:41

投稿

popopop
popopop

スコア11

test CHANGED
File without changes
test CHANGED
@@ -20,11 +20,7 @@
20
20
 
21
21
  list($width, $hight)=$date;
22
22
 
23
- var_dump($width);
23
+
24
-
25
- var_dump($hight);
26
-
27
- var_dump($date[2]);
28
24
 
29
25
  $w = $width / 100;
30
26
 
@@ -66,7 +62,7 @@
66
62
 
67
63
  if ($date[2] == 2) {
68
64
 
69
- $img_in = imagecreatefromjpg($file);
65
+ $img_in = imagecreatefromjpeg($file);
70
66
 
71
67
  $img_out = imagecreatetruecolor(100, 200);
72
68
 
@@ -88,7 +84,7 @@
88
84
 
89
85
 
90
86
 
91
- imagejpg($img_out, "images/new.jpeg");
87
+ imagejpeg($img_out, "images/new.jpeg");
92
88
 
93
89
  }
94
90
 

2

コードの編集

2019/12/04 05:16

投稿

popopop
popopop

スコア11

test CHANGED
File without changes
test CHANGED
@@ -1,8 +1,8 @@
1
1
  PNG、GIF、JPEGの画像のリサイズで、PNGとGIFは動くんですがJPEGだけ見切れてしまいます
2
2
 
3
- 原因わかりますでしょうか?```PHP
3
+ 原因わかりますでしょうか?
4
-
4
+
5
- コード
5
+ ```php
6
6
 
7
7
  if (isset($_POST["send"])) {
8
8
 
@@ -176,196 +176,10 @@
176
176
 
177
177
 
178
178
 
179
-
179
+ ```
180
-
181
-
182
180
 
183
181
  ```html
184
182
 
185
- <?php
186
-
187
-
188
-
189
-
190
-
191
- if (isset($_POST["send"])) {
192
-
193
- $file = $_FILES['fname']['tmp_name'];
194
-
195
-
196
-
197
-
198
-
199
- $date= getimagesize($file);
200
-
201
-
202
-
203
-
204
-
205
- list($width, $hight)=$date;
206
-
207
- var_dump($width);
208
-
209
- var_dump($hight);
210
-
211
- var_dump($date[2]);
212
-
213
- $w = $width / 100;
214
-
215
- $h = $hight / 200;
216
-
217
- var_dump($w);
218
-
219
- var_dump($h);
220
-
221
- if ($width >= $hight) {
222
-
223
- $nw = $width / $w;
224
-
225
- $nh = $hight / $w;
226
-
227
- } elseif ($width < $hight) {
228
-
229
- $nw = $width / $h;
230
-
231
- $nh = $hight / $h;
232
-
233
- }
234
-
235
- var_dump($nw);
236
-
237
- var_dump($nh);
238
-
239
- $nx = (100-$nw) / 2;
240
-
241
- $ny = (200-$nh) / 2;
242
-
243
-
244
-
245
-
246
-
247
-
248
-
249
- //JPG
250
-
251
- if ($date[2] == 2) {
252
-
253
- $img_in = imagecreatefromjpg($file);
254
-
255
- $img_out = imagecreatetruecolor(100, 200);
256
-
257
-
258
-
259
- imagealphablending($img_out, false);
260
-
261
- imagesavealpha($img_out, true);
262
-
263
-
264
-
265
-
266
-
267
- imagecopyresampled($img_out, $img_in, $nx, $ny, 0, 0, $nw, $nh, $width, $hight);
268
-
269
-
270
-
271
- $filename = 'jpeg';
272
-
273
-
274
-
275
- imagejpg($img_out, "images/new.jpeg");
276
-
277
- }
278
-
279
-
280
-
281
- //PNG
282
-
283
- elseif ($date[2] == 3) {
284
-
285
-
286
-
287
- $img_in = imagecreatefrompng($file);
288
-
289
- $img_out = imagecreatetruecolor(100, 200);
290
-
291
-
292
-
293
- imagealphablending($img_out, false);
294
-
295
- imagesavealpha($img_out, true);
296
-
297
-
298
-
299
-
300
-
301
- imagecopyresampled($img_out, $img_in, $nx, $ny, 0, 0, $nw, $nh, $width, $hight);
302
-
303
-
304
-
305
- $filename = 'png';
306
-
307
-
308
-
309
- imagepng($img_out, 'images/new.png');
310
-
311
- }
312
-
313
-
314
-
315
-
316
-
317
- //GIF
318
-
319
- elseif($date[2] == 1){
320
-
321
- $img_in = imagecreatefromgif($file);
322
-
323
- $img_out = imagecreatetruecolor(100, 200);
324
-
325
-
326
-
327
- imagealphablending($img_out, false);
328
-
329
- imagesavealpha($img_out, true);
330
-
331
-
332
-
333
-
334
-
335
- imagecopyresampled($img_out, $img_in, $nx, $ny, 0, 0, $nw, $nh, $width, $hight);
336
-
337
-
338
-
339
-
340
-
341
- $filename = 'gif';
342
-
343
- imagegif($img_out, "images/new.gif");
344
-
345
- }
346
-
347
-
348
-
349
-
350
-
351
-
352
-
353
- imagedestroy($img_in);
354
-
355
- imagedestroy($img_out);
356
-
357
-
358
-
359
- }
360
-
361
-
362
-
363
-
364
-
365
- ?>
366
-
367
-
368
-
369
183
  <!doctype html>
370
184
 
371
185
  <html>
@@ -416,10 +230,4 @@
416
230
 
417
231
  </html>
418
232
 
419
-
420
-
421
233
  ```
422
-
423
-
424
-
425
- ```

1

内容の追加

2019/12/04 05:14

投稿

popopop
popopop

スコア11

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,186 @@
1
1
  PNG、GIF、JPEGの画像のリサイズで、PNGとGIFは動くんですがJPEGだけ見切れてしまいます
2
2
 
3
- 原因わかりますでしょうか?```php
3
+ 原因わかりますでしょうか?```PHP
4
+
5
+ コード
6
+
7
+ if (isset($_POST["send"])) {
8
+
9
+ $file = $_FILES['fname']['tmp_name'];
10
+
11
+
12
+
13
+
14
+
15
+ $date= getimagesize($file);
16
+
17
+
18
+
19
+
20
+
21
+ list($width, $hight)=$date;
22
+
23
+ var_dump($width);
24
+
25
+ var_dump($hight);
26
+
27
+ var_dump($date[2]);
28
+
29
+ $w = $width / 100;
30
+
31
+ $h = $hight / 200;
32
+
33
+ var_dump($w);
34
+
35
+ var_dump($h);
36
+
37
+ if ($width >= $hight) {
38
+
39
+ $nw = $width / $w;
40
+
41
+ $nh = $hight / $w;
42
+
43
+ } elseif ($width < $hight) {
44
+
45
+ $nw = $width / $h;
46
+
47
+ $nh = $hight / $h;
48
+
49
+ }
50
+
51
+ var_dump($nw);
52
+
53
+ var_dump($nh);
54
+
55
+ $nx = (100-$nw) / 2;
56
+
57
+ $ny = (200-$nh) / 2;
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+ //JPG
66
+
67
+ if ($date[2] == 2) {
68
+
69
+ $img_in = imagecreatefromjpg($file);
70
+
71
+ $img_out = imagecreatetruecolor(100, 200);
72
+
73
+
74
+
75
+ imagealphablending($img_out, false);
76
+
77
+ imagesavealpha($img_out, true);
78
+
79
+
80
+
81
+
82
+
83
+ imagecopyresampled($img_out, $img_in, $nx, $ny, 0, 0, $nw, $nh, $width, $hight);
84
+
85
+
86
+
87
+ $filename = 'jpeg';
88
+
89
+
90
+
91
+ imagejpg($img_out, "images/new.jpeg");
92
+
93
+ }
94
+
95
+
96
+
97
+ //PNG
98
+
99
+ elseif ($date[2] == 3) {
100
+
101
+
102
+
103
+ $img_in = imagecreatefrompng($file);
104
+
105
+ $img_out = imagecreatetruecolor(100, 200);
106
+
107
+
108
+
109
+ imagealphablending($img_out, false);
110
+
111
+ imagesavealpha($img_out, true);
112
+
113
+
114
+
115
+
116
+
117
+ imagecopyresampled($img_out, $img_in, $nx, $ny, 0, 0, $nw, $nh, $width, $hight);
118
+
119
+
120
+
121
+ $filename = 'png';
122
+
123
+
124
+
125
+ imagepng($img_out, 'images/new.png');
126
+
127
+ }
128
+
129
+
130
+
131
+
132
+
133
+ //GIF
134
+
135
+ elseif($date[2] == 1){
136
+
137
+ $img_in = imagecreatefromgif($file);
138
+
139
+ $img_out = imagecreatetruecolor(100, 200);
140
+
141
+
142
+
143
+ imagealphablending($img_out, false);
144
+
145
+ imagesavealpha($img_out, true);
146
+
147
+
148
+
149
+
150
+
151
+ imagecopyresampled($img_out, $img_in, $nx, $ny, 0, 0, $nw, $nh, $width, $hight);
152
+
153
+
154
+
155
+
156
+
157
+ $filename = 'gif';
158
+
159
+ imagegif($img_out, "images/new.gif");
160
+
161
+ }
162
+
163
+
164
+
165
+
166
+
167
+
168
+
169
+ imagedestroy($img_in);
170
+
171
+ imagedestroy($img_out);
172
+
173
+
174
+
175
+ }
176
+
177
+
178
+
179
+
180
+
181
+
182
+
183
+ ```html
4
184
 
5
185
  <?php
6
186
 
@@ -239,3 +419,7 @@
239
419
 
240
420
 
241
421
  ```
422
+
423
+
424
+
425
+ ```