用户之前在发烧网参加的上传图片活动都没有经过无损压缩处理.想用脚本对一月内传上去的图片进行处理,但amazon_s3服务集群上只能使用他们提供的一些简单的api.所以只能先down 下来,压缩处理后,再传上去覆盖原来的图片.
经过多次调试,最终写了个php的脚本对之进行处理:详见这里.
代码如下:
1: ./tmp.txt);
6: $rs = file('./tmp.txt');
7:
8: foreach($rs as $line) {
9: $r = array_filter(explode(' ', $line));
10: if(!empty($r[0])){
11: $r[0] = trim($r[0]);
12: $time = strtotime($r[0]);
13: }
14: if(!empty($time) && $time >= $start_time){
15: if(!empty($r[10])){
16: $img = trim($r[10]);
17: $path_info = pathinfo($r[10]);
18: $ext = trim($path_info[extension]);
19: $file_name = strtolower(trim($path_info[basename]));
20:
21: exec(s3cmd get .$img);
22: exec(cp {$file_name} /mnt/heisoo/s3/{$source}/);
23:
24: if (in_array($ext,$exts)) {
25: system(/usr/bin/optipng -o5 .$file_name);
26: }
27: if ($ext == jpg || $ext == jpeg) {
28: system(/usr/bin/jpegoptim -o --strip-all .$file_name);
29: }
30: system(s3cmd put {$file_name} {$img} --guess-mime-type --add-header 'cache-control:max-age=31536000' --add-header 'expires: thu, 01 dec 2014 16:00:00 gmt' --acl-public);
31: unlink($file_name);
32: }
33: }
34: }
35:
36: unlink('./tmp.txt');
37: }
38:
39: compress_img(promotion_main_pic);
40: compress_img(src_thumb);
41: compress_img(uploadimage);
42: compress_img(dialog_image);
43: compress_img(joinpicture);
44: ?>
http://www.bkjia.com/phpjc/440176.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/440176.htmltecharticle用户之前在发烧网参加的上传图片活动都没有经过无损压缩处理.想用脚本对一月内传上去的图片进行处理,但amazon_s3服务集群上只能使用他...