質問編集履歴
3
質問文の編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,194 +20,336 @@
|
|
20
20
|
|
21
21
|
利用しているサーバー(ロリポップ)ではImage::Magickは利用可(パスは /usr/bin/convert)となっています。
|
22
22
|
|
23
|
+
|
24
|
+
|
25
|
+
```ここに言語を入力
|
26
|
+
|
27
|
+
#HTML
|
28
|
+
|
29
|
+
<input type="file" name="●●●" />
|
30
|
+
|
31
|
+
```
|
32
|
+
|
33
|
+
```ここに言語を入力
|
34
|
+
|
35
|
+
#PERL
|
36
|
+
|
37
|
+
sub UpFile {
|
38
|
+
|
39
|
+
$macbin=0;
|
40
|
+
|
41
|
+
foreach (@in) {
|
42
|
+
|
43
|
+
if ($_ =~ /(.*)Content-type:(.*)/i) { $tail=$2; }
|
44
|
+
|
45
|
+
if ($_ =~ /(.*)filename=(.*)/i) { $fname=$2; }
|
46
|
+
|
47
|
+
if ($_ =~ /application/x-macbinary/i) { $macbin=1; }
|
48
|
+
|
49
|
+
}
|
50
|
+
|
51
|
+
$tail =~ s/\r//g;
|
52
|
+
|
53
|
+
$tail =~ s/\n//g;
|
54
|
+
|
55
|
+
$fname =~ tr/\"\x0D\x0A//d;
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
$flag=0;
|
60
|
+
|
61
|
+
if ($tail =~ /image/gif/i && $gif) { $tail=".gif"; $flag=1; }
|
62
|
+
|
63
|
+
if ($tail =~ /image/jpeg/i && $jpeg) { $tail=".jpg"; $flag=1; }
|
64
|
+
|
65
|
+
if ($tail =~ /image/x-png/i && $png) { $tail=".png"; $flag=1; }
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
if (!$flag) {
|
70
|
+
|
71
|
+
if ($fname =~ /.gif$/i && $gif) { $tail=".gif"; $flag=1; }
|
72
|
+
|
73
|
+
if (($fname =~ /.jpe?g$/i && $jpeg)) { $tail=".jpg"; $flag=1; }
|
74
|
+
|
75
|
+
if ($fname =~ /.png$/i && $png) { $tail=".png"; $flag=1; }
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
foreach $confirm_type (@confirm_type) {
|
82
|
+
|
83
|
+
if ( $fname =~ /.$confirm_type$/i ) { $tail=".$confirm_type"; $flag=2; $org_width="file"; last; }
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
if (!$flag) { return; }
|
90
|
+
|
91
|
+
elsif (!$flag) {
|
92
|
+
|
93
|
+
&error("アップロードできないファイル形式です","lock");
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
$upfile = $in{'upfile'};
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
if ($macbin) {
|
104
|
+
|
105
|
+
$length = substr($upfile,83,4);
|
106
|
+
|
107
|
+
$length = unpack("%N",$length);
|
108
|
+
|
109
|
+
$upfile = substr($upfile,128,$length);
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
$ImgFile = "$ImgUrl$no$tail";
|
116
|
+
|
117
|
+
open(OUT,"> $ImgFile") || &error("画像のアップロードに失敗しました","lock");
|
118
|
+
|
119
|
+
binmode(OUT);
|
120
|
+
|
121
|
+
binmode(STDOUT);
|
122
|
+
|
123
|
+
print OUT $upfile;
|
124
|
+
|
125
|
+
close(OUT);
|
126
|
+
|
127
|
+
chmod (0666,$ImgFile);
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
if ($tail eq ".jpg") { ($W, $H) = &JpegSize($ImgFile); }
|
132
|
+
|
133
|
+
elsif ($tail eq ".gif") { ($W, $H) = &GifSize($ImgFile); }
|
134
|
+
|
135
|
+
elsif ($tail eq ".png") { ($W, $H) = &PngSize($ImgFile); }
|
136
|
+
|
137
|
+
elsif ( $flag eq "2" ) { $W = $down_ix; $H = $down_iy; }
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
if ($W > $MaxW || $H > $MaxH) {
|
142
|
+
|
143
|
+
$orw = $W; $orh = $H;
|
144
|
+
|
145
|
+
$W2 = $MaxW / $W;
|
146
|
+
|
147
|
+
$H2 = $MaxH / $H;
|
148
|
+
|
149
|
+
if ($W2 < $H2) { $key = $W2; }
|
150
|
+
|
151
|
+
else { $key = $H2; }
|
152
|
+
|
153
|
+
$W = int ($W * $key) || 1;
|
154
|
+
|
155
|
+
$H = int ($H * $key) || 1;
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
}
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
sub JpegSize {
|
164
|
+
|
165
|
+
local($jpeg) = @_;
|
166
|
+
|
167
|
+
local($t, $m, $c, $l, $W, $H);
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
open(JPEG, "$jpeg") || return (0,0);
|
172
|
+
|
173
|
+
binmode JPEG;
|
174
|
+
|
175
|
+
read(JPEG, $t, 2);
|
176
|
+
|
177
|
+
while (1) {
|
178
|
+
|
179
|
+
read(JPEG, $t, 4);
|
180
|
+
|
181
|
+
($m, $c, $l) = unpack("a a n", $t);
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
if ($m ne "\xFF") { $W = $H = 0; last; }
|
186
|
+
|
187
|
+
elsif ((ord($c) >= 0xC0) && (ord($c) <= 0xC3)) {
|
188
|
+
|
189
|
+
read(JPEG, $t, 5);
|
190
|
+
|
191
|
+
($H, $W) = unpack("xnn", $t);
|
192
|
+
|
193
|
+
last;
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
else {
|
198
|
+
|
199
|
+
read(JPEG, $t, ($l - 2));
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
}
|
204
|
+
|
205
|
+
close(JPEG);
|
206
|
+
|
207
|
+
return ($W, $H);
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
```
|
212
|
+
|
213
|
+
以下は参考サイトなどを見ながら自分でやってみたものですが、アップされた写真のexif情報は削除されませんでした。
|
214
|
+
|
215
|
+
```ここに言語を入力
|
216
|
+
|
217
|
+
sub UpFile {
|
218
|
+
|
219
|
+
$macbin=0;
|
220
|
+
|
221
|
+
foreach (@in) {
|
222
|
+
|
223
|
+
if ($_ =~ /(.*)Content-type:(.*)/i) { $tail=$2; }
|
224
|
+
|
225
|
+
if ($_ =~ /(.*)filename=(.*)/i) { $fname=$2; }
|
226
|
+
|
227
|
+
if ($_ =~ /application/x-macbinary/i) { $macbin=1; }
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
$tail =~ s/\r//g;
|
232
|
+
|
233
|
+
$tail =~ s/\n//g;
|
234
|
+
|
235
|
+
$fname =~ tr/\"\x0D\x0A//d;
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
$flag=0;
|
240
|
+
|
241
|
+
if ($tail =~ /image/gif/i && $gif) { $tail=".gif"; $flag=1; }
|
242
|
+
|
243
|
+
if ($tail =~ /image/jpeg/i && $jpeg) { $tail=".jpg"; $flag=1; }
|
244
|
+
|
245
|
+
if ($tail =~ /image/x-png/i && $png) { $tail=".png"; $flag=1; }
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
if (!$flag) {
|
250
|
+
|
251
|
+
if ($fname =~ /.gif$/i && $gif) { $tail=".gif"; $flag=1; }
|
252
|
+
|
253
|
+
if (($fname =~ /.jpe?g$/i && $jpeg)) { $tail=".jpg"; $flag=1; }
|
254
|
+
|
255
|
+
if ($fname =~ /.png$/i && $png) { $tail=".png"; $flag=1; }
|
256
|
+
|
257
|
+
}
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
foreach $confirm_type (@confirm_type) {
|
262
|
+
|
263
|
+
if ( $fname =~ /.$confirm_type$/i ) { $tail=".$confirm_type"; $flag=2; $org_width="file"; last; }
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
if (!$flag) { return; }
|
270
|
+
|
271
|
+
elsif (!$flag) {
|
272
|
+
|
273
|
+
&error("アップロードできないファイル形式です","lock");
|
274
|
+
|
275
|
+
}
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
$upfile = $in{'upfile'};
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
if ($macbin) {
|
284
|
+
|
285
|
+
$length = substr($upfile,83,4);
|
286
|
+
|
287
|
+
$length = unpack("%N",$length);
|
288
|
+
|
289
|
+
$upfile = substr($upfile,128,$length);
|
290
|
+
|
291
|
+
}
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
$ImgFile = "$ImgUrl$no$tail";
|
296
|
+
|
297
|
+
####以下を追記してみましたがアップされた写真のexif情報は削除されませんでした####
|
298
|
+
|
299
|
+
my $im = new Image::Magick;
|
300
|
+
|
301
|
+
$im -> Read( $ImgFile );
|
302
|
+
|
303
|
+
$im -> Strip;
|
304
|
+
|
305
|
+
$im -> Write( $ImgFile );
|
306
|
+
|
307
|
+
####//追記####
|
308
|
+
|
309
|
+
open(OUT,"> $ImgFile") || &error("画像のアップロードに失敗しました","lock");
|
310
|
+
|
311
|
+
binmode(OUT);
|
312
|
+
|
313
|
+
binmode(STDOUT);
|
314
|
+
|
315
|
+
print OUT $upfile;
|
316
|
+
|
317
|
+
close(OUT);
|
318
|
+
|
319
|
+
chmod (0666,$ImgFile);
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
if ($tail eq ".jpg") { ($W, $H) = &JpegSize($ImgFile); }
|
324
|
+
|
325
|
+
elsif ($tail eq ".gif") { ($W, $H) = &GifSize($ImgFile); }
|
326
|
+
|
327
|
+
elsif ($tail eq ".png") { ($W, $H) = &PngSize($ImgFile); }
|
328
|
+
|
329
|
+
elsif ( $flag eq "2" ) { $W = $down_ix; $H = $down_iy; }
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
if ($W > $MaxW || $H > $MaxH) {
|
334
|
+
|
335
|
+
$orw = $W; $orh = $H;
|
336
|
+
|
337
|
+
$W2 = $MaxW / $W;
|
338
|
+
|
339
|
+
$H2 = $MaxH / $H;
|
340
|
+
|
341
|
+
if ($W2 < $H2) { $key = $W2; }
|
342
|
+
|
343
|
+
else { $key = $H2; }
|
344
|
+
|
345
|
+
$W = int ($W * $key) || 1;
|
346
|
+
|
347
|
+
$H = int ($H * $key) || 1;
|
348
|
+
|
349
|
+
}
|
350
|
+
|
351
|
+
}
|
352
|
+
|
353
|
+
```
|
354
|
+
|
23
355
|
Image::Magick以外の方法でも構いませんので、アップロードする画像のexif情報を削除する方法がありましたらばアドバイスお願いいたします。
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
```ここに言語を入力
|
28
|
-
|
29
|
-
#HTML
|
30
|
-
|
31
|
-
<input type="file" name="●●●" />
|
32
|
-
|
33
|
-
```
|
34
|
-
|
35
|
-
```ここに言語を入力
|
36
|
-
|
37
|
-
#PERL
|
38
|
-
|
39
|
-
sub UpFile {
|
40
|
-
|
41
|
-
$macbin=0;
|
42
|
-
|
43
|
-
foreach (@in) {
|
44
|
-
|
45
|
-
if ($_ =~ /(.*)Content-type:(.*)/i) { $tail=$2; }
|
46
|
-
|
47
|
-
if ($_ =~ /(.*)filename=(.*)/i) { $fname=$2; }
|
48
|
-
|
49
|
-
if ($_ =~ /application/x-macbinary/i) { $macbin=1; }
|
50
|
-
|
51
|
-
}
|
52
|
-
|
53
|
-
$tail =~ s/\r//g;
|
54
|
-
|
55
|
-
$tail =~ s/\n//g;
|
56
|
-
|
57
|
-
$fname =~ tr/\"\x0D\x0A//d;
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
$flag=0;
|
62
|
-
|
63
|
-
if ($tail =~ /image/gif/i && $gif) { $tail=".gif"; $flag=1; }
|
64
|
-
|
65
|
-
if ($tail =~ /image/jpeg/i && $jpeg) { $tail=".jpg"; $flag=1; }
|
66
|
-
|
67
|
-
if ($tail =~ /image/x-png/i && $png) { $tail=".png"; $flag=1; }
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
if (!$flag) {
|
72
|
-
|
73
|
-
if ($fname =~ /.gif$/i && $gif) { $tail=".gif"; $flag=1; }
|
74
|
-
|
75
|
-
if (($fname =~ /.jpe?g$/i && $jpeg)) { $tail=".jpg"; $flag=1; }
|
76
|
-
|
77
|
-
if ($fname =~ /.png$/i && $png) { $tail=".png"; $flag=1; }
|
78
|
-
|
79
|
-
}
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
foreach $confirm_type (@confirm_type) {
|
84
|
-
|
85
|
-
if ( $fname =~ /.$confirm_type$/i ) { $tail=".$confirm_type"; $flag=2; $org_width="file"; last; }
|
86
|
-
|
87
|
-
}
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
if (!$flag) { return; }
|
92
|
-
|
93
|
-
elsif (!$flag) {
|
94
|
-
|
95
|
-
&error("アップロードできないファイル形式です","lock");
|
96
|
-
|
97
|
-
}
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
$upfile = $in{'upfile'};
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
if ($macbin) {
|
106
|
-
|
107
|
-
$length = substr($upfile,83,4);
|
108
|
-
|
109
|
-
$length = unpack("%N",$length);
|
110
|
-
|
111
|
-
$upfile = substr($upfile,128,$length);
|
112
|
-
|
113
|
-
}
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
$ImgFile = "$ImgUrl$no$tail";
|
118
|
-
|
119
|
-
open(OUT,"> $ImgFile") || &error("画像のアップロードに失敗しました","lock");
|
120
|
-
|
121
|
-
binmode(OUT);
|
122
|
-
|
123
|
-
binmode(STDOUT);
|
124
|
-
|
125
|
-
print OUT $upfile;
|
126
|
-
|
127
|
-
close(OUT);
|
128
|
-
|
129
|
-
chmod (0666,$ImgFile);
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
if ($tail eq ".jpg") { ($W, $H) = &JpegSize($ImgFile); }
|
134
|
-
|
135
|
-
elsif ($tail eq ".gif") { ($W, $H) = &GifSize($ImgFile); }
|
136
|
-
|
137
|
-
elsif ($tail eq ".png") { ($W, $H) = &PngSize($ImgFile); }
|
138
|
-
|
139
|
-
elsif ( $flag eq "2" ) { $W = $down_ix; $H = $down_iy; }
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
if ($W > $MaxW || $H > $MaxH) {
|
144
|
-
|
145
|
-
$orw = $W; $orh = $H;
|
146
|
-
|
147
|
-
$W2 = $MaxW / $W;
|
148
|
-
|
149
|
-
$H2 = $MaxH / $H;
|
150
|
-
|
151
|
-
if ($W2 < $H2) { $key = $W2; }
|
152
|
-
|
153
|
-
else { $key = $H2; }
|
154
|
-
|
155
|
-
$W = int ($W * $key) || 1;
|
156
|
-
|
157
|
-
$H = int ($H * $key) || 1;
|
158
|
-
|
159
|
-
}
|
160
|
-
|
161
|
-
}
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
sub JpegSize {
|
166
|
-
|
167
|
-
local($jpeg) = @_;
|
168
|
-
|
169
|
-
local($t, $m, $c, $l, $W, $H);
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
open(JPEG, "$jpeg") || return (0,0);
|
174
|
-
|
175
|
-
binmode JPEG;
|
176
|
-
|
177
|
-
read(JPEG, $t, 2);
|
178
|
-
|
179
|
-
while (1) {
|
180
|
-
|
181
|
-
read(JPEG, $t, 4);
|
182
|
-
|
183
|
-
($m, $c, $l) = unpack("a a n", $t);
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
if ($m ne "\xFF") { $W = $H = 0; last; }
|
188
|
-
|
189
|
-
elsif ((ord($c) >= 0xC0) && (ord($c) <= 0xC3)) {
|
190
|
-
|
191
|
-
read(JPEG, $t, 5);
|
192
|
-
|
193
|
-
($H, $W) = unpack("xnn", $t);
|
194
|
-
|
195
|
-
last;
|
196
|
-
|
197
|
-
}
|
198
|
-
|
199
|
-
else {
|
200
|
-
|
201
|
-
read(JPEG, $t, ($l - 2));
|
202
|
-
|
203
|
-
}
|
204
|
-
|
205
|
-
}
|
206
|
-
|
207
|
-
close(JPEG);
|
208
|
-
|
209
|
-
return ($W, $H);
|
210
|
-
|
211
|
-
}
|
212
|
-
|
213
|
-
```
|
2
質問文の編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,16 +1,22 @@
|
|
1
|
+
perlで写真をアップロードするフォームがあります。
|
2
|
+
|
3
|
+
写真をフォームからアップロードするとサーバーの写真用の保存フォルダに保存され、その写真をウェブ上で見れるようにしています。
|
4
|
+
|
5
|
+
今は写真をアップロードすると写真のexif情報もそのまま保存されます。
|
6
|
+
|
1
|
-
|
7
|
+
これをアップロードする時に写真からexif情報を削除してアップロードしたいと考えています。
|
2
8
|
|
3
9
|
|
4
10
|
|
5
11
|
調べてみるとImage::Magickのstripオプョンを使うことでexif情報が削除できるとのことで、
|
6
12
|
|
7
|
-
アップロードファイルの保存処理の部分にいくつかコードを追加してみたのですがうまくいきません。
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
以下はもともとのファイルの保存処理のコードです。
|
12
|
-
|
13
|
-
|
13
|
+
アップロードする写真の保存処理の部分にImage::Magickのstripオプョンを組み込むのではないかと思うのですが、
|
14
|
+
|
15
|
+
どのようにすればよいのかわかりません。
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
以下は、HTML上のアップロードするフォームとperlの写真の保存処理のコードです。
|
14
20
|
|
15
21
|
利用しているサーバー(ロリポップ)ではImage::Magickは利用可(パスは /usr/bin/convert)となっています。
|
16
22
|
|
@@ -20,6 +26,16 @@
|
|
20
26
|
|
21
27
|
```ここに言語を入力
|
22
28
|
|
29
|
+
#HTML
|
30
|
+
|
31
|
+
<input type="file" name="●●●" />
|
32
|
+
|
33
|
+
```
|
34
|
+
|
35
|
+
```ここに言語を入力
|
36
|
+
|
37
|
+
#PERL
|
38
|
+
|
23
39
|
sub UpFile {
|
24
40
|
|
25
41
|
$macbin=0;
|
1
コードの編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -37,8 +37,6 @@
|
|
37
37
|
$tail =~ s/\r//g;
|
38
38
|
|
39
39
|
$tail =~ s/\n//g;
|
40
|
-
|
41
|
-
# $fname =~ s/\"//g;
|
42
40
|
|
43
41
|
$fname =~ tr/\"\x0D\x0A//d;
|
44
42
|
|