-
Notifications
You must be signed in to change notification settings - Fork 14
/
imagerotate.php
121 lines (102 loc) · 3.22 KB
/
imagerotate.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
use Xmf\Request;
require_once __DIR__ . '/tadtools_header.php';
if (!function_exists('imagecreatetruecolor')) {
die('imagecreatetruecolor functions are not available.');
}
$op = Request::getString('op');
$subdir = Request::getString('subdir');
$image_dir = Request::getString('image_dir');
$thumbs_dir = Request::getString('thumbs_dir');
$filename = Request::getString('filename');
$type = Request::getString('type');
$pic = XOOPS_ROOT_PATH . "/uploads/{$subdir}{$image_dir}/{$filename}";
$thumb = XOOPS_ROOT_PATH . "/uploads/{$subdir}{$thumbs_dir}/{$filename}";
// 關閉除錯訊息
header('HTTP/1.1 200 OK');
$xoopsLogger->activated = false;
if ('image/jpeg' === $type or 'image/jpg' === $type or 'image/pjpg' === $type or 'image/pjpeg' === $type) {
$pic_im = imagecreatefromjpeg($pic);
$thumb_im = imagecreatefromjpeg($thumb);
header('Content-type: image/jpg');
} elseif ('image/png' === $type) {
$pic_im = imagecreatefrompng($pic);
$thumb_im = imagecreatefrompng($thumb);
header('Content-type: image/png');
} elseif ('image/gif' === $type) {
$pic_im = imagecreatefromgif($pic);
$thumb_im = imagecreatefromgif($thumb);
header('Content-type: image/gif');
}
if ('right' === $op) {
$pic_new_im = rotate_right90($pic_im);
$thumb_new_im = rotate_right90($thumb_im);
} elseif ('left' === $op) {
$pic_new_im = rotate_left90($pic_im);
$thumb_new_im = rotate_left90($thumb_im);
}
if ('image/jpeg' === $type or 'image/jpg' === $type or 'image/pjpg' === $type or 'image/pjpeg' === $type) {
imagejpeg($pic_new_im, $pic);
imagejpeg($thumb_new_im, $thumb);
} elseif ('image/png' === $type) {
imagepng($pic_new_im, $pic);
imagepng($thumb_new_im, $thumb);
} elseif ('image/gif' === $type) {
imagegif($pic_new_im, $pic);
imagegif($thumb_new_im, $thumb);
}
imagedestroy($pic_new_im);
imagedestroy($thumb_new_im);
echo XOOPS_URL . "/uploads/{$subdir}{$thumbs_dir}/{$filename}";
function rotate_right90($im)
{
$wid = imagesx($im);
$hei = imagesy($im);
$im2 = imagecreatetruecolor($hei, $wid);
for ($i = 0; $i < $wid; $i++) {
for ($j = 0; $j < $hei; $j++) {
$ref = imagecolorat($im, $i, $j);
imagesetpixel($im2, $hei - $j, $i, $ref);
}
}
return $im2;
}
function rotate_left90($im)
{
$wid = imagesx($im);
$hei = imagesy($im);
$im2 = imagecreatetruecolor($hei, $wid);
for ($i = 0; $i < $wid; $i++) {
for ($j = 0; $j < $hei; $j++) {
$ref = imagecolorat($im, $i, $j);
imagesetpixel($im2, $j, $wid - $i, $ref);
}
}
return $im2;
}
function mirror($im)
{
$wid = imagesx($im);
$hei = imagesy($im);
$im2 = imagecreatetruecolor($wid, $hei);
for ($i = 0; $i < $wid; $i++) {
for ($j = 0; $j < $hei; $j++) {
$ref = imagecolorat($im, $i, $j);
imagesetpixel($im2, $wid - $i, $j, $ref);
}
}
return $im2;
}
function flip($im)
{
$wid = imagesx($im);
$hei = imagesy($im);
$im2 = imagecreatetruecolor($wid, $hei);
for ($i = 0; $i < $wid; $i++) {
for ($j = 0; $j < $hei; $j++) {
$ref = imagecolorat($im, $i, $j);
imagesetpixel($im2, $i, $hei - $j, $ref);
}
}
return $im2;
}