1 | <?php |
---|
2 | |
---|
3 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
4 | |
---|
5 | function get_image_with_band($srcImage) |
---|
6 | { |
---|
7 | $srcWidth = imagesx($srcImage); |
---|
8 | $srcHeight = imagesy($srcImage); |
---|
9 | $const = intval($srcWidth * 0.04); |
---|
10 | |
---|
11 | $imgBand = imagecreatetruecolor($srcWidth + 6 * $const, $srcHeight); |
---|
12 | |
---|
13 | $white = imagecolorallocate($imgBand, 255, 255, 255); |
---|
14 | $y_start = intval($srcHeight / 2); |
---|
15 | $aug = intval($y_start / 4) + 1; |
---|
16 | $i = 0; |
---|
17 | |
---|
18 | while ($y_start + $i * $aug < $srcHeight - $const) |
---|
19 | { |
---|
20 | imagefilledrectangle($imgBand, $const, $y_start + $i * $aug - ($const / 2), 2 * $const - 1, $y_start + $i * $aug + ($const / 2) - 1, $white); |
---|
21 | imagefilledrectangle($imgBand, $const, $y_start - $i * $aug - ($const / 2), 2 * $const - 1, $y_start - $i * $aug + ($const / 2) - 1, $white); |
---|
22 | |
---|
23 | imagefilledrectangle($imgBand, $srcWidth + (4 * $const), $y_start + $i * $aug - ($const / 2), $srcWidth + (5 * $const) - 1, $y_start + $i * $aug + ($const / 2) - 1, $white); |
---|
24 | imagefilledrectangle($imgBand, $srcWidth + (4 * $const), $y_start - $i * $aug - ($const / 2), $srcWidth + (5 * $const) - 1, $y_start - $i * $aug + ($const / 2) - 1, $white); |
---|
25 | |
---|
26 | ++$i; |
---|
27 | } |
---|
28 | |
---|
29 | imagecopy($imgBand, $srcImage, 3 * $const, 0, 0, 0, $srcWidth, $srcHeight); |
---|
30 | return $imgBand; |
---|
31 | } |
---|
32 | |
---|
33 | function Py_RatioResizeImg($url, $path, $newWidth, $newHeight) |
---|
34 | { |
---|
35 | global $conf, $lang, $page; |
---|
36 | |
---|
37 | if (!function_exists('gd_info')) |
---|
38 | { |
---|
39 | return false; |
---|
40 | } |
---|
41 | |
---|
42 | $tempfile = $url; |
---|
43 | if (url_is_remote($url)) |
---|
44 | { |
---|
45 | $tempfile = tempnam($path, 'jpg'); |
---|
46 | fetchRemote($url, $tempfile_content); |
---|
47 | file_put_contents($tempfile, $tempfile_content); |
---|
48 | } |
---|
49 | |
---|
50 | list($width, $height, $type) = getimagesize($tempfile); |
---|
51 | if (IMAGETYPE_PNG == $type) |
---|
52 | { |
---|
53 | $srcImage = imagecreatefrompng($tempfile); |
---|
54 | } |
---|
55 | else |
---|
56 | { |
---|
57 | $srcImage = imagecreatefromjpeg($tempfile); |
---|
58 | } |
---|
59 | |
---|
60 | unlink($tempfile); |
---|
61 | |
---|
62 | if (isset($_POST['add_band'])) |
---|
63 | { |
---|
64 | $srcImage = get_image_with_band($srcImage); |
---|
65 | } |
---|
66 | |
---|
67 | $srcWidth = imagesx($srcImage); |
---|
68 | $srcHeight = imagesy($srcImage); |
---|
69 | |
---|
70 | if (isset($_POST['thumb_resize'])) |
---|
71 | { |
---|
72 | $ratioWidth = $srcWidth / $newWidth; |
---|
73 | $ratioHeight = $srcHeight / $newHeight; |
---|
74 | if ($ratioWidth < $ratioHeight) |
---|
75 | { |
---|
76 | $destWidth = $srcWidth / $ratioHeight; |
---|
77 | $destHigh = $newHeight; |
---|
78 | } |
---|
79 | else |
---|
80 | { |
---|
81 | $destWidth = $newWidth; |
---|
82 | $destHigh = $srcHeight / $ratioWidth; |
---|
83 | } |
---|
84 | } |
---|
85 | else |
---|
86 | { |
---|
87 | $destWidth = $srcWidth; |
---|
88 | $destHigh = $srcHeight; |
---|
89 | } |
---|
90 | |
---|
91 | $destImage = imagecreatetruecolor($destWidth, $destHigh); |
---|
92 | |
---|
93 | imagecopyresampled( |
---|
94 | $destImage, |
---|
95 | $srcImage, |
---|
96 | 0, |
---|
97 | 0, |
---|
98 | 0, |
---|
99 | 0, |
---|
100 | $destWidth, |
---|
101 | $destHigh, |
---|
102 | $srcWidth, |
---|
103 | $srcHeight |
---|
104 | ); |
---|
105 | |
---|
106 | if (IMAGETYPE_PNG == $type) |
---|
107 | { |
---|
108 | imagepng($destImage, $path); |
---|
109 | } |
---|
110 | else |
---|
111 | { |
---|
112 | imagejpeg($destImage, $path, 95); |
---|
113 | } |
---|
114 | |
---|
115 | imagedestroy($srcImage); |
---|
116 | imagedestroy($destImage); |
---|
117 | return true; |
---|
118 | } |
---|
119 | |
---|
120 | // Récupération de la miniature depuis le serveur |
---|
121 | if ($_POST['thumbnail'] == 'thumb_from_server') |
---|
122 | { |
---|
123 | $video['thumb_url'] = str_replace('&', '&', $video['thumb_url']); |
---|
124 | if (($thumb_dir = mkget_thumbnail_dir(dirname($file_path), $error)) == false) |
---|
125 | { |
---|
126 | array_push($page['errors'], l10n('py_error9')); |
---|
127 | } |
---|
128 | else |
---|
129 | { |
---|
130 | $thumb_path = file_path_for_type($file_path, 'thumb'); |
---|
131 | if (file_exists($thumb_path)) |
---|
132 | { |
---|
133 | array_push($page['errors'], sprintf(l10n('py_error11'), $path), l10n('py_error9')); |
---|
134 | } |
---|
135 | else |
---|
136 | { |
---|
137 | if (Py_RatioResizeImg($video['thumb_url'], $thumb_path, $_POST['thumb_width'], $_POST['thumb_hight'])) |
---|
138 | { |
---|
139 | array_push($page['infos'], l10n('py_info2')); |
---|
140 | $thumb_extension = 'jpg'; |
---|
141 | } |
---|
142 | else |
---|
143 | { |
---|
144 | array_push($page['errors'], l10n('py_error9')); |
---|
145 | } |
---|
146 | } |
---|
147 | } |
---|
148 | } |
---|
149 | |
---|
150 | // Upload de la miniature par l'utilisateur |
---|
151 | if ($_POST['thumbnail'] == 'thumb_from_user') |
---|
152 | { |
---|
153 | if (empty($_FILES['picture']['size'])) |
---|
154 | { |
---|
155 | array_push($page['infos'], l10n('py_error12')); |
---|
156 | } |
---|
157 | else |
---|
158 | { |
---|
159 | $ext = get_extension($_FILES['picture']['name']); |
---|
160 | if (($thumb_dir = mkget_thumbnail_dir(dirname($file_path), $error)) == false) |
---|
161 | { |
---|
162 | array_push($page['errors'], l10n('py_error9')); |
---|
163 | } |
---|
164 | else |
---|
165 | { |
---|
166 | $thumb_path = get_filename_wo_extension(file_path_for_type($file_path, 'thumb')).'.'.$ext; |
---|
167 | if (file_exists($thumb_path)) |
---|
168 | { |
---|
169 | array_push($page['errors'], sprintf(l10n('py_error11'), $thumb_path), l10n('py_error9')); |
---|
170 | } |
---|
171 | else |
---|
172 | { |
---|
173 | if (Py_RatioResizeImg($_FILES['picture']['tmp_name'], $thumb_path, $_POST['thumb_width'], $_POST['thumb_hight'])) |
---|
174 | { |
---|
175 | $thumb_extension = $ext; |
---|
176 | array_push($page['infos'], l10n('py_info2')); |
---|
177 | } |
---|
178 | else |
---|
179 | { |
---|
180 | array_push($page['errors'], l10n('py_error9')); |
---|
181 | } |
---|
182 | } |
---|
183 | } |
---|
184 | } |
---|
185 | } |
---|
186 | |
---|
187 | ?> |
---|