-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.php
76 lines (72 loc) · 2.19 KB
/
app.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
class imageExifPlugin extends PluginBase{
function __construct(){
parent::__construct();
//扩展缺失提示
if( !function_exists('exif_read_data')){
$this->appPackage();
$this->packageData['configItem'] = array(
"sep001" => '<div class="alert alert-danger m-30">'.LNG('imageExif.Config.missLib').'</div>',
);
}
}
public function regiest(){
$this->hookRegiest(array(
'user.commonJs.insert' => 'imageExifPlugin.echoJs',
'share.image' => 'imageExifPlugin.imageCheck',
'explorer.image' => 'imageExifPlugin.imageCheck',
));
}
public function echoJs($st,$act){
if(!function_exists('exif_read_data')){
return;
}
$this->echoFile('static/main.js');
}
public function index(){
$path = $this->filePath($this->in['path']);
$fileUrl = _make_file_proxy($path);
$fileName = get_path_this(rawurldecode($this->in['path']));
$data = $this->getExif();
include(dirname(__FILE__).'/static/template.php');
}
public function getExif(){
$path = _DIR($this->in['path']);
$exif = @exif_read_data($path);
//show_json($exif,!!$exif);
return $exif;
}
//根据Orientation 自动旋转图片
//http://blog.csdn.net/ouyangtianhan/article/details/29825885
//https://gxnotes.com/article/126807.html
//https://zhuanlan.zhihu.com/p/25216999
public function imageCheck(){
if( !function_exists('exif_read_data')){
return;
}
$path = _DIR($this->in['path']);
$exif = @exif_read_data($path);
if(!file_exists($path) || !$exif || !isset($exif['Orientation'])) return;
if( $exif['Orientation']< 3) return;
$img = ImageThumb::image($path);
if(!$img) return;
$ort = $exif['Orientation'];
if($ort == 5 || $ort == 6){
$img = imagerotate($img, 270, null);
}
if($ort == 3 || $ort == 4){
$img = imagerotate($img, 180, null);
}
if($ort == 7 || $ort == 8){
$img = imagerotate($img, 90, null);
}
if($ort == 4 || $ort == 5 || $ort == 7){
imageflip($img,IMG_FLIP_HORIZONTAL);
}
$ext = get_path_ext($path);
$imagefun = 'image'.($ext=='jpg'?'jpeg':$ext);
$res = $imagefun($img, $path);
imagedestroy($img);
//show_json($exif,$res);
}
}