1
|
|
|
<?php |
2
|
|
|
// +------------------------------------------------------------------------+ |
3
|
|
|
// | class.upload.php | |
4
|
|
|
// +------------------------------------------------------------------------+ |
5
|
|
|
// | Copyright (c) Colin Verot 2003-2010. All rights reserved. | |
6
|
|
|
// | Version 0.31 | |
7
|
|
|
// | Last modified 11/04/2011 | |
8
|
|
|
// | Email [email protected] | |
9
|
|
|
// | Web http://www.verot.net | |
10
|
|
|
// +------------------------------------------------------------------------+ |
11
|
|
|
// | This program is free software; you can redistribute it and/or modify | |
12
|
|
|
// | it under the terms of the GNU General Public License version 2 as | |
13
|
|
|
// | published by the Free Software Foundation. | |
14
|
|
|
// | | |
15
|
|
|
// | This program is distributed in the hope that it will be useful, | |
16
|
|
|
// | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17
|
|
|
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18
|
|
|
// | GNU General Public License for more details. | |
19
|
|
|
// | | |
20
|
|
|
// | You should have received a copy of the GNU General Public License | |
21
|
|
|
// | along with this program; if not, write to the | |
22
|
|
|
// | Free Software Foundation, Inc., 59 Temple Place, Suite 330, | |
23
|
|
|
// | Boston, MA 02111-1307 USA | |
24
|
|
|
// | | |
25
|
|
|
// | Please give credit on sites that use class.upload and submit changes | |
26
|
|
|
// | of the script so other people can use them as well. | |
27
|
|
|
// | This script is free to use, don't abuse. | |
28
|
|
|
// +------------------------------------------------------------------------+ |
29
|
|
|
// |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Class upload |
33
|
|
|
* |
34
|
|
|
* @version 0.31 |
35
|
|
|
* @author Colin Verot <[email protected]> |
36
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
37
|
|
|
* @copyright Colin Verot |
38
|
|
|
* @package cmf |
39
|
|
|
* @subpackage external |
40
|
|
|
*/ |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Class upload |
44
|
|
|
* |
45
|
|
|
* <b>What does it do?</b> |
46
|
|
|
* |
47
|
|
|
* It manages file uploads for you. In short, it manages the uploaded file, |
48
|
|
|
* and allows you to do whatever you want with the file, especially if it |
49
|
|
|
* is an image, and as many times as you want. |
50
|
|
|
* |
51
|
|
|
* It is the ideal class to quickly integrate file upload in your site. |
52
|
|
|
* If the file is an image, you can convert, resize, crop it in many ways. |
53
|
|
|
* You can also apply filters, add borders, text, watermarks, etc... |
54
|
|
|
* That's all you need for a gallery script for instance. Supported formats |
55
|
|
|
* are PNG, JPG, GIF and BMP. |
56
|
|
|
* |
57
|
|
|
* You can also use the class to work on local files, which is especially |
58
|
|
|
* useful to use the image manipulation features. The class also supports |
59
|
|
|
* Flash uploaders. |
60
|
|
|
* |
61
|
|
|
* The class works with PHP 4 and 5, and its error messages can |
62
|
|
|
* be localized at will. |
63
|
|
|
* |
64
|
|
|
* <b>How does it work?</b> |
65
|
|
|
* |
66
|
|
|
* You instanciate the class with the $_FILES['my_field'] array |
67
|
|
|
* where my_field is the field name from your upload form. |
68
|
|
|
* The class will check if the original file has been uploaded |
69
|
|
|
* to its temporary location (alternatively, you can instanciate |
70
|
|
|
* the class with a local filename). |
71
|
|
|
* |
72
|
|
|
* You can then set a number of processing variables to act on the file. |
73
|
|
|
* For instance, you can rename the file, and if it is an image, |
74
|
|
|
* convert and resize it in many ways. |
75
|
|
|
* You can also set what will the class do if the file already exists. |
76
|
|
|
* |
77
|
|
|
* Then you call the function {@link process} to actually perform the actions |
78
|
|
|
* according to the processing parameters you set above. |
79
|
|
|
* It will create new instances of the original file, |
80
|
|
|
* so the original file remains the same between each process. |
81
|
|
|
* The file will be manipulated, and copied to the given location. |
82
|
|
|
* The processing variables will be reset once it is done. |
83
|
|
|
* |
84
|
|
|
* You can repeat setting up a new set of processing variables, |
85
|
|
|
* and calling {@link process} again as many times as you want. |
86
|
|
|
* When you have finished, you can call {@link clean} to delete |
87
|
|
|
* the original uploaded file. |
88
|
|
|
* |
89
|
|
|
* If you don't set any processing parameters and call {@link process} |
90
|
|
|
* just after instanciating the class. The uploaded file will be simply |
91
|
|
|
* copied to the given location without any alteration or checks. |
92
|
|
|
* |
93
|
|
|
* Don't forget to add <i>enctype="multipart/form-data"</i> in your form |
94
|
|
|
* tag <form> if you want your form to upload the file. |
95
|
|
|
* |
96
|
|
|
* <b>How to use it?</b><br> |
97
|
|
|
* Create a simple HTML file, with a form such as: |
98
|
|
|
* <pre> |
99
|
|
|
* <form enctype="multipart/form-data" method="post" action="upload.php"> |
100
|
|
|
* <input type="file" size="32" name="image_field" value=""> |
101
|
|
|
* <input type="submit" name="Submit" value="upload"> |
102
|
|
|
* </form> |
103
|
|
|
* </pre> |
104
|
|
|
* Create a file called upload.php: |
105
|
|
|
* <pre> |
106
|
|
|
* $handle = new upload($_FILES['image_field']); |
107
|
|
|
* if ($handle->uploaded) { |
108
|
|
|
* $handle->file_new_name_body = 'image_resized'; |
109
|
|
|
* $handle->image_resize = true; |
110
|
|
|
* $handle->image_x = 100; |
111
|
|
|
* $handle->image_ratio_y = true; |
112
|
|
|
* $handle->process('/home/user/files/'); |
113
|
|
|
* if ($handle->processed) { |
114
|
|
|
* echo 'image resized'; |
115
|
|
|
* $handle->clean(); |
116
|
|
|
* } else { |
117
|
|
|
* echo 'error : ' . $handle->error; |
118
|
|
|
* } |
119
|
|
|
* } |
120
|
|
|
* </pre> |
121
|
|
|
* |
122
|
|
|
* <b>How to process local files?</b><br> |
123
|
|
|
* Use the class as following, the rest being the same as above: |
124
|
|
|
* <pre> |
125
|
|
|
* $handle = new upload('/home/user/myfile.jpg'); |
126
|
|
|
* </pre> |
127
|
|
|
* |
128
|
|
|
* <b>How to set the language?</b><br> |
129
|
|
|
* Instantiate the class with a second argument being the language code: |
130
|
|
|
* <pre> |
131
|
|
|
* $handle = new upload($_FILES['image_field'], 'fr_FR'); |
132
|
|
|
* $handle = new upload('/home/user/myfile.jpg', 'fr_FR'); |
133
|
|
|
* </pre> |
134
|
|
|
* |
135
|
|
|
* <b>How to output the resulting file or picture directly to the browser?</b><br> |
136
|
|
|
* Simply call {@link process}() without an argument (or with null as first argument): |
137
|
|
|
* <pre> |
138
|
|
|
* $handle = new upload($_FILES['image_field']); |
139
|
|
|
* header('Content-type: ' . $handle->file_src_mime); |
140
|
|
|
* echo $handle->Process(); |
141
|
|
|
* die(); |
142
|
|
|
* </pre> |
143
|
|
|
* Or if you want to force the download of the file: |
144
|
|
|
* <pre> |
145
|
|
|
* $handle = new upload($_FILES['image_field']); |
146
|
|
|
* header('Content-type: ' . $handle->file_src_mime); |
147
|
|
|
* header("Content-Disposition: attachment; filename=".rawurlencode($handle->file_src_name).";"); |
148
|
|
|
* echo $handle->Process(); |
149
|
|
|
* die(); |
150
|
|
|
* </pre> |
151
|
|
|
* |
152
|
|
|
* <b>Processing parameters</b> (reset after each process) |
153
|
|
|
* <ul> |
154
|
|
|
* <li><b>{@link file_new_name_body}</b> replaces the name body (default: null)<br> |
155
|
|
|
* <pre>$handle->file_new_name_body = 'new name';</pre></li> |
156
|
|
|
* <li><b>{@link file_name_body_add}</b> appends to the name body (default: null)<br> |
157
|
|
|
* <pre>$handle->file_name_body_add = '_uploaded';</pre></li> |
158
|
|
|
* <li><b>{@link file_name_body_pre}</b> prepends to the name body (default: null)<br> |
159
|
|
|
* <pre>$handle->file_name_body_pre = 'thumb_';</pre></li> |
160
|
|
|
* <li><b>{@link file_new_name_ext}</b> replaces the file extension (default: null)<br> |
161
|
|
|
* <pre>$handle->file_new_name_ext = 'txt';</pre></li> |
162
|
|
|
* <li><b>{@link file_safe_name}</b> formats the filename (spaces changed to _) (default: true)<br> |
163
|
|
|
* <pre>$handle->file_safe_name = true;</pre></li> |
164
|
|
|
* <li><b>{@link file_force_extension}</b> forces an extension if there is't any (default: true)<br> |
165
|
|
|
* <pre>$handle->file_force_extension = true;</pre></li> |
166
|
|
|
* <li><b>{@link file_overwrite}</b> sets behaviour if file already exists (default: false)<br> |
167
|
|
|
* <pre>$handle->file_overwrite = true;</pre></li> |
168
|
|
|
* <li><b>{@link file_auto_rename}</b> automatically renames file if it already exists (default: true)<br> |
169
|
|
|
* <pre>$handle->file_auto_rename = true;</pre></li> |
170
|
|
|
* <li><b>{@link dir_auto_create}</b> automatically creates destination directory if missing (default: true)<br> |
171
|
|
|
* <pre>$handle->auto_create_dir = true;</pre></li> |
172
|
|
|
* <li><b>{@link dir_auto_chmod}</b> automatically attempts to chmod the destination directory if not writeable (default: true)<br> |
173
|
|
|
* <pre>$handle->dir_auto_chmod = true;</pre></li> |
174
|
|
|
* <li><b>{@link dir_chmod}</b> chmod used when creating directory or if directory not writeable (default: 0777)<br> |
175
|
|
|
* <pre>$handle->dir_chmod = 0777;</pre></li> |
176
|
|
|
* <li><b>{@link file_max_size}</b> sets maximum upload size (default: upload_max_filesize from php.ini)<br> |
177
|
|
|
* <pre>$handle->file_max_size = '1024'; // 1KB</pre></li> |
178
|
|
|
* <li><b>{@link mime_check}</b> sets if the class check the MIME against the {@link allowed} list (default: true)<br> |
179
|
|
|
* <pre>$handle->mime_check = true;</pre></li> |
180
|
|
|
* <li><b>{@link no_script}</b> sets if the class turns scripts into text files (default: true)<br> |
181
|
|
|
* <pre>$handle->no_script = false;</pre></li> |
182
|
|
|
* <li><b>{@link allowed}</b> array of allowed mime-types (or one string). wildcard accepted, as in image/* (default: check {@link Init})<br> |
183
|
|
|
* <pre>$handle->allowed = array('application/pdf','application/msword', 'image/*');</pre></li> |
184
|
|
|
* <li><b>{@link forbidden}</b> array of forbidden mime-types (or one string). wildcard accepted, as in image/* (default: check {@link Init})<br> |
185
|
|
|
* <pre>$handle->forbidden = array('application/*');</pre></li> |
186
|
|
|
* </ul> |
187
|
|
|
* <ul> |
188
|
|
|
* <li><b>{@link image_convert}</b> if set, image will be converted (possible values : ''|'png'|'jpeg'|'gif'|'bmp'; default: '')<br> |
189
|
|
|
* <pre>$handle->image_convert = 'jpg';</pre></li> |
190
|
|
|
* <li><b>{@link image_background_color}</b> if set, will forcibly fill transparent areas with the color, in hexadecimal (default: null)<br> |
191
|
|
|
* <pre>$handle->image_background_color = '#FF00FF';</pre></li> |
192
|
|
|
* <li><b>{@link image_default_color}</b> fallback color background color for non alpha-transparent output formats, such as JPEG or BMP, in hexadecimal (default: #FFFFFF)<br> |
193
|
|
|
* <pre>$handle->image_default_color = '#FF00FF';</pre></li> |
194
|
|
|
* <li><b>{@link jpeg_quality}</b> sets the compression quality for JPEG images (default: 85)<br> |
195
|
|
|
* <pre>$handle->jpeg_quality = 50;</pre></li> |
196
|
|
|
* <li><b>{@link jpeg_size}</b> if set to a size in bytes, will approximate {@link jpeg_quality} so the output image fits within the size (default: null)<br> |
197
|
|
|
* <pre>$handle->jpeg_size = 3072;</pre></li> |
198
|
|
|
* </ul> |
199
|
|
|
* The following eight settings can be used to invalidate an upload if the file is an image (note that <i>open_basedir</i> restrictions prevent the use of these settings) |
200
|
|
|
* <ul> |
201
|
|
|
* <li><b>{@link image_max_width}</b> if set to a dimension in pixels, the upload will be invalid if the image width is greater (default: null)<br> |
202
|
|
|
* <pre>$handle->image_max_width = 200;</pre></li> |
203
|
|
|
* <li><b>{@link image_max_height}</b> if set to a dimension in pixels, the upload will be invalid if the image height is greater (default: null)<br> |
204
|
|
|
* <pre>$handle->image_max_height = 100;</pre></li> |
205
|
|
|
* <li><b>{@link image_max_pixels}</b> if set to a number of pixels, the upload will be invalid if the image number of pixels is greater (default: null)<br> |
206
|
|
|
* <pre>$handle->image_max_pixels = 50000;</pre></li> |
207
|
|
|
* <li><b>{@link image_max_ratio}</b> if set to a aspect ratio (width/height), the upload will be invalid if the image apect ratio is greater (default: null)<br> |
208
|
|
|
* <pre>$handle->image_max_ratio = 1.5;</pre></li> |
209
|
|
|
* <li><b>{@link image_min_width}</b> if set to a dimension in pixels, the upload will be invalid if the image width is lower (default: null)<br> |
210
|
|
|
* <pre>$handle->image_min_width = 100;</pre></li> |
211
|
|
|
* <li><b>{@link image_min_height}</b> if set to a dimension in pixels, the upload will be invalid if the image height is lower (default: null)<br> |
212
|
|
|
* <pre>$handle->image_min_height = 500;</pre></li> |
213
|
|
|
* <li><b>{@link image_min_pixels}</b> if set to a number of pixels, the upload will be invalid if the image number of pixels is lower (default: null)<br> |
214
|
|
|
* <pre>$handle->image_min_pixels = 20000;</pre></li> |
215
|
|
|
* <li><b>{@link image_min_ratio}</b> if set to a aspect ratio (width/height), the upload will be invalid if the image apect ratio is lower (default: null)<br> |
216
|
|
|
* <pre>$handle->image_min_ratio = 0.5;</pre></li> |
217
|
|
|
* </ul> |
218
|
|
|
* <ul> |
219
|
|
|
* <li><b>{@link image_resize}</b> determines is an image will be resized (default: false)<br> |
220
|
|
|
* <pre>$handle->image_resize = true;</pre></li> |
221
|
|
|
* </ul> |
222
|
|
|
* The following variables are used only if {@link image_resize} == true |
223
|
|
|
* <ul> |
224
|
|
|
* <li><b>{@link image_x}</b> destination image width (default: 150)<br> |
225
|
|
|
* <pre>$handle->image_x = 100;</pre></li> |
226
|
|
|
* <li><b>{@link image_y}</b> destination image height (default: 150)<br> |
227
|
|
|
* <pre>$handle->image_y = 200;</pre></li> |
228
|
|
|
* </ul> |
229
|
|
|
* Use either one of the following |
230
|
|
|
* <ul> |
231
|
|
|
* <li><b>{@link image_ratio}</b> if true, resize image conserving the original sizes ratio, using {@link image_x} AND {@link image_y} as max sizes if true (default: false)<br> |
232
|
|
|
* <pre>$handle->image_ratio = true;</pre></li> |
233
|
|
|
* <li><b>{@link image_ratio_crop}</b> if true, resize image conserving the original sizes ratio, using {@link image_x} AND {@link image_y} as max sizes, and cropping excedent to fill the space. setting can also be a string, with one or more from 'TBLR', indicating which side of the image will be kept while cropping (default: false)<br> |
234
|
|
|
* <pre>$handle->image_ratio_crop = true;</pre></li> |
235
|
|
|
* <li><b>{@link image_ratio_fill}</b> if true, resize image conserving the original sizes ratio, using {@link image_x} AND {@link image_y} as max sizes, fitting the image in the space and coloring the remaining space. setting can also be a string, with one or more from 'TBLR', indicating which side of the space the image will be in (default: false)<br> |
236
|
|
|
* <pre>$handle->image_ratio_fill = true;</pre></li> |
237
|
|
|
* <li><b>{@link image_ratio_no_zoom_in}</b> same as {@link image_ratio}, but won't resize if the source image is smaller than {@link image_x} x {@link image_y} (default: false)<br> |
238
|
|
|
* <pre>$handle->image_ratio_no_zoom_in = true;</pre></li> |
239
|
|
|
* <li><b>{@link image_ratio_no_zoom_out}</b> same as {@link image_ratio}, but won't resize if the source image is bigger than {@link image_x} x {@link image_y} (default: false)<br> |
240
|
|
|
* <pre>$handle->image_ratio_no_zoom_out = true;</pre></li> |
241
|
|
|
* <li><b>{@link image_ratio_x}</b> if true, resize image, calculating {@link image_x} from {@link image_y} and conserving the original sizes ratio (default: false)<br> |
242
|
|
|
* <pre>$handle->image_ratio_x = true;</pre></li> |
243
|
|
|
* <li><b>{@link image_ratio_y}</b> if true, resize image, calculating {@link image_y} from {@link image_x} and conserving the original sizes ratio (default: false)<br> |
244
|
|
|
* <pre>$handle->image_ratio_y = true;</pre></li> |
245
|
|
|
* <li><b>{@link image_ratio_pixels}</b> if set to a long integer, resize image, calculating {@link image_y} and {@link image_x} to match a the number of pixels (default: false)<br> |
246
|
|
|
* <pre>$handle->image_ratio_pixels = 25000;</pre></li> |
247
|
|
|
* </ul> |
248
|
|
|
* The following image manipulations require GD2+ |
249
|
|
|
* <ul> |
250
|
|
|
* <li><b>{@link image_brightness}</b> if set, corrects the brightness. value between -127 and 127 (default: null)<br> |
251
|
|
|
* <pre>$handle->image_brightness = 40;</pre></li> |
252
|
|
|
* <li><b>{@link image_contrast}</b> if set, corrects the contrast. value between -127 and 127 (default: null)<br> |
253
|
|
|
* <pre>$handle->image_contrast = 50;</pre></li> |
254
|
|
|
* <li><b>{@link image_opacity}</b> if set, changes the image opacity. value between 0 and 100 (default: null)<br> |
255
|
|
|
* <pre>$handle->image_opacity = 50;</pre></li> |
256
|
|
|
* <li><b>{@link image_tint_color}</b> if set, will tint the image with a color, value as hexadecimal #FFFFFF (default: null)<br> |
257
|
|
|
* <pre>$handle->image_tint_color = '#FF0000';</pre></li> |
258
|
|
|
* <li><b>{@link image_overlay_color}</b> if set, will add a colored overlay, value as hexadecimal #FFFFFF (default: null)<br> |
259
|
|
|
* <pre>$handle->image_overlay_color = '#FF0000';</pre></li> |
260
|
|
|
* <li><b>{@link image_overlay_opacity}</b> used when {@link image_overlay_color} is set, determines the opacity (default: 50)<br> |
261
|
|
|
* <pre>$handle->image_overlay_opacity = 20;</pre></li> |
262
|
|
|
* <li><b>{@link image_negative}</b> inverts the colors in the image (default: false)<br> |
263
|
|
|
* <pre>$handle->image_negative = true;</pre></li> |
264
|
|
|
* <li><b>{@link image_greyscale}</b> transforms an image into greyscale (default: false)<br> |
265
|
|
|
* <pre>$handle->image_greyscale = true;</pre></li> |
266
|
|
|
* <li><b>{@link image_threshold}</b> applies a threshold filter. value between -127 and 127 (default: null)<br> |
267
|
|
|
* <pre>$handle->image_threshold = 20;</pre></li> |
268
|
|
|
* <li><b>{@link image_unsharp}</b> applies an unsharp mask, with alpha transparency support (default: false)<br> |
269
|
|
|
* <pre>$handle->image_unsharp = true;</pre></li> |
270
|
|
|
* <li><b>{@link image_unsharp_amount}</b> unsharp mask amount, typically 50 - 200 (default: 80)<br> |
271
|
|
|
* <pre>$handle->image_unsharp_amount = 120;</pre></li> |
272
|
|
|
* <li><b>{@link image_unsharp_radius}</b> unsharp mask radius, typically 0.5 - 1 (default: 0.5)<br> |
273
|
|
|
* <pre>$handle->image_unsharp_radius = 0.8;</pre></li> |
274
|
|
|
* <li><b>{@link image_unsharp_threshold}</b> unsharp mask threshold, typically 0 - 5 (default: 1)<br> |
275
|
|
|
* <pre>$handle->image_unsharp_threshold = 0;</pre></li> |
276
|
|
|
* </ul> |
277
|
|
|
* <ul> |
278
|
|
|
* <li><b>{@link image_text}</b> creates a text label on the image, value is a string, with eventual replacement tokens (default: null)<br> |
279
|
|
|
* <pre>$handle->image_text = 'test';</pre></li> |
280
|
|
|
* <li><b>{@link image_text_direction}</b> text label direction, either 'h' horizontal or 'v' vertical (default: 'h')<br> |
281
|
|
|
* <pre>$handle->image_text_direction = 'v';</pre></li> |
282
|
|
|
* <li><b>{@link image_text_color}</b> text color for the text label, in hexadecimal (default: #FFFFFF)<br> |
283
|
|
|
* <pre>$handle->image_text_color = '#FF0000';</pre></li> |
284
|
|
|
* <li><b>{@link image_text_opacity}</b> text opacity on the text label, integer between 0 and 100 (default: 100)<br> |
285
|
|
|
* <pre>$handle->image_text_opacity = 50;</pre></li> |
286
|
|
|
* <li><b>{@link image_text_background}</b> text label background color, in hexadecimal (default: null)<br> |
287
|
|
|
* <pre>$handle->image_text_background = '#FFFFFF';</pre></li> |
288
|
|
|
* <li><b>{@link image_text_background_opacity}</b> text label background opacity, integer between 0 and 100 (default: 100)<br> |
289
|
|
|
* <pre>$handle->image_text_background_opacity = 50;</pre></li> |
290
|
|
|
* <li><b>{@link image_text_font}</b> built-in font for the text label, from 1 to 5. 1 is the smallest (default: 5)<br> |
291
|
|
|
* <pre>$handle->image_text_font = 4;</pre></li> |
292
|
|
|
* <li><b>{@link image_text_x}</b> absolute text label position, in pixels from the left border. can be negative (default: null)<br> |
293
|
|
|
* <pre>$handle->image_text_x = 5;</pre></li> |
294
|
|
|
* <li><b>{@link image_text_y}</b> absolute text label position, in pixels from the top border. can be negative (default: null)<br> |
295
|
|
|
* <pre>$handle->image_text_y = 5;</pre></li> |
296
|
|
|
* <li><b>{@link image_text_position}</b> text label position withing the image, a combination of one or two from 'TBLR': top, bottom, left, right (default: null)<br> |
297
|
|
|
* <pre>$handle->image_text_position = 'LR';</pre></li> |
298
|
|
|
* <li><b>{@link image_text_padding}</b> text label padding, in pixels. can be overridden by {@link image_text_padding_x} and {@link image_text_padding_y} (default: 0)<br> |
299
|
|
|
* <pre>$handle->image_text_padding = 5;</pre></li> |
300
|
|
|
* <li><b>{@link image_text_padding_x}</b> text label horizontal padding (default: null)<br> |
301
|
|
|
* <pre>$handle->image_text_padding_x = 2;</pre></li> |
302
|
|
|
* <li><b>{@link image_text_padding_y}</b> text label vertical padding (default: null)<br> |
303
|
|
|
* <pre>$handle->image_text_padding_y = 10;</pre></li> |
304
|
|
|
* <li><b>{@link image_text_alignment}</b> text alignment when text has multiple lines, either 'L', 'C' or 'R' (default: 'C')<br> |
305
|
|
|
* <pre>$handle->image_text_alignment = 'R';</pre></li> |
306
|
|
|
* <li><b>{@link image_text_line_spacing}</b> space between lines in pixels, when text has multiple lines (default: 0)<br> |
307
|
|
|
* <pre>$handle->image_text_line_spacing = 3;</pre></li> |
308
|
|
|
* </ul> |
309
|
|
|
* <ul> |
310
|
|
|
* <li><b>{@link image_flip}</b> flips image, wither 'h' horizontal or 'v' vertical (default: null)<br> |
311
|
|
|
* <pre>$handle->image_flip = 'h';</pre></li> |
312
|
|
|
* <li><b>{@link image_rotate}</b> rotates image. possible values are 90, 180 and 270 (default: null)<br> |
313
|
|
|
* <pre>$handle->image_rotate = 90;</pre></li> |
314
|
|
|
* <li><b>{@link image_crop}</b> crops image. accepts 4, 2 or 1 values as 'T R B L' or 'TB LR' or 'TBLR'. dimension can be 20, or 20px or 20% (default: null)<br> |
315
|
|
|
* <pre>$handle->image_crop = array(50,40,30,20); OR '-20 20%'...</pre></li> |
316
|
|
|
* <li><b>{@link image_precrop}</b> crops image, before an eventual resizing. accepts 4, 2 or 1 values as 'T R B L' or 'TB LR' or 'TBLR'. dimension can be 20, or 20px or 20% (default: null)<br> |
317
|
|
|
* <pre>$handle->image_precrop = array(50,40,30,20); OR '-20 20%'...</pre></li> |
318
|
|
|
* </ul> |
319
|
|
|
* <ul> |
320
|
|
|
* <li><b>{@link image_bevel}</b> adds a bevel border to the image. value is thickness in pixels (default: null)<br> |
321
|
|
|
* <pre>$handle->image_bevel = 20;</pre></li> |
322
|
|
|
* <li><b>{@link image_bevel_color1}</b> top and left bevel color, in hexadecimal (default: #FFFFFF)<br> |
323
|
|
|
* <pre>$handle->image_bevel_color1 = '#FFFFFF';</pre></li> |
324
|
|
|
* <li><b>{@link image_bevel_color2}</b> bottom and right bevel color, in hexadecimal (default: #000000)<br> |
325
|
|
|
* <pre>$handle->image_bevel_color2 = '#000000';</pre></li> |
326
|
|
|
* <li><b>{@link image_border}</b> adds a unicolor border to the image. accepts 4, 2 or 1 values as 'T R B L' or 'TB LR' or 'TBLR'. dimension can be 20, or 20px or 20% (default: null)<br> |
327
|
|
|
* <pre>$handle->image_border = '3px'; OR '-20 20%' OR array(3,2)...</pre></li> |
328
|
|
|
* <li><b>{@link image_border_color}</b> border color, in hexadecimal (default: #FFFFFF)<br> |
329
|
|
|
* <pre>$handle->image_border_color = '#FFFFFF';</pre></li> |
330
|
|
|
* <li><b>{@link image_border_opacity}</b> border opacity, integer between 0 and 100 (default: 100)<br> |
331
|
|
|
* <pre>$handle->image_border_opacity = 50;</pre></li> |
332
|
|
|
* <li><b>{@link image_border_transparent}</b> adds a fading-to-transparent border to the image. accepts 4, 2 or 1 values as 'T R B L' or 'TB LR' or 'TBLR'. dimension can be 20, or 20px or 20% (default: null)<br> |
333
|
|
|
* <pre>$handle->image_border_transparent = '3px'; OR '-20 20%' OR array(3,2)...</pre></li> |
334
|
|
|
* <li><b>{@link image_frame}</b> type of frame: 1=flat 2=crossed (default: null)<br> |
335
|
|
|
* <pre>$handle->image_frame = 2;</pre></li> |
336
|
|
|
* <li><b>{@link image_frame_colors}</b> list of hex colors, in an array or a space separated string (default: '#FFFFFF #999999 #666666 #000000')<br> |
337
|
|
|
* <pre>$handle->image_frame_colors = array('#999999', '#FF0000', '#666666', '#333333', '#000000');</pre></li> |
338
|
|
|
* <li><b>{@link image_frame_opacity}</b> frame opacity, integer between 0 and 100 (default: 100)<br> |
339
|
|
|
* <pre>$handle->image_frame_opacity = 50;</pre></li> |
340
|
|
|
* </ul> |
341
|
|
|
* <ul> |
342
|
|
|
* <li><b>{@link image_watermark}</b> adds a watermark on the image, value is a local filename. accepted files are GIF, JPG, BMP, PNG and PNG alpha (default: null)<br> |
343
|
|
|
* <pre>$handle->image_watermark = 'watermark.png';</pre></li> |
344
|
|
|
* <li><b>{@link image_watermark_x}</b> absolute watermark position, in pixels from the left border. can be negative (default: null)<br> |
345
|
|
|
* <pre>$handle->image_watermark_x = 5;</pre></li> |
346
|
|
|
* <li><b>{@link image_watermark_y}</b> absolute watermark position, in pixels from the top border. can be negative (default: null)<br> |
347
|
|
|
* <pre>$handle->image_watermark_y = 5;</pre></li> |
348
|
|
|
* <li><b>{@link image_watermark_position}</b> watermark position withing the image, a combination of one or two from 'TBLR': top, bottom, left, right (default: null)<br> |
349
|
|
|
* <pre>$handle->image_watermark_position = 'LR';</pre></li> |
350
|
|
|
* <li><b>{@link image_watermark_no_zoom_in}</b> prevents the watermark to be resized up if it is smaller than the image (default: true)<br> |
351
|
|
|
* <pre>$handle->image_watermark_no_zoom_in = false;</pre></li> |
352
|
|
|
* <li><b>{@link image_watermark_no_zoom_out}</b> prevents the watermark to be resized down if it is bigger than the image (default: false)<br> |
353
|
|
|
* <pre>$handle->image_watermark_no_zoom_out = true;</pre></li> |
354
|
|
|
* </ul> |
355
|
|
|
* <ul> |
356
|
|
|
* <li><b>{@link image_reflection_height}</b> if set, a reflection will be added. Format is either in pixels or percentage, such as 40, '40', '40px' or '40%' (default: null)<br> |
357
|
|
|
* <pre>$handle->image_reflection_height = '25%';</pre></li> |
358
|
|
|
* <li><b>{@link image_reflection_space}</b> space in pixels between the source image and the reflection, can be negative (default: null)<br> |
359
|
|
|
* <pre>$handle->image_reflection_space = 3;</pre></li> |
360
|
|
|
* <li><b>{@link image_reflection_color}</b> reflection background color, in hexadecimal. Now deprecated in favor of {@link image_default_color} (default: #FFFFFF)<br> |
361
|
|
|
* <pre>$handle->image_default_color = '#000000';</pre></li> |
362
|
|
|
* <li><b>{@link image_reflection_opacity}</b> opacity level at which the reflection starts, integer between 0 and 100 (default: 60)<br> |
363
|
|
|
* <pre>$handle->image_reflection_opacity = 60;</pre></li> |
364
|
|
|
* </ul> |
365
|
|
|
* |
366
|
|
|
* <b>Values that can be read before calling {@link process}()</b> |
367
|
|
|
* <ul> |
368
|
|
|
* <li><b>{@link file_src_name}</b> Source file name</li> |
369
|
|
|
* <li><b>{@link file_src_name_body}</b> Source file name body</li> |
370
|
|
|
* <li><b>{@link file_src_name_ext}</b> Source file extension</li> |
371
|
|
|
* <li><b>{@link file_src_pathname}</b> Source file complete path and name</li> |
372
|
|
|
* <li><b>{@link file_src_mime}</b> Source file mime type</li> |
373
|
|
|
* <li><b>{@link file_src_size}</b> Source file size in bytes</li> |
374
|
|
|
* <li><b>{@link file_src_error}</b> Upload error code</li> |
375
|
|
|
* <li><b>{@link file_is_image}</b> Boolean flag, true if the file is a supported image type</li> |
376
|
|
|
* </ul> |
377
|
|
|
* If the file is a supported image type (and <i>open_basedir</i> restrictions allow it) |
378
|
|
|
* <ul> |
379
|
|
|
* <li><b>{@link image_src_x}</b> Source file width in pixels</li> |
380
|
|
|
* <li><b>{@link image_src_y}</b> Source file height in pixels</li> |
381
|
|
|
* <li><b>{@link image_src_pixels}</b> Source file number of pixels</li> |
382
|
|
|
* <li><b>{@link image_src_type}</b> Source file type (png, jpg, gif or bmp)</li> |
383
|
|
|
* <li><b>{@link image_src_bits}</b> Source file color depth</li> |
384
|
|
|
* </ul> |
385
|
|
|
* |
386
|
|
|
* <b>Values that can be read after calling {@link process}()</b> |
387
|
|
|
* <ul> |
388
|
|
|
* <li><b>{@link file_dst_path}</b> Destination file path</li> |
389
|
|
|
* <li><b>{@link file_dst_name_body}</b> Destination file name body</li> |
390
|
|
|
* <li><b>{@link file_dst_name_ext}</b> Destination file extension</li> |
391
|
|
|
* <li><b>{@link file_dst_name}</b> Destination file name</li> |
392
|
|
|
* <li><b>{@link file_dst_pathname}</b> Destination file complete path and name</li> |
393
|
|
|
* </ul> |
394
|
|
|
* If the file is a supported image type |
395
|
|
|
* <ul> |
396
|
|
|
* <li><b>{@link image_dst_x}</b> Destination file width</li> |
397
|
|
|
* <li><b>{@link image_dst_y}</b> Destination file height</li> |
398
|
|
|
* <li><b>{@link image_convert}</b> Destination file format</li> |
399
|
|
|
* </ul> |
400
|
|
|
* |
401
|
|
|
* <b>Requirements</b> |
402
|
|
|
* |
403
|
|
|
* Most of the image operations require GD. GD2 is greatly recommended |
404
|
|
|
* |
405
|
|
|
* The class is compatible with PHP 4.3+, and compatible with PHP5 |
406
|
|
|
* |
407
|
|
|
* <b>Changelog</b> |
408
|
|
|
* <ul> |
409
|
|
|
* <li><b>v 0.31</b> 11/04/2011<br> |
410
|
|
|
* - added application/x-rar MIME type<br> |
411
|
|
|
* - make sure exec() and ini_get_all()function are not disabled if we want to use them<br> |
412
|
|
|
* - make sure that we don't divide by zero when calculating JPEG size<br> |
413
|
|
|
* - {@link allowed} and {@link forbidden} can now accept strings<br> |
414
|
|
|
* - try to guess the file extension from the MIME type if there is no file extension<br> |
415
|
|
|
* - better class properties when changing the file extension<br> |
416
|
|
|
* - added {@link file_force_extension} to allow extension-less files if needed<br> |
417
|
|
|
* - better file safe conversion of the filename<br> |
418
|
|
|
* - allow shorthand byte values, such as 1K, 2M, 3G for {@link file_max_size} and {@link jpeg_size}<br> |
419
|
|
|
* - added {@link image_opacity} to change picture opacity<br> |
420
|
|
|
* - added {@link image_border_opacity} to allow semi-transparent borders<br> |
421
|
|
|
* - added {@link image_frame_opacity} to allow semi-transparent frames<br> |
422
|
|
|
* - added {@link image_border_transparent} to allow borders fading to transparent<br> |
423
|
|
|
* - duplicated {@link image_overlay_percent} into {@link image_overlay_opacity}<br> |
424
|
|
|
* - duplicated {@link image_text_percent} into {@link image_text_opacity}<br> |
425
|
|
|
* - duplicated {@link image_text_background_percent} into {@link image_text_background_opacity}</li> |
426
|
|
|
* <li><b>v 0.30</b> 05/09/2010<br> |
427
|
|
|
* - implemented an unsharp mask, with alpha transparency support, activated if {@link image_unsharp} is true. added {@link image_unsharp_amount}, {@link image_unsharp_radius}, and {@link image_unsharp_threshold}<br> |
428
|
|
|
* - added text/rtf MIME type, and no_script exception<br> |
429
|
|
|
* - corrected bug when {@link no_script} is activated and several process() are called<br> |
430
|
|
|
* - better error handling for finfo<br> |
431
|
|
|
* - display upload_max_filesize information from php.ini in the log<br> |
432
|
|
|
* - automatic extension for extension-less images<br> |
433
|
|
|
* - fixed {@link image_ratio_fill} top and left filling<br> |
434
|
|
|
* - fixed alphablending issue when applying a transparent PNG watermark on a transparent PNG<br> |
435
|
|
|
* - added {@link image_watermark_no_zoom_in} and {@link image_watermark_no_zoom_out} to allow the watermark to be resized down (or up) to fit in the image. By default, the watermark may be resized down, but not up.</li> |
436
|
|
|
* <li><b>v 0.29</b> 03/02/2010<br> |
437
|
|
|
* - added protection against malicious images<br> |
438
|
|
|
* - added zip and torrent MIME type<br> |
439
|
|
|
* - replaced split() with explode()<br> |
440
|
|
|
* - initialise image_dst_x/y with image_src_x/y<br> |
441
|
|
|
* - removed {@link mime_fileinfo}, {@link mime_file}, {@link mime_magic} and {@link mime_getimagesize} from the docs since they are used before {@link process}<br> |
442
|
|
|
* - added more extensions and MIME types<br> |
443
|
|
|
* - improved MIME type validation<br> |
444
|
|
|
* - improved logging</li> |
445
|
|
|
* <li><b>v 0.28</b> 10/08/2009<br> |
446
|
|
|
* - replaced ereg functions to be compatible with PHP 5.3<br> |
447
|
|
|
* - added flv MIME type<br> |
448
|
|
|
* - improved MIME type detection<br> |
449
|
|
|
* - added {@link file_name_body_pre} to prepend a string to the file name<br> |
450
|
|
|
* - added {@link mime_fileinfo}, {@link mime_file}, {@link mime_magic} and {@link mime_getimagesize} so that it is possible to deactivate some MIME type checking method<br> |
451
|
|
|
* - use exec() rather than shell_exec(), to play better with safe mode <br> |
452
|
|
|
* - added some error messages<br> |
453
|
|
|
* - fix bug when checking on conditions, {@link processed} wasn't propagated properly</li> |
454
|
|
|
* <li><b>v 0.27</b> 14/05/2009<br> |
455
|
|
|
* - look for the language files directory from __FILE__<br> |
456
|
|
|
* - deactivate {@link file_auto_rename} if {@link file_overwrite} is set<br> |
457
|
|
|
* - improved transparency replacement for true color images<br> |
458
|
|
|
* - fixed calls to newer version of UNIX file utility<br> |
459
|
|
|
* - fixed error when using PECL Fileinfo extension in SAFE MODE, and when using the finfo class<br> |
460
|
|
|
* - added {@link image_precrop} to crop the image before an eventual resizing</li> |
461
|
|
|
* <li><b>v 0.26</b> 13/11/2008<br> |
462
|
|
|
* - rewrote conversion from palette to true color to handle transparency better<br> |
463
|
|
|
* - fixed imagecopymergealpha() when the overlayed image is of wrong dimensions<br> |
464
|
|
|
* - fixed imagecreatenew() when the image to create have less than 1 pixels width or height<br> |
465
|
|
|
* - rewrote MIME type detection to be more secure and not rely on browser information; now using Fileinfo PECL extension, UNIX file() command, MIME magic, and getimagesize(), in that order<br> |
466
|
|
|
* - added support for Flash uploaders<br> |
467
|
|
|
* - some bug fixing and error handling</li> |
468
|
|
|
* <li><b>v 0.25</b> 17/11/2007<br> |
469
|
|
|
* - added translation files and mechanism to instantiate the class with a language different from English<br> |
470
|
|
|
* - added {@link forbidden} to set an array of forbidden MIME types<br> |
471
|
|
|
* - implemented support for simple wildcards in {@link allowed} and {@link forbidden}, such as image/*<br> |
472
|
|
|
* - preset the file extension to the desired conversion format when converting an image<br> |
473
|
|
|
* - added read and write support for BMP images<br> |
474
|
|
|
* - added a flag {@link file_is_image} to determine if the file is a supported image type<br> |
475
|
|
|
* - the class now provides some information about the image, before calling {@link process}(). Available are {@link image_src_x}, {@link image_src_y} and the newly introduced {@link image_src_bits}, {@link image_src_pixels} and {@link image_src_type}. Note that this will not work if <i>open_basedir</i> restrictions are in place<br> |
476
|
|
|
* - improved logging; now provides useful system information<br> |
477
|
|
|
* - added some more pre-processing checks for files that are images: {@link image_max_width}, {@link image_max_height}, {@link image_max_pixels}, {@link image_max_ratio}, {@link image_min_width}, {@link image_min_height}, {@link image_min_pixels} and {@link image_min_ratio}<br> |
478
|
|
|
* - added {@link image_ratio_pixels} to resize an image to a number of pixels, keeping aspect ratio<br> |
479
|
|
|
* - added {@link image_is_palette} and {@link image_is_transparent} and {@link image_transparent_color} for GIF images<br> |
480
|
|
|
* - added {@link image_default_color} to define a fallback color for non alpha-transparent output formats, such as JPEG or BMP<br> |
481
|
|
|
* - changed {@link image_background_color}, which now forces transparent areas to be painted<br> |
482
|
|
|
* - improved reflections and color overlays so that it works with alpha transparent images<br> |
483
|
|
|
* - {@link image_reflection_color} is now deprecated in favour of {@link image_default_color}<br /> |
484
|
|
|
* - transparent PNGs are now processed in true color, and fully preserving the alpha channel when doing merges<br> |
485
|
|
|
* - transparent GIFs are now automatically detected. {@link preserve_transparency} is deprecated<br> |
486
|
|
|
* - transparent true color images can be saved as GIF while retaining transparency, semi transparent areas being merged with {@link image_default_color}<br> |
487
|
|
|
* - transparent true color images can be saved as JPG/BMP with the semi transparent areas being merged with {@link image_default_color}<br> |
488
|
|
|
* - fixed conversion of images to true color<br> |
489
|
|
|
* - the class can now output the uploaded files content as the return value of process() if the function is called with an empty or null argumenti, or no argument</li> |
490
|
|
|
* <li><b>v 0.24</b> 25/05/2007<br> |
491
|
|
|
* - added {@link image_background_color}, to set the default background color of an image<br> |
492
|
|
|
* - added possibility of using replacement tokens in text labels<br> |
493
|
|
|
* - changed default JPEG quality to 85<br> |
494
|
|
|
* - fixed a small bug when using greyscale filter and associated filters<br> |
495
|
|
|
* - added {@link image_ratio_fill} in order to fit an image within some dimensions and color the remaining space. Very similar to {@link image_ratio_crop}<br> |
496
|
|
|
* - improved the recursive creation of directories<br> |
497
|
|
|
* - the class now converts palette based images to true colors before doing graphic manipulations</li> |
498
|
|
|
* <li><b>v 0.23</b> 23/12/2006<br> |
499
|
|
|
* - fixed a bug when processing more than once the same uploaded file. If there is an open_basedir restriction, the class now creates a temporary file for the first call to process(). This file will be used for subsequent processes, and will be deleted upon calling clean()</li> |
500
|
|
|
* <li><b>v 0.22</b> 16/12/2006<br> |
501
|
|
|
* - added automatic creation of a temporary file if the upload directory is not within open_basedir<br> |
502
|
|
|
* - fixed a bug which was preventing to work on a local file by overwriting it with its processed copy<br> |
503
|
|
|
* - added MIME types video/x-ms-wmv and image/x-png and fixed PNG support for IE weird MIME types<br> |
504
|
|
|
* - modified {@link image_ratio_crop} so it can accept one or more from string 'TBLR', determining which side of the image is kept while cropping<br> |
505
|
|
|
* - added support for multiple lines in the text, using "\n" as a line break<br> |
506
|
|
|
* - added {@link image_text_line_spacing} which allow to set the space between several lines of text<br> |
507
|
|
|
* - added {@link image_text_alignment} which allow to set the alignment when text has several lines<br> |
508
|
|
|
* - {@link image_text_font} can now be set to the path of a GDF font to load external fonts<br> |
509
|
|
|
* - added {@link image_reflection_height} to create a reflection of the source image, which height is in pixels or percentage<br> |
510
|
|
|
* - added {@link image_reflection_space} to set the space in pixels between the source image and the reflection<br> |
511
|
|
|
* - added {@link image_reflection_color} to set the reflection background color<br> |
512
|
|
|
* - added {@link image_reflection_opacity} to set the initial level of opacity of the reflection</li> |
513
|
|
|
* <li><b>v 0.21</b> 30/09/2006<br> |
514
|
|
|
* - added {@link image_ratio_crop} which resizes within {@link image_x} and {@link image_y}, keeping ratio, but filling the space by cropping excedent of image<br> |
515
|
|
|
* - added {@link mime_check}, which default is true, to set checks against {@link allowed} MIME list<br> |
516
|
|
|
* - if MIME is empty, the class now triggers an error<br> |
517
|
|
|
* - color #000000 is OK for {@link image_text_color}, and related text transparency bug fixed<br> |
518
|
|
|
* - {@link gd_version}() now uses gd_info(), or else phpinfo()<br> |
519
|
|
|
* - fixed path issue when the destination path has no trailing slash on Windows systems <br> |
520
|
|
|
* - removed inline functions to be fully PHP5 compatible </li> |
521
|
|
|
* <li><b>v 0.20</b> 11/08/2006<br> |
522
|
|
|
* - added some more error checking and messages (GD presence, permissions...)<br> |
523
|
|
|
* - fix when uploading files without extension<br> |
524
|
|
|
* - changed values for {@link image_brightness} and {@link image_contrast} to be between -127 and 127<br> |
525
|
|
|
* - added {@link dir_auto_create} to automatically and recursively create destination directory if missing.<br> |
526
|
|
|
* - added {@link dir_auto_chmod} to automatically chmod the destination directory if not writeable.<br> |
527
|
|
|
* - added {@link dir_chmod} to set the default chmod to use.<br> |
528
|
|
|
* - added {@link image_crop} to crop images<br> |
529
|
|
|
* - added {@link image_negative} to invert the colors on the image<br> |
530
|
|
|
* - added {@link image_greyscale} to turn the image into greyscale<br> |
531
|
|
|
* - added {@link image_threshold} to apply a threshold filter on the image<br> |
532
|
|
|
* - added {@link image_bevel}, {@link image_bevel_color1} and {@link image_bevel_color2} to add a bevel border<br> |
533
|
|
|
* - added {@link image_border} and {@link image_border_color} to add a single color border<br> |
534
|
|
|
* - added {@link image_frame} and {@link image_frame_colors} to add a multicolored frame</li> |
535
|
|
|
* <li><b>v 0.19</b> 29/03/2006<br> |
536
|
|
|
* - class is now compatible i18n (thanks Sylwester).<br> |
537
|
|
|
* - the class can mow manipulate local files, not only uploaded files (instanciate the class with a local filename).<br> |
538
|
|
|
* - {@link file_safe_name} has been improved a bit.<br> |
539
|
|
|
* - added {@link image_brightness}, {@link image_contrast}, {@link image_tint_color}, {@link image_overlay_color} and {@link image_overlay_percent} to do color manipulation on the images.<br> |
540
|
|
|
* - added {@link image_text} and all derivated settings to add a text label on the image.<br> |
541
|
|
|
* - added {@link image_watermark} and all derivated settings to add a watermark image on the image.<br> |
542
|
|
|
* - added {@link image_flip} and {@link image_rotate} for more image manipulations<br> |
543
|
|
|
* - added {@link jpeg_size} to calculate the JPG compression quality in order to fit within one filesize.</li> |
544
|
|
|
* <li><b>v 0.18</b> 02/02/2006<br> |
545
|
|
|
* - added {@link no_script} to turn dangerous scripts into text files.<br> |
546
|
|
|
* - added {@link mime_magic_check} to set the class to use mime_magic.<br> |
547
|
|
|
* - added {@link preserve_transparency} *experimental*. Thanks Gregor.<br> |
548
|
|
|
* - fixed size and mime checking, wasn't working :/ Thanks Willem.<br> |
549
|
|
|
* - fixed memory leak when resizing images.<br> |
550
|
|
|
* - when resizing, it is not necessary anymore to set {@link image_convert}.<br> |
551
|
|
|
* - il is now possible to simply convert an image, with no resizing.<br> |
552
|
|
|
* - sets the default {@link file_max_size} to upload_max_filesize from php.ini. Thanks Edward</li> |
553
|
|
|
* <li><b>v 0.17</b> 28/05/2005<br> |
554
|
|
|
* - the class can be used with any version of GD.<br> |
555
|
|
|
* - added security check on the file with a list of mime-types.<br> |
556
|
|
|
* - changed the license to GPL v2 only</li> |
557
|
|
|
* <li><b>v 0.16</b> 19/05/2005<br> |
558
|
|
|
* - added {@link file_auto_rename} automatic file renaming if the same filename already exists.<br> |
559
|
|
|
* - added {@link file_safe_name} safe formatting of the filename (spaces to _underscores so far).<br> |
560
|
|
|
* - added some more error reporting to avoid crash if GD is not present</li> |
561
|
|
|
* <li><b>v 0.15</b> 16/04/2005<br> |
562
|
|
|
* - added JPEG compression quality setting. Thanks Vad</li> |
563
|
|
|
* <li><b>v 0.14</b> 14/03/2005<br> |
564
|
|
|
* - reworked the class file to allow parsing with phpDocumentor</li> |
565
|
|
|
* <li><b>v 0.13</b> 07/03/2005<br> |
566
|
|
|
* - fixed a bug with {@link image_ratio}. Thanks Justin.<br> |
567
|
|
|
* - added {@link image_ratio_no_zoom_in} and {@link image_ratio_no_zoom_out} </li> |
568
|
|
|
* <li><b>v 0.12</b> 21/01/2005<br> |
569
|
|
|
* - added {@link image_ratio} to resize within max values, keeping image ratio</li> |
570
|
|
|
* <li><b>v 0.11</b> 22/08/2003<br> |
571
|
|
|
* - update for GD2 (changed imageresized() into imagecopyresampled() and imagecreate() into imagecreatetruecolor())</li> |
572
|
|
|
* </ul> |
573
|
|
|
* |
574
|
|
|
* @package cmf |
575
|
|
|
* @subpackage external |
576
|
|
|
*/ |
577
|
|
|
class upload { |
578
|
|
|
|
579
|
|
|
|
580
|
|
|
/** |
581
|
|
|
* Class version |
582
|
|
|
* |
583
|
|
|
* @access public |
584
|
|
|
* @var string |
585
|
|
|
*/ |
586
|
|
|
var $version; |
587
|
|
|
|
588
|
|
|
/** |
589
|
|
|
* Uploaded file name |
590
|
|
|
* |
591
|
|
|
* @access public |
592
|
|
|
* @var string |
593
|
|
|
*/ |
594
|
|
|
var $file_src_name; |
595
|
|
|
|
596
|
|
|
/** |
597
|
|
|
* Uploaded file name body (i.e. without extension) |
598
|
|
|
* |
599
|
|
|
* @access public |
600
|
|
|
* @var string |
601
|
|
|
*/ |
602
|
|
|
var $file_src_name_body; |
603
|
|
|
|
604
|
|
|
/** |
605
|
|
|
* Uploaded file name extension |
606
|
|
|
* |
607
|
|
|
* @access public |
608
|
|
|
* @var string |
609
|
|
|
*/ |
610
|
|
|
var $file_src_name_ext; |
611
|
|
|
|
612
|
|
|
/** |
613
|
|
|
* Uploaded file MIME type |
614
|
|
|
* |
615
|
|
|
* @access public |
616
|
|
|
* @var string |
617
|
|
|
*/ |
618
|
|
|
var $file_src_mime; |
619
|
|
|
|
620
|
|
|
/** |
621
|
|
|
* Uploaded file size, in bytes |
622
|
|
|
* |
623
|
|
|
* @access public |
624
|
|
|
* @var double |
625
|
|
|
*/ |
626
|
|
|
var $file_src_size; |
627
|
|
|
|
628
|
|
|
/** |
629
|
|
|
* Holds eventual PHP error code from $_FILES |
630
|
|
|
* |
631
|
|
|
* @access public |
632
|
|
|
* @var string |
633
|
|
|
*/ |
634
|
|
|
var $file_src_error; |
635
|
|
|
|
636
|
|
|
/** |
637
|
|
|
* Uloaded file name, including server path |
638
|
|
|
* |
639
|
|
|
* @access public |
640
|
|
|
* @var string |
641
|
|
|
*/ |
642
|
|
|
var $file_src_pathname; |
643
|
|
|
|
644
|
|
|
/** |
645
|
|
|
* Uloaded file name temporary copy |
646
|
|
|
* |
647
|
|
|
* @access private |
648
|
|
|
* @var string |
649
|
|
|
*/ |
650
|
|
|
var $file_src_temp; |
651
|
|
|
|
652
|
|
|
/** |
653
|
|
|
* Destination file name |
654
|
|
|
* |
655
|
|
|
* @access public |
656
|
|
|
* @var string |
657
|
|
|
*/ |
658
|
|
|
var $file_dst_path; |
659
|
|
|
|
660
|
|
|
/** |
661
|
|
|
* Destination file name |
662
|
|
|
* |
663
|
|
|
* @access public |
664
|
|
|
* @var string |
665
|
|
|
*/ |
666
|
|
|
var $file_dst_name; |
667
|
|
|
|
668
|
|
|
/** |
669
|
|
|
* Destination file name body (i.e. without extension) |
670
|
|
|
* |
671
|
|
|
* @access public |
672
|
|
|
* @var string |
673
|
|
|
*/ |
674
|
|
|
var $file_dst_name_body; |
675
|
|
|
|
676
|
|
|
/** |
677
|
|
|
* Destination file extension |
678
|
|
|
* |
679
|
|
|
* @access public |
680
|
|
|
* @var string |
681
|
|
|
*/ |
682
|
|
|
var $file_dst_name_ext; |
683
|
|
|
|
684
|
|
|
/** |
685
|
|
|
* Destination file name, including path |
686
|
|
|
* |
687
|
|
|
* @access public |
688
|
|
|
* @var string |
689
|
|
|
*/ |
690
|
|
|
var $file_dst_pathname; |
691
|
|
|
|
692
|
|
|
/** |
693
|
|
|
* Source image width |
694
|
|
|
* |
695
|
|
|
* @access public |
696
|
|
|
* @var integer |
697
|
|
|
*/ |
698
|
|
|
var $image_src_x; |
699
|
|
|
|
700
|
|
|
/** |
701
|
|
|
* Source image height |
702
|
|
|
* |
703
|
|
|
* @access public |
704
|
|
|
* @var integer |
705
|
|
|
*/ |
706
|
|
|
var $image_src_y; |
707
|
|
|
|
708
|
|
|
/** |
709
|
|
|
* Source image color depth |
710
|
|
|
* |
711
|
|
|
* @access public |
712
|
|
|
* @var integer |
713
|
|
|
*/ |
714
|
|
|
var $image_src_bits; |
715
|
|
|
|
716
|
|
|
/** |
717
|
|
|
* Number of pixels |
718
|
|
|
* |
719
|
|
|
* @access public |
720
|
|
|
* @var long |
721
|
|
|
*/ |
722
|
|
|
var $image_src_pixels; |
723
|
|
|
|
724
|
|
|
/** |
725
|
|
|
* Type of image (png, gif, jpg or bmp) |
726
|
|
|
* |
727
|
|
|
* @access public |
728
|
|
|
* @var string |
729
|
|
|
*/ |
730
|
|
|
var $image_src_type; |
731
|
|
|
|
732
|
|
|
/** |
733
|
|
|
* Destination image width |
734
|
|
|
* |
735
|
|
|
* @access public |
736
|
|
|
* @var integer |
737
|
|
|
*/ |
738
|
|
|
var $image_dst_x; |
739
|
|
|
|
740
|
|
|
/** |
741
|
|
|
* Destination image height |
742
|
|
|
* |
743
|
|
|
* @access public |
744
|
|
|
* @var integer |
745
|
|
|
*/ |
746
|
|
|
var $image_dst_y; |
747
|
|
|
|
748
|
|
|
/** |
749
|
|
|
* Supported image formats |
750
|
|
|
* |
751
|
|
|
* @access private |
752
|
|
|
* @var array |
753
|
|
|
*/ |
754
|
|
|
var $image_supported; |
755
|
|
|
|
756
|
|
|
/** |
757
|
|
|
* Flag to determine if the source file is an image |
758
|
|
|
* |
759
|
|
|
* @access public |
760
|
|
|
* @var boolean |
761
|
|
|
*/ |
762
|
|
|
var $file_is_image; |
763
|
|
|
|
764
|
|
|
/** |
765
|
|
|
* Flag set after instanciating the class |
766
|
|
|
* |
767
|
|
|
* Indicates if the file has been uploaded properly |
768
|
|
|
* |
769
|
|
|
* @access public |
770
|
|
|
* @var bool |
771
|
|
|
*/ |
772
|
|
|
var $uploaded; |
773
|
|
|
|
774
|
|
|
/** |
775
|
|
|
* Flag stopping PHP upload checks |
776
|
|
|
* |
777
|
|
|
* Indicates whether we instanciated the class with a filename, in which case |
778
|
|
|
* we will not check on the validity of the PHP *upload* |
779
|
|
|
* |
780
|
|
|
* This flag is automatically set to true when working on a local file |
781
|
|
|
* |
782
|
|
|
* Warning: for uploads, this flag MUST be set to false for security reason |
783
|
|
|
* |
784
|
|
|
* @access public |
785
|
|
|
* @var bool |
786
|
|
|
*/ |
787
|
|
|
var $no_upload_check; |
788
|
|
|
|
789
|
|
|
/** |
790
|
|
|
* Flag set after calling a process |
791
|
|
|
* |
792
|
|
|
* Indicates if the processing, and copy of the resulting file went OK |
793
|
|
|
* |
794
|
|
|
* @access public |
795
|
|
|
* @var bool |
796
|
|
|
*/ |
797
|
|
|
var $processed; |
798
|
|
|
|
799
|
|
|
/** |
800
|
|
|
* Holds eventual error message in plain english |
801
|
|
|
* |
802
|
|
|
* @access public |
803
|
|
|
* @var string |
804
|
|
|
*/ |
805
|
|
|
var $error; |
806
|
|
|
|
807
|
|
|
/** |
808
|
|
|
* Holds an HTML formatted log |
809
|
|
|
* |
810
|
|
|
* @access public |
811
|
|
|
* @var string |
812
|
|
|
*/ |
813
|
|
|
var $log; |
814
|
|
|
|
815
|
|
|
|
816
|
|
|
// overiddable processing variables |
817
|
|
|
|
818
|
|
|
|
819
|
|
|
/** |
820
|
|
|
* Set this variable to replace the name body (i.e. without extension) |
821
|
|
|
* |
822
|
|
|
* @access public |
823
|
|
|
* @var string |
824
|
|
|
*/ |
825
|
|
|
var $file_new_name_body; |
826
|
|
|
|
827
|
|
|
/** |
828
|
|
|
* Set this variable to append a string to the file name body |
829
|
|
|
* |
830
|
|
|
* @access public |
831
|
|
|
* @var string |
832
|
|
|
*/ |
833
|
|
|
var $file_name_body_add; |
834
|
|
|
|
835
|
|
|
/** |
836
|
|
|
* Set this variable to prepend a string to the file name body |
837
|
|
|
* |
838
|
|
|
* @access public |
839
|
|
|
* @var string |
840
|
|
|
*/ |
841
|
|
|
var $file_name_body_pre; |
842
|
|
|
|
843
|
|
|
/** |
844
|
|
|
* Set this variable to change the file extension |
845
|
|
|
* |
846
|
|
|
* @access public |
847
|
|
|
* @var string |
848
|
|
|
*/ |
849
|
|
|
var $file_new_name_ext; |
850
|
|
|
|
851
|
|
|
/** |
852
|
|
|
* Set this variable to format the filename (spaces changed to _) |
853
|
|
|
* |
854
|
|
|
* @access public |
855
|
|
|
* @var boolean |
856
|
|
|
*/ |
857
|
|
|
var $file_safe_name; |
858
|
|
|
|
859
|
|
|
/** |
860
|
|
|
* Forces an extension if the source file doesn't have one |
861
|
|
|
* |
862
|
|
|
* If the file is an image, then the correct extension will be added |
863
|
|
|
* Otherwise, a .txt extension will be chosen |
864
|
|
|
* |
865
|
|
|
* @access public |
866
|
|
|
* @var boolean |
867
|
|
|
*/ |
868
|
|
|
var $file_force_extension; |
869
|
|
|
|
870
|
|
|
/** |
871
|
|
|
* Set this variable to false if you don't want to check the MIME against the allowed list |
872
|
|
|
* |
873
|
|
|
* This variable is set to true by default for security reason |
874
|
|
|
* |
875
|
|
|
* @access public |
876
|
|
|
* @var boolean |
877
|
|
|
*/ |
878
|
|
|
var $mime_check; |
879
|
|
|
|
880
|
|
|
/** |
881
|
|
|
* Set this variable to false in the init() function if you don't want to check the MIME |
882
|
|
|
* with Fileinfo PECL extension. On some systems, Fileinfo is known to be buggy, and you |
883
|
|
|
* may want to deactivate it in the class code directly. |
884
|
|
|
* |
885
|
|
|
* You can also set it with the path of the magic database file. |
886
|
|
|
* If set to true, the class will try to read the MAGIC environment variable |
887
|
|
|
* and if it is empty, will default to '/usr/share/file/magic' |
888
|
|
|
* If set to an empty string, it will call finfo_open without the path argument |
889
|
|
|
* |
890
|
|
|
* This variable is set to true by default for security reason |
891
|
|
|
* |
892
|
|
|
* @access public |
893
|
|
|
* @var boolean |
894
|
|
|
*/ |
895
|
|
|
var $mime_fileinfo; |
896
|
|
|
|
897
|
|
|
/** |
898
|
|
|
* Set this variable to false in the init() function if you don't want to check the MIME |
899
|
|
|
* with UNIX file() command |
900
|
|
|
* |
901
|
|
|
* This variable is set to true by default for security reason |
902
|
|
|
* |
903
|
|
|
* @access public |
904
|
|
|
* @var boolean |
905
|
|
|
*/ |
906
|
|
|
var $mime_file; |
907
|
|
|
|
908
|
|
|
/** |
909
|
|
|
* Set this variable to false in the init() function if you don't want to check the MIME |
910
|
|
|
* with the magic.mime file |
911
|
|
|
* |
912
|
|
|
* The function mime_content_type() will be deprecated, |
913
|
|
|
* and this variable will be set to false in a future release |
914
|
|
|
* |
915
|
|
|
* This variable is set to true by default for security reason |
916
|
|
|
* |
917
|
|
|
* @access public |
918
|
|
|
* @var boolean |
919
|
|
|
*/ |
920
|
|
|
var $mime_magic; |
921
|
|
|
|
922
|
|
|
/** |
923
|
|
|
* Set this variable to false in the init() function if you don't want to check the MIME |
924
|
|
|
* with getimagesize() |
925
|
|
|
* |
926
|
|
|
* The class tries to get a MIME type from getimagesize() |
927
|
|
|
* If no MIME is returned, it tries to guess the MIME type from the file type |
928
|
|
|
* |
929
|
|
|
* This variable is set to true by default for security reason |
930
|
|
|
* |
931
|
|
|
* @access public |
932
|
|
|
* @var boolean |
933
|
|
|
*/ |
934
|
|
|
var $mime_getimagesize; |
935
|
|
|
|
936
|
|
|
/** |
937
|
|
|
* Set this variable to false if you don't want to turn dangerous scripts into simple text files |
938
|
|
|
* |
939
|
|
|
* @access public |
940
|
|
|
* @var boolean |
941
|
|
|
*/ |
942
|
|
|
var $no_script; |
943
|
|
|
|
944
|
|
|
/** |
945
|
|
|
* Set this variable to true to allow automatic renaming of the file |
946
|
|
|
* if the file already exists |
947
|
|
|
* |
948
|
|
|
* Default value is true |
949
|
|
|
* |
950
|
|
|
* For instance, on uploading foo.ext,<br> |
951
|
|
|
* if foo.ext already exists, upload will be renamed foo_1.ext<br> |
952
|
|
|
* and if foo_1.ext already exists, upload will be renamed foo_2.ext<br> |
953
|
|
|
* |
954
|
|
|
* Note that this option doesn't have any effect if {@link file_overwrite} is true |
955
|
|
|
* |
956
|
|
|
* @access public |
957
|
|
|
* @var bool |
958
|
|
|
*/ |
959
|
|
|
var $file_auto_rename; |
960
|
|
|
|
961
|
|
|
/** |
962
|
|
|
* Set this variable to true to allow automatic creation of the destination |
963
|
|
|
* directory if it is missing (works recursively) |
964
|
|
|
* |
965
|
|
|
* Default value is true |
966
|
|
|
* |
967
|
|
|
* @access public |
968
|
|
|
* @var bool |
969
|
|
|
*/ |
970
|
|
|
var $dir_auto_create; |
971
|
|
|
|
972
|
|
|
/** |
973
|
|
|
* Set this variable to true to allow automatic chmod of the destination |
974
|
|
|
* directory if it is not writeable |
975
|
|
|
* |
976
|
|
|
* Default value is true |
977
|
|
|
* |
978
|
|
|
* @access public |
979
|
|
|
* @var bool |
980
|
|
|
*/ |
981
|
|
|
var $dir_auto_chmod; |
982
|
|
|
|
983
|
|
|
/** |
984
|
|
|
* Set this variable to the default chmod you want the class to use |
985
|
|
|
* when creating directories, or attempting to write in a directory |
986
|
|
|
* |
987
|
|
|
* Default value is 0777 (without quotes) |
988
|
|
|
* |
989
|
|
|
* @access public |
990
|
|
|
* @var bool |
991
|
|
|
*/ |
992
|
|
|
var $dir_chmod; |
993
|
|
|
|
994
|
|
|
/** |
995
|
|
|
* Set this variable tu true to allow overwriting of an existing file |
996
|
|
|
* |
997
|
|
|
* Default value is false, so no files will be overwritten |
998
|
|
|
* |
999
|
|
|
* @access public |
1000
|
|
|
* @var bool |
1001
|
|
|
*/ |
1002
|
|
|
var $file_overwrite; |
1003
|
|
|
|
1004
|
|
|
/** |
1005
|
|
|
* Set this variable to change the maximum size in bytes for an uploaded file |
1006
|
|
|
* |
1007
|
|
|
* Default value is the value <i>upload_max_filesize</i> from php.ini |
1008
|
|
|
* |
1009
|
|
|
* Value in bytes (integer) or shorthand byte values (string) is allowed. |
1010
|
|
|
* The available options are K (for Kilobytes), M (for Megabytes) and G (for Gigabytes) |
1011
|
|
|
* |
1012
|
|
|
* @access public |
1013
|
|
|
* @var double |
1014
|
|
|
*/ |
1015
|
|
|
var $file_max_size; |
1016
|
|
|
|
1017
|
|
|
/** |
1018
|
|
|
* Set this variable to true to resize the file if it is an image |
1019
|
|
|
* |
1020
|
|
|
* You will probably want to set {@link image_x} and {@link image_y}, and maybe one of the ratio variables |
1021
|
|
|
* |
1022
|
|
|
* Default value is false (no resizing) |
1023
|
|
|
* |
1024
|
|
|
* @access public |
1025
|
|
|
* @var bool |
1026
|
|
|
*/ |
1027
|
|
|
var $image_resize; |
1028
|
|
|
|
1029
|
|
|
/** |
1030
|
|
|
* Set this variable to convert the file if it is an image |
1031
|
|
|
* |
1032
|
|
|
* Possibles values are : ''; 'png'; 'jpeg'; 'gif'; 'bmp' |
1033
|
|
|
* |
1034
|
|
|
* Default value is '' (no conversion)<br> |
1035
|
|
|
* If {@link resize} is true, {@link convert} will be set to the source file extension |
1036
|
|
|
* |
1037
|
|
|
* @access public |
1038
|
|
|
* @var string |
1039
|
|
|
*/ |
1040
|
|
|
var $image_convert; |
1041
|
|
|
|
1042
|
|
|
/** |
1043
|
|
|
* Set this variable to the wanted (or maximum/minimum) width for the processed image, in pixels |
1044
|
|
|
* |
1045
|
|
|
* Default value is 150 |
1046
|
|
|
* |
1047
|
|
|
* @access public |
1048
|
|
|
* @var integer |
1049
|
|
|
*/ |
1050
|
|
|
var $image_x; |
1051
|
|
|
|
1052
|
|
|
/** |
1053
|
|
|
* Set this variable to the wanted (or maximum/minimum) height for the processed image, in pixels |
1054
|
|
|
* |
1055
|
|
|
* Default value is 150 |
1056
|
|
|
* |
1057
|
|
|
* @access public |
1058
|
|
|
* @var integer |
1059
|
|
|
*/ |
1060
|
|
|
var $image_y; |
1061
|
|
|
|
1062
|
|
|
/** |
1063
|
|
|
* Set this variable to keep the original size ratio to fit within {@link image_x} x {@link image_y} |
1064
|
|
|
* |
1065
|
|
|
* Default value is false |
1066
|
|
|
* |
1067
|
|
|
* @access public |
1068
|
|
|
* @var bool |
1069
|
|
|
*/ |
1070
|
|
|
var $image_ratio; |
1071
|
|
|
|
1072
|
|
|
/** |
1073
|
|
|
* Set this variable to keep the original size ratio to fit within {@link image_x} x {@link image_y} |
1074
|
|
|
* |
1075
|
|
|
* The image will be resized as to fill the whole space, and excedent will be cropped |
1076
|
|
|
* |
1077
|
|
|
* Value can also be a string, one or more character from 'TBLR' (top, bottom, left and right) |
1078
|
|
|
* If set as a string, it determines which side of the image is kept while cropping. |
1079
|
|
|
* By default, the part of the image kept is in the center, i.e. it crops equally on both sides |
1080
|
|
|
* |
1081
|
|
|
* Default value is false |
1082
|
|
|
* |
1083
|
|
|
* @access public |
1084
|
|
|
* @var mixed |
1085
|
|
|
*/ |
1086
|
|
|
var $image_ratio_crop; |
1087
|
|
|
|
1088
|
|
|
/** |
1089
|
|
|
* Set this variable to keep the original size ratio to fit within {@link image_x} x {@link image_y} |
1090
|
|
|
* |
1091
|
|
|
* The image will be resized to fit entirely in the space, and the rest will be colored. |
1092
|
|
|
* The default color is white, but can be set with {@link image_default_color} |
1093
|
|
|
* |
1094
|
|
|
* Value can also be a string, one or more character from 'TBLR' (top, bottom, left and right) |
1095
|
|
|
* If set as a string, it determines in which side of the space the image is displayed. |
1096
|
|
|
* By default, the image is displayed in the center, i.e. it fills the remaining space equally on both sides |
1097
|
|
|
* |
1098
|
|
|
* Default value is false |
1099
|
|
|
* |
1100
|
|
|
* @access public |
1101
|
|
|
* @var mixed |
1102
|
|
|
*/ |
1103
|
|
|
var $image_ratio_fill; |
1104
|
|
|
|
1105
|
|
|
/** |
1106
|
|
|
* Set this variable to a number of pixels so that {@link image_x} and {@link image_y} are the best match possible |
1107
|
|
|
* |
1108
|
|
|
* The image will be resized to have approximatively the number of pixels |
1109
|
|
|
* The aspect ratio wil be conserved |
1110
|
|
|
* |
1111
|
|
|
* Default value is false |
1112
|
|
|
* |
1113
|
|
|
* @access public |
1114
|
|
|
* @var mixed |
1115
|
|
|
*/ |
1116
|
|
|
var $image_ratio_pixels; |
1117
|
|
|
|
1118
|
|
|
/** |
1119
|
|
|
* Set this variable to keep the original size ratio to fit within {@link image_x} x {@link image_y}, |
1120
|
|
|
* but only if original image is bigger |
1121
|
|
|
* |
1122
|
|
|
* Default value is false |
1123
|
|
|
* |
1124
|
|
|
* @access public |
1125
|
|
|
* @var bool |
1126
|
|
|
*/ |
1127
|
|
|
var $image_ratio_no_zoom_in; |
1128
|
|
|
|
1129
|
|
|
/** |
1130
|
|
|
* Set this variable to keep the original size ratio to fit within {@link image_x} x {@link image_y}, |
1131
|
|
|
* but only if original image is smaller |
1132
|
|
|
* |
1133
|
|
|
* Default value is false |
1134
|
|
|
* |
1135
|
|
|
* @access public |
1136
|
|
|
* @var bool |
1137
|
|
|
*/ |
1138
|
|
|
var $image_ratio_no_zoom_out; |
1139
|
|
|
|
1140
|
|
|
/** |
1141
|
|
|
* Set this variable to calculate {@link image_x} automatically , using {@link image_y} and conserving ratio |
1142
|
|
|
* |
1143
|
|
|
* Default value is false |
1144
|
|
|
* |
1145
|
|
|
* @access public |
1146
|
|
|
* @var bool |
1147
|
|
|
*/ |
1148
|
|
|
var $image_ratio_x; |
1149
|
|
|
|
1150
|
|
|
/** |
1151
|
|
|
* Set this variable to calculate {@link image_y} automatically , using {@link image_x} and conserving ratio |
1152
|
|
|
* |
1153
|
|
|
* Default value is false |
1154
|
|
|
* |
1155
|
|
|
* @access public |
1156
|
|
|
* @var bool |
1157
|
|
|
*/ |
1158
|
|
|
var $image_ratio_y; |
1159
|
|
|
|
1160
|
|
|
/** |
1161
|
|
|
* Set this variable to set a maximum image width, above which the upload will be invalid |
1162
|
|
|
* |
1163
|
|
|
* Default value is null |
1164
|
|
|
* |
1165
|
|
|
* @access public |
1166
|
|
|
* @var integer |
1167
|
|
|
*/ |
1168
|
|
|
var $image_max_width; |
1169
|
|
|
|
1170
|
|
|
/** |
1171
|
|
|
* Set this variable to set a maximum image height, above which the upload will be invalid |
1172
|
|
|
* |
1173
|
|
|
* Default value is null |
1174
|
|
|
* |
1175
|
|
|
* @access public |
1176
|
|
|
* @var integer |
1177
|
|
|
*/ |
1178
|
|
|
var $image_max_height; |
1179
|
|
|
|
1180
|
|
|
/** |
1181
|
|
|
* Set this variable to set a maximum number of pixels for an image, above which the upload will be invalid |
1182
|
|
|
* |
1183
|
|
|
* Default value is null |
1184
|
|
|
* |
1185
|
|
|
* @access public |
1186
|
|
|
* @var long |
1187
|
|
|
*/ |
1188
|
|
|
var $image_max_pixels; |
1189
|
|
|
|
1190
|
|
|
/** |
1191
|
|
|
* Set this variable to set a maximum image aspect ratio, above which the upload will be invalid |
1192
|
|
|
* |
1193
|
|
|
* Note that ratio = width / height |
1194
|
|
|
* |
1195
|
|
|
* Default value is null |
1196
|
|
|
* |
1197
|
|
|
* @access public |
1198
|
|
|
* @var float |
1199
|
|
|
*/ |
1200
|
|
|
var $image_max_ratio; |
1201
|
|
|
|
1202
|
|
|
/** |
1203
|
|
|
* Set this variable to set a minimum image width, below which the upload will be invalid |
1204
|
|
|
* |
1205
|
|
|
* Default value is null |
1206
|
|
|
* |
1207
|
|
|
* @access public |
1208
|
|
|
* @var integer |
1209
|
|
|
*/ |
1210
|
|
|
var $image_min_width; |
1211
|
|
|
|
1212
|
|
|
/** |
1213
|
|
|
* Set this variable to set a minimum image height, below which the upload will be invalid |
1214
|
|
|
* |
1215
|
|
|
* Default value is null |
1216
|
|
|
* |
1217
|
|
|
* @access public |
1218
|
|
|
* @var integer |
1219
|
|
|
*/ |
1220
|
|
|
var $image_min_height; |
1221
|
|
|
|
1222
|
|
|
/** |
1223
|
|
|
* Set this variable to set a minimum number of pixels for an image, below which the upload will be invalid |
1224
|
|
|
* |
1225
|
|
|
* Default value is null |
1226
|
|
|
* |
1227
|
|
|
* @access public |
1228
|
|
|
* @var long |
1229
|
|
|
*/ |
1230
|
|
|
var $image_min_pixels; |
1231
|
|
|
|
1232
|
|
|
/** |
1233
|
|
|
* Set this variable to set a minimum image aspect ratio, below which the upload will be invalid |
1234
|
|
|
* |
1235
|
|
|
* Note that ratio = width / height |
1236
|
|
|
* |
1237
|
|
|
* Default value is null |
1238
|
|
|
* |
1239
|
|
|
* @access public |
1240
|
|
|
* @var float |
1241
|
|
|
*/ |
1242
|
|
|
var $image_min_ratio; |
1243
|
|
|
|
1244
|
|
|
/** |
1245
|
|
|
* Quality of JPEG created/converted destination image |
1246
|
|
|
* |
1247
|
|
|
* Default value is 85 |
1248
|
|
|
* |
1249
|
|
|
* @access public |
1250
|
|
|
* @var integer |
1251
|
|
|
*/ |
1252
|
|
|
var $jpeg_quality; |
1253
|
|
|
|
1254
|
|
|
/** |
1255
|
|
|
* Determines the quality of the JPG image to fit a desired file size |
1256
|
|
|
* |
1257
|
|
|
* The JPG quality will be set between 1 and 100% |
1258
|
|
|
* The calculations are approximations. |
1259
|
|
|
* |
1260
|
|
|
* Value in bytes (integer) or shorthand byte values (string) is allowed. |
1261
|
|
|
* The available options are K (for Kilobytes), M (for Megabytes) and G (for Gigabytes) |
1262
|
|
|
* |
1263
|
|
|
* Default value is null (no calculations) |
1264
|
|
|
* |
1265
|
|
|
* @access public |
1266
|
|
|
* @var integer |
1267
|
|
|
*/ |
1268
|
|
|
var $jpeg_size; |
1269
|
|
|
|
1270
|
|
|
/** |
1271
|
|
|
* Preserve transparency when resizing or converting an image (deprecated) |
1272
|
|
|
* |
1273
|
|
|
* Default value is automatically set to true for transparent GIFs |
1274
|
|
|
* This setting is now deprecated |
1275
|
|
|
* |
1276
|
|
|
* @access public |
1277
|
|
|
* @var integer |
1278
|
|
|
*/ |
1279
|
|
|
var $preserve_transparency; |
1280
|
|
|
|
1281
|
|
|
/** |
1282
|
|
|
* Flag set to true when the image is transparent |
1283
|
|
|
* |
1284
|
|
|
* This is actually used only for transparent GIFs |
1285
|
|
|
* |
1286
|
|
|
* @access public |
1287
|
|
|
* @var boolean |
1288
|
|
|
*/ |
1289
|
|
|
var $image_is_transparent; |
1290
|
|
|
|
1291
|
|
|
/** |
1292
|
|
|
* Transparent color in a palette |
1293
|
|
|
* |
1294
|
|
|
* This is actually used only for transparent GIFs |
1295
|
|
|
* |
1296
|
|
|
* @access public |
1297
|
|
|
* @var boolean |
1298
|
|
|
*/ |
1299
|
|
|
var $image_transparent_color; |
1300
|
|
|
|
1301
|
|
|
/** |
1302
|
|
|
* Background color, used to paint transparent areas with |
1303
|
|
|
* |
1304
|
|
|
* If set, it will forcibly remove transparency by painting transparent areas with the color |
1305
|
|
|
* This setting will fill in all transparent areas in PNG and GIF, as opposed to {@link image_default_color} |
1306
|
|
|
* which will do so only in BMP, JPEG, and alpha transparent areas in transparent GIFs |
1307
|
|
|
* This setting overrides {@link image_default_color} |
1308
|
|
|
* |
1309
|
|
|
* Default value is null |
1310
|
|
|
* |
1311
|
|
|
* @access public |
1312
|
|
|
* @var string |
1313
|
|
|
*/ |
1314
|
|
|
var $image_background_color; |
1315
|
|
|
|
1316
|
|
|
/** |
1317
|
|
|
* Default color for non alpha-transparent images |
1318
|
|
|
* |
1319
|
|
|
* This setting is to be used to define a background color for semi transparent areas |
1320
|
|
|
* of an alpha transparent when the output format doesn't support alpha transparency |
1321
|
|
|
* This is useful when, from an alpha transparent PNG image, or an image with alpha transparent features |
1322
|
|
|
* if you want to output it as a transparent GIFs for instance, you can set a blending color for transparent areas |
1323
|
|
|
* If you output in JPEG or BMP, this color will be used to fill in the previously transparent areas |
1324
|
|
|
* |
1325
|
|
|
* The default color white |
1326
|
|
|
* |
1327
|
|
|
* @access public |
1328
|
|
|
* @var boolean |
1329
|
|
|
*/ |
1330
|
|
|
var $image_default_color; |
1331
|
|
|
|
1332
|
|
|
/** |
1333
|
|
|
* Flag set to true when the image is not true color |
1334
|
|
|
* |
1335
|
|
|
* @access public |
1336
|
|
|
* @var boolean |
1337
|
|
|
*/ |
1338
|
|
|
var $image_is_palette; |
1339
|
|
|
|
1340
|
|
|
/** |
1341
|
|
|
* Corrects the image brightness |
1342
|
|
|
* |
1343
|
|
|
* Value can range between -127 and 127 |
1344
|
|
|
* |
1345
|
|
|
* Default value is null |
1346
|
|
|
* |
1347
|
|
|
* @access public |
1348
|
|
|
* @var integer |
1349
|
|
|
*/ |
1350
|
|
|
var $image_brightness; |
1351
|
|
|
|
1352
|
|
|
/** |
1353
|
|
|
* Corrects the image contrast |
1354
|
|
|
* |
1355
|
|
|
* Value can range between -127 and 127 |
1356
|
|
|
* |
1357
|
|
|
* Default value is null |
1358
|
|
|
* |
1359
|
|
|
* @access public |
1360
|
|
|
* @var integer |
1361
|
|
|
*/ |
1362
|
|
|
var $image_contrast; |
1363
|
|
|
|
1364
|
|
|
/** |
1365
|
|
|
* Changes the image opacity |
1366
|
|
|
* |
1367
|
|
|
* Value can range between 0 and 100 |
1368
|
|
|
* |
1369
|
|
|
* Default value is null |
1370
|
|
|
* |
1371
|
|
|
* @access public |
1372
|
|
|
* @var integer |
1373
|
|
|
*/ |
1374
|
|
|
var $image_opacity; |
1375
|
|
|
|
1376
|
|
|
/** |
1377
|
|
|
* Applies threshold filter |
1378
|
|
|
* |
1379
|
|
|
* Value can range between -127 and 127 |
1380
|
|
|
* |
1381
|
|
|
* Default value is null |
1382
|
|
|
* |
1383
|
|
|
* @access public |
1384
|
|
|
* @var integer |
1385
|
|
|
*/ |
1386
|
|
|
var $image_threshold; |
1387
|
|
|
|
1388
|
|
|
/** |
1389
|
|
|
* Applies a tint on the image |
1390
|
|
|
* |
1391
|
|
|
* Value is an hexadecimal color, such as #FFFFFF |
1392
|
|
|
* |
1393
|
|
|
* Default value is null |
1394
|
|
|
* |
1395
|
|
|
* @access public |
1396
|
|
|
* @var string; |
1397
|
|
|
*/ |
1398
|
|
|
var $image_tint_color; |
1399
|
|
|
|
1400
|
|
|
/** |
1401
|
|
|
* Applies a colored overlay on the image |
1402
|
|
|
* |
1403
|
|
|
* Value is an hexadecimal color, such as #FFFFFF |
1404
|
|
|
* |
1405
|
|
|
* To use with {@link image_overlay_opacity} |
1406
|
|
|
* |
1407
|
|
|
* Default value is null |
1408
|
|
|
* |
1409
|
|
|
* @access public |
1410
|
|
|
* @var string; |
1411
|
|
|
*/ |
1412
|
|
|
var $image_overlay_color; |
1413
|
|
|
|
1414
|
|
|
/** |
1415
|
|
|
* Sets the opacity for the colored overlay |
1416
|
|
|
* |
1417
|
|
|
* Value is a percentage, as an integer between 0 (transparent) and 100 (opaque) |
1418
|
|
|
* |
1419
|
|
|
* Unless used with {@link image_overlay_color}, this setting has no effect |
1420
|
|
|
* |
1421
|
|
|
* Default value is 50 |
1422
|
|
|
* |
1423
|
|
|
* @access public |
1424
|
|
|
* @var integer |
1425
|
|
|
*/ |
1426
|
|
|
var $image_overlay_opacity; |
1427
|
|
|
|
1428
|
|
|
/** |
1429
|
|
|
* Soon to be deprecated old form of {@link image_overlay_opacity} |
1430
|
|
|
* |
1431
|
|
|
* @access public |
1432
|
|
|
* @var integer |
1433
|
|
|
*/ |
1434
|
|
|
var $image_overlay_percent; |
1435
|
|
|
|
1436
|
|
|
/** |
1437
|
|
|
* Inverts the color of an image |
1438
|
|
|
* |
1439
|
|
|
* Default value is FALSE |
1440
|
|
|
* |
1441
|
|
|
* @access public |
1442
|
|
|
* @var boolean; |
1443
|
|
|
*/ |
1444
|
|
|
var $image_negative; |
1445
|
|
|
|
1446
|
|
|
/** |
1447
|
|
|
* Turns the image into greyscale |
1448
|
|
|
* |
1449
|
|
|
* Default value is FALSE |
1450
|
|
|
* |
1451
|
|
|
* @access public |
1452
|
|
|
* @var boolean; |
1453
|
|
|
*/ |
1454
|
|
|
var $image_greyscale; |
1455
|
|
|
|
1456
|
|
|
/** |
1457
|
|
|
* Applies an unsharp mask, with alpha transparency support |
1458
|
|
|
* |
1459
|
|
|
* Beware that this unsharp mask is quite resource-intensive |
1460
|
|
|
* |
1461
|
|
|
* Default value is FALSE |
1462
|
|
|
* |
1463
|
|
|
* @access public |
1464
|
|
|
* @var boolean; |
1465
|
|
|
*/ |
1466
|
|
|
var $image_unsharp; |
1467
|
|
|
|
1468
|
|
|
/** |
1469
|
|
|
* Sets the unsharp mask amount |
1470
|
|
|
* |
1471
|
|
|
* Value is an integer between 0 and 500, typically between 50 and 200 |
1472
|
|
|
* |
1473
|
|
|
* Unless used with {@link image_unsharp}, this setting has no effect |
1474
|
|
|
* |
1475
|
|
|
* Default value is 80 |
1476
|
|
|
* |
1477
|
|
|
* @access public |
1478
|
|
|
* @var integer |
1479
|
|
|
*/ |
1480
|
|
|
var $image_unsharp_amount; |
1481
|
|
|
|
1482
|
|
|
/** |
1483
|
|
|
* Sets the unsharp mask radius |
1484
|
|
|
* |
1485
|
|
|
* Value is an integer between 0 and 50, typically between 0.5 and 1 |
1486
|
|
|
* |
1487
|
|
|
* Unless used with {@link image_unsharp}, this setting has no effect |
1488
|
|
|
* |
1489
|
|
|
* Default value is 0.5 |
1490
|
|
|
* |
1491
|
|
|
* @access public |
1492
|
|
|
* @var integer |
1493
|
|
|
*/ |
1494
|
|
|
var $image_unsharp_radius; |
1495
|
|
|
|
1496
|
|
|
/** |
1497
|
|
|
* Sets the unsharp mask threshold |
1498
|
|
|
* |
1499
|
|
|
* Value is an integer between 0 and 255, typically between 0 and 5 |
1500
|
|
|
* |
1501
|
|
|
* Unless used with {@link image_unsharp}, this setting has no effect |
1502
|
|
|
* |
1503
|
|
|
* Default value is 1 |
1504
|
|
|
* |
1505
|
|
|
* @access public |
1506
|
|
|
* @var integer |
1507
|
|
|
*/ |
1508
|
|
|
var $image_unsharp_threshold; |
1509
|
|
|
|
1510
|
|
|
/** |
1511
|
|
|
* Adds a text label on the image |
1512
|
|
|
* |
1513
|
|
|
* Value is a string, any text. Text will not word-wrap, although you can use breaklines in your text "\n" |
1514
|
|
|
* |
1515
|
|
|
* If set, this setting allow the use of all other settings starting with image_text_ |
1516
|
|
|
* |
1517
|
|
|
* Replacement tokens can be used in the string: |
1518
|
|
|
* <pre> |
1519
|
|
|
* gd_version src_name src_name_body src_name_ext |
1520
|
|
|
* src_pathname src_mime src_x src_y |
1521
|
|
|
* src_type src_bits src_pixels |
1522
|
|
|
* src_size src_size_kb src_size_mb src_size_human |
1523
|
|
|
* dst_path dst_name_body dst_pathname |
1524
|
|
|
* dst_name dst_name_ext dst_x dst_y |
1525
|
|
|
* date time host server ip |
1526
|
|
|
* </pre> |
1527
|
|
|
* The tokens must be enclosed in square brackets: [dst_x] will be replaced by the width of the picture |
1528
|
|
|
* |
1529
|
|
|
* Default value is null |
1530
|
|
|
* |
1531
|
|
|
* @access public |
1532
|
|
|
* @var string; |
1533
|
|
|
*/ |
1534
|
|
|
var $image_text; |
1535
|
|
|
|
1536
|
|
|
/** |
1537
|
|
|
* Sets the text direction for the text label |
1538
|
|
|
* |
1539
|
|
|
* Value is either 'h' or 'v', as in horizontal and vertical |
1540
|
|
|
* |
1541
|
|
|
* Default value is h (horizontal) |
1542
|
|
|
* |
1543
|
|
|
* @access public |
1544
|
|
|
* @var string; |
1545
|
|
|
*/ |
1546
|
|
|
var $image_text_direction; |
1547
|
|
|
|
1548
|
|
|
/** |
1549
|
|
|
* Sets the text color for the text label |
1550
|
|
|
* |
1551
|
|
|
* Value is an hexadecimal color, such as #FFFFFF |
1552
|
|
|
* |
1553
|
|
|
* Default value is #FFFFFF (white) |
1554
|
|
|
* |
1555
|
|
|
* @access public |
1556
|
|
|
* @var string; |
1557
|
|
|
*/ |
1558
|
|
|
var $image_text_color; |
1559
|
|
|
|
1560
|
|
|
/** |
1561
|
|
|
* Sets the text opacity in the text label |
1562
|
|
|
* |
1563
|
|
|
* Value is a percentage, as an integer between 0 (transparent) and 100 (opaque) |
1564
|
|
|
* |
1565
|
|
|
* Default value is 100 |
1566
|
|
|
* |
1567
|
|
|
* @access public |
1568
|
|
|
* @var integer |
1569
|
|
|
*/ |
1570
|
|
|
var $image_text_opacity; |
1571
|
|
|
|
1572
|
|
|
/** |
1573
|
|
|
* Soon to be deprecated old form of {@link image_text_opacity} |
1574
|
|
|
* |
1575
|
|
|
* @access public |
1576
|
|
|
* @var integer |
1577
|
|
|
*/ |
1578
|
|
|
var $image_text_percent; |
1579
|
|
|
|
1580
|
|
|
/** |
1581
|
|
|
* Sets the text background color for the text label |
1582
|
|
|
* |
1583
|
|
|
* Value is an hexadecimal color, such as #FFFFFF |
1584
|
|
|
* |
1585
|
|
|
* Default value is null (no background) |
1586
|
|
|
* |
1587
|
|
|
* @access public |
1588
|
|
|
* @var string; |
1589
|
|
|
*/ |
1590
|
|
|
var $image_text_background; |
1591
|
|
|
|
1592
|
|
|
/** |
1593
|
|
|
* Sets the text background opacity in the text label |
1594
|
|
|
* |
1595
|
|
|
* Value is a percentage, as an integer between 0 (transparent) and 100 (opaque) |
1596
|
|
|
* |
1597
|
|
|
* Default value is 100 |
1598
|
|
|
* |
1599
|
|
|
* @access public |
1600
|
|
|
* @var integer |
1601
|
|
|
*/ |
1602
|
|
|
var $image_text_background_opacity; |
1603
|
|
|
|
1604
|
|
|
/** |
1605
|
|
|
* Soon to be deprecated old form of {@link image_text_background_opacity} |
1606
|
|
|
* |
1607
|
|
|
* @access public |
1608
|
|
|
* @var integer |
1609
|
|
|
*/ |
1610
|
|
|
var $image_text_background_percent; |
1611
|
|
|
|
1612
|
|
|
/** |
1613
|
|
|
* Sets the text font in the text label |
1614
|
|
|
* |
1615
|
|
|
* Value is a an integer between 1 and 5 for GD built-in fonts. 1 is the smallest font, 5 the biggest |
1616
|
|
|
* Value can also be a string, which represents the path to a GDF font. The font will be loaded into GD, and used as a built-in font. |
1617
|
|
|
* |
1618
|
|
|
* Default value is 5 |
1619
|
|
|
* |
1620
|
|
|
* @access public |
1621
|
|
|
* @var mixed; |
1622
|
|
|
*/ |
1623
|
|
|
var $image_text_font; |
1624
|
|
|
|
1625
|
|
|
/** |
1626
|
|
|
* Sets the text label position within the image |
1627
|
|
|
* |
1628
|
|
|
* Value is one or two out of 'TBLR' (top, bottom, left, right) |
1629
|
|
|
* |
1630
|
|
|
* The positions are as following: |
1631
|
|
|
* <pre> |
1632
|
|
|
* TL T TR |
1633
|
|
|
* L R |
1634
|
|
|
* BL B BR |
1635
|
|
|
* </pre> |
1636
|
|
|
* |
1637
|
|
|
* Default value is null (centered, horizontal and vertical) |
1638
|
|
|
* |
1639
|
|
|
* Note that is {@link image_text_x} and {@link image_text_y} are used, this setting has no effect |
1640
|
|
|
* |
1641
|
|
|
* @access public |
1642
|
|
|
* @var string; |
1643
|
|
|
*/ |
1644
|
|
|
var $image_text_position; |
1645
|
|
|
|
1646
|
|
|
/** |
1647
|
|
|
* Sets the text label absolute X position within the image |
1648
|
|
|
* |
1649
|
|
|
* Value is in pixels, representing the distance between the left of the image and the label |
1650
|
|
|
* If a negative value is used, it will represent the distance between the right of the image and the label |
1651
|
|
|
* |
1652
|
|
|
* Default value is null (so {@link image_text_position} is used) |
1653
|
|
|
* |
1654
|
|
|
* @access public |
1655
|
|
|
* @var integer |
1656
|
|
|
*/ |
1657
|
|
|
var $image_text_x; |
1658
|
|
|
|
1659
|
|
|
/** |
1660
|
|
|
* Sets the text label absolute Y position within the image |
1661
|
|
|
* |
1662
|
|
|
* Value is in pixels, representing the distance between the top of the image and the label |
1663
|
|
|
* If a negative value is used, it will represent the distance between the bottom of the image and the label |
1664
|
|
|
* |
1665
|
|
|
* Default value is null (so {@link image_text_position} is used) |
1666
|
|
|
* |
1667
|
|
|
* @access public |
1668
|
|
|
* @var integer |
1669
|
|
|
*/ |
1670
|
|
|
var $image_text_y; |
1671
|
|
|
|
1672
|
|
|
/** |
1673
|
|
|
* Sets the text label padding |
1674
|
|
|
* |
1675
|
|
|
* Value is in pixels, representing the distance between the text and the label background border |
1676
|
|
|
* |
1677
|
|
|
* Default value is 0 |
1678
|
|
|
* |
1679
|
|
|
* This setting can be overriden by {@link image_text_padding_x} and {@link image_text_padding_y} |
1680
|
|
|
* |
1681
|
|
|
* @access public |
1682
|
|
|
* @var integer |
1683
|
|
|
*/ |
1684
|
|
|
var $image_text_padding; |
1685
|
|
|
|
1686
|
|
|
/** |
1687
|
|
|
* Sets the text label horizontal padding |
1688
|
|
|
* |
1689
|
|
|
* Value is in pixels, representing the distance between the text and the left and right label background borders |
1690
|
|
|
* |
1691
|
|
|
* Default value is null |
1692
|
|
|
* |
1693
|
|
|
* If set, this setting overrides the horizontal part of {@link image_text_padding} |
1694
|
|
|
* |
1695
|
|
|
* @access public |
1696
|
|
|
* @var integer |
1697
|
|
|
*/ |
1698
|
|
|
var $image_text_padding_x; |
1699
|
|
|
|
1700
|
|
|
/** |
1701
|
|
|
* Sets the text label vertical padding |
1702
|
|
|
* |
1703
|
|
|
* Value is in pixels, representing the distance between the text and the top and bottom label background borders |
1704
|
|
|
* |
1705
|
|
|
* Default value is null |
1706
|
|
|
* |
1707
|
|
|
* If set, his setting overrides the vertical part of {@link image_text_padding} |
1708
|
|
|
* |
1709
|
|
|
* @access public |
1710
|
|
|
* @var integer |
1711
|
|
|
*/ |
1712
|
|
|
var $image_text_padding_y; |
1713
|
|
|
|
1714
|
|
|
/** |
1715
|
|
|
* Sets the text alignment |
1716
|
|
|
* |
1717
|
|
|
* Value is a string, which can be either 'L', 'C' or 'R' |
1718
|
|
|
* |
1719
|
|
|
* Default value is 'C' |
1720
|
|
|
* |
1721
|
|
|
* This setting is relevant only if the text has several lines. |
1722
|
|
|
* |
1723
|
|
|
* @access public |
1724
|
|
|
* @var string; |
1725
|
|
|
*/ |
1726
|
|
|
var $image_text_alignment; |
1727
|
|
|
|
1728
|
|
|
/** |
1729
|
|
|
* Sets the text line spacing |
1730
|
|
|
* |
1731
|
|
|
* Value is an integer, in pixels |
1732
|
|
|
* |
1733
|
|
|
* Default value is 0 |
1734
|
|
|
* |
1735
|
|
|
* This setting is relevant only if the text has several lines. |
1736
|
|
|
* |
1737
|
|
|
* @access public |
1738
|
|
|
* @var integer |
1739
|
|
|
*/ |
1740
|
|
|
var $image_text_line_spacing; |
1741
|
|
|
|
1742
|
|
|
/** |
1743
|
|
|
* Sets the height of the reflection |
1744
|
|
|
* |
1745
|
|
|
* Value is an integer in pixels, or a string which format can be in pixels or percentage. |
1746
|
|
|
* For instance, values can be : 40, '40', '40px' or '40%' |
1747
|
|
|
* |
1748
|
|
|
* Default value is null, no reflection |
1749
|
|
|
* |
1750
|
|
|
* @access public |
1751
|
|
|
* @var mixed; |
1752
|
|
|
*/ |
1753
|
|
|
var $image_reflection_height; |
1754
|
|
|
|
1755
|
|
|
/** |
1756
|
|
|
* Sets the space between the source image and its relection |
1757
|
|
|
* |
1758
|
|
|
* Value is an integer in pixels, which can be negative |
1759
|
|
|
* |
1760
|
|
|
* Default value is 2 |
1761
|
|
|
* |
1762
|
|
|
* This setting is relevant only if {@link image_reflection_height} is set |
1763
|
|
|
* |
1764
|
|
|
* @access public |
1765
|
|
|
* @var integer |
1766
|
|
|
*/ |
1767
|
|
|
var $image_reflection_space; |
1768
|
|
|
|
1769
|
|
|
/** |
1770
|
|
|
* Sets the color of the reflection background (deprecated) |
1771
|
|
|
* |
1772
|
|
|
* Value is an hexadecimal color, such as #FFFFFF |
1773
|
|
|
* |
1774
|
|
|
* Default value is #FFFFFF |
1775
|
|
|
* |
1776
|
|
|
* This setting is relevant only if {@link image_reflection_height} is set |
1777
|
|
|
* |
1778
|
|
|
* This setting is now deprecated in favor of {@link image_default_color} |
1779
|
|
|
* |
1780
|
|
|
* @access public |
1781
|
|
|
* @var string; |
1782
|
|
|
*/ |
1783
|
|
|
var $image_reflection_color; |
1784
|
|
|
|
1785
|
|
|
/** |
1786
|
|
|
* Sets the initial opacity of the reflection |
1787
|
|
|
* |
1788
|
|
|
* Value is an integer between 0 (no opacity) and 100 (full opacity). |
1789
|
|
|
* The reflection will start from {@link image_reflection_opacity} and end up at 0 |
1790
|
|
|
* |
1791
|
|
|
* Default value is 60 |
1792
|
|
|
* |
1793
|
|
|
* This setting is relevant only if {@link image_reflection_height} is set |
1794
|
|
|
* |
1795
|
|
|
* @access public |
1796
|
|
|
* @var integer |
1797
|
|
|
*/ |
1798
|
|
|
var $image_reflection_opacity; |
1799
|
|
|
|
1800
|
|
|
/** |
1801
|
|
|
* Flips the image vertically or horizontally |
1802
|
|
|
* |
1803
|
|
|
* Value is either 'h' or 'v', as in horizontal and vertical |
1804
|
|
|
* |
1805
|
|
|
* Default value is null (no flip) |
1806
|
|
|
* |
1807
|
|
|
* @access public |
1808
|
|
|
* @var string; |
1809
|
|
|
*/ |
1810
|
|
|
var $image_flip; |
1811
|
|
|
|
1812
|
|
|
/** |
1813
|
|
|
* Rotates the image by increments of 45 degrees |
1814
|
|
|
* |
1815
|
|
|
* Value is either 90, 180 or 270 |
1816
|
|
|
* |
1817
|
|
|
* Default value is null (no rotation) |
1818
|
|
|
* |
1819
|
|
|
* @access public |
1820
|
|
|
* @var string; |
1821
|
|
|
*/ |
1822
|
|
|
var $image_rotate; |
1823
|
|
|
|
1824
|
|
|
/** |
1825
|
|
|
* Crops an image |
1826
|
|
|
* |
1827
|
|
|
* Values are four dimensions, or two, or one (CSS style) |
1828
|
|
|
* They represent the amount cropped top, right, bottom and left. |
1829
|
|
|
* These values can either be in an array, or a space separated string. |
1830
|
|
|
* Each value can be in pixels (with or without 'px'), or percentage (of the source image) |
1831
|
|
|
* |
1832
|
|
|
* For instance, are valid: |
1833
|
|
|
* <pre> |
1834
|
|
|
* $foo->image_crop = 20 OR array(20); |
1835
|
|
|
* $foo->image_crop = '20px' OR array('20px'); |
1836
|
|
|
* $foo->image_crop = '20 40' OR array('20', 40); |
1837
|
|
|
* $foo->image_crop = '-20 25%' OR array(-20, '25%'); |
1838
|
|
|
* $foo->image_crop = '20px 25%' OR array('20px', '25%'); |
1839
|
|
|
* $foo->image_crop = '20% 25%' OR array('20%', '25%'); |
1840
|
|
|
* $foo->image_crop = '20% 25% 10% 30%' OR array('20%', '25%', '10%', '30%'); |
1841
|
|
|
* $foo->image_crop = '20px 25px 2px 2px' OR array('20px', '25%px', '2px', '2px'); |
1842
|
|
|
* $foo->image_crop = '20 25% 40px 10%' OR array(20, '25%', '40px', '10%'); |
1843
|
|
|
* </pre> |
1844
|
|
|
* |
1845
|
|
|
* If a value is negative, the image will be expanded, and the extra parts will be filled with black |
1846
|
|
|
* |
1847
|
|
|
* Default value is null (no cropping) |
1848
|
|
|
* |
1849
|
|
|
* @access public |
1850
|
|
|
* @var string OR array; |
1851
|
|
|
*/ |
1852
|
|
|
var $image_crop; |
1853
|
|
|
|
1854
|
|
|
/** |
1855
|
|
|
* Crops an image, before an eventual resizing |
1856
|
|
|
* |
1857
|
|
|
* See {@link image_crop} for valid formats |
1858
|
|
|
* |
1859
|
|
|
* Default value is null (no cropping) |
1860
|
|
|
* |
1861
|
|
|
* @access public |
1862
|
|
|
* @var string OR array; |
1863
|
|
|
*/ |
1864
|
|
|
var $image_precrop; |
1865
|
|
|
|
1866
|
|
|
/** |
1867
|
|
|
* Adds a bevel border on the image |
1868
|
|
|
* |
1869
|
|
|
* Value is a positive integer, representing the thickness of the bevel |
1870
|
|
|
* |
1871
|
|
|
* If the bevel colors are the same as the background, it makes a fade out effect |
1872
|
|
|
* |
1873
|
|
|
* Default value is null (no bevel) |
1874
|
|
|
* |
1875
|
|
|
* @access public |
1876
|
|
|
* @var integer |
1877
|
|
|
*/ |
1878
|
|
|
var $image_bevel; |
1879
|
|
|
|
1880
|
|
|
/** |
1881
|
|
|
* Top and left bevel color |
1882
|
|
|
* |
1883
|
|
|
* Value is a color, in hexadecimal format |
1884
|
|
|
* This setting is used only if {@link image_bevel} is set |
1885
|
|
|
* |
1886
|
|
|
* Default value is #FFFFFF |
1887
|
|
|
* |
1888
|
|
|
* @access public |
1889
|
|
|
* @var string; |
1890
|
|
|
*/ |
1891
|
|
|
var $image_bevel_color1; |
1892
|
|
|
|
1893
|
|
|
/** |
1894
|
|
|
* Right and bottom bevel color |
1895
|
|
|
* |
1896
|
|
|
* Value is a color, in hexadecimal format |
1897
|
|
|
* This setting is used only if {@link image_bevel} is set |
1898
|
|
|
* |
1899
|
|
|
* Default value is #000000 |
1900
|
|
|
* |
1901
|
|
|
* @access public |
1902
|
|
|
* @var string; |
1903
|
|
|
*/ |
1904
|
|
|
var $image_bevel_color2; |
1905
|
|
|
|
1906
|
|
|
/** |
1907
|
|
|
* Adds a single-color border on the outer of the image |
1908
|
|
|
* |
1909
|
|
|
* Values are four dimensions, or two, or one (CSS style) |
1910
|
|
|
* They represent the border thickness top, right, bottom and left. |
1911
|
|
|
* These values can either be in an array, or a space separated string. |
1912
|
|
|
* Each value can be in pixels (with or without 'px'), or percentage (of the source image) |
1913
|
|
|
* |
1914
|
|
|
* See {@link image_crop} for valid formats |
1915
|
|
|
* |
1916
|
|
|
* If a value is negative, the image will be cropped. |
1917
|
|
|
* Note that the dimensions of the picture will be increased by the borders' thickness |
1918
|
|
|
* |
1919
|
|
|
* Default value is null (no border) |
1920
|
|
|
* |
1921
|
|
|
* @access public |
1922
|
|
|
* @var integer |
1923
|
|
|
*/ |
1924
|
|
|
var $image_border; |
1925
|
|
|
|
1926
|
|
|
/** |
1927
|
|
|
* Border color |
1928
|
|
|
* |
1929
|
|
|
* Value is a color, in hexadecimal format. |
1930
|
|
|
* This setting is used only if {@link image_border} is set |
1931
|
|
|
* |
1932
|
|
|
* Default value is #FFFFFF |
1933
|
|
|
* |
1934
|
|
|
* @access public |
1935
|
|
|
* @var string; |
1936
|
|
|
*/ |
1937
|
|
|
var $image_border_color; |
1938
|
|
|
|
1939
|
|
|
/** |
1940
|
|
|
* Sets the opacity for the borders |
1941
|
|
|
* |
1942
|
|
|
* Value is a percentage, as an integer between 0 (transparent) and 100 (opaque) |
1943
|
|
|
* |
1944
|
|
|
* Unless used with {@link image_border}, this setting has no effect |
1945
|
|
|
* |
1946
|
|
|
* Default value is 100 |
1947
|
|
|
* |
1948
|
|
|
* @access public |
1949
|
|
|
* @var integer |
1950
|
|
|
*/ |
1951
|
|
|
var $image_border_opacity; |
1952
|
|
|
|
1953
|
|
|
/** |
1954
|
|
|
* Adds a fading-to-transparent border on the image |
1955
|
|
|
* |
1956
|
|
|
* Values are four dimensions, or two, or one (CSS style) |
1957
|
|
|
* They represent the border thickness top, right, bottom and left. |
1958
|
|
|
* These values can either be in an array, or a space separated string. |
1959
|
|
|
* Each value can be in pixels (with or without 'px'), or percentage (of the source image) |
1960
|
|
|
* |
1961
|
|
|
* See {@link image_crop} for valid formats |
1962
|
|
|
* |
1963
|
|
|
* Note that the dimensions of the picture will not be increased by the borders' thickness |
1964
|
|
|
* |
1965
|
|
|
* Default value is null (no border) |
1966
|
|
|
* |
1967
|
|
|
* @access public |
1968
|
|
|
* @var integer |
1969
|
|
|
*/ |
1970
|
|
|
var $image_border_transparent; |
1971
|
|
|
|
1972
|
|
|
/** |
1973
|
|
|
* Adds a multi-color frame on the outer of the image |
1974
|
|
|
* |
1975
|
|
|
* Value is an integer. Two values are possible for now: |
1976
|
|
|
* 1 for flat border, meaning that the frame is mirrored horizontally and vertically |
1977
|
|
|
* 2 for crossed border, meaning that the frame will be inversed, as in a bevel effect |
1978
|
|
|
* |
1979
|
|
|
* The frame will be composed of colored lines set in {@link image_frame_colors} |
1980
|
|
|
* |
1981
|
|
|
* Note that the dimensions of the picture will be increased by the borders' thickness |
1982
|
|
|
* |
1983
|
|
|
* Default value is null (no frame) |
1984
|
|
|
* |
1985
|
|
|
* @access public |
1986
|
|
|
* @var integer |
1987
|
|
|
*/ |
1988
|
|
|
var $image_frame; |
1989
|
|
|
|
1990
|
|
|
/** |
1991
|
|
|
* Sets the colors used to draw a frame |
1992
|
|
|
* |
1993
|
|
|
* Values is a list of n colors in hexadecimal format. |
1994
|
|
|
* These values can either be in an array, or a space separated string. |
1995
|
|
|
* |
1996
|
|
|
* The colors are listed in the following order: from the outset of the image to its center |
1997
|
|
|
* |
1998
|
|
|
* For instance, are valid: |
1999
|
|
|
* <pre> |
2000
|
|
|
* $foo->image_frame_colors = '#FFFFFF #999999 #666666 #000000'; |
2001
|
|
|
* $foo->image_frame_colors = array('#FFFFFF', '#999999', '#666666', '#000000'); |
2002
|
|
|
* </pre> |
2003
|
|
|
* |
2004
|
|
|
* This setting is used only if {@link image_frame} is set |
2005
|
|
|
* |
2006
|
|
|
* Default value is '#FFFFFF #999999 #666666 #000000' |
2007
|
|
|
* |
2008
|
|
|
* @access public |
2009
|
|
|
* @var string OR array; |
2010
|
|
|
*/ |
2011
|
|
|
var $image_frame_colors; |
2012
|
|
|
|
2013
|
|
|
/** |
2014
|
|
|
* Sets the opacity for the frame |
2015
|
|
|
* |
2016
|
|
|
* Value is a percentage, as an integer between 0 (transparent) and 100 (opaque) |
2017
|
|
|
* |
2018
|
|
|
* Unless used with {@link image_frame}, this setting has no effect |
2019
|
|
|
* |
2020
|
|
|
* Default value is 100 |
2021
|
|
|
* |
2022
|
|
|
* @access public |
2023
|
|
|
* @var integer |
2024
|
|
|
*/ |
2025
|
|
|
var $image_frame_opacity; |
2026
|
|
|
|
2027
|
|
|
/** |
2028
|
|
|
* Adds a watermark on the image |
2029
|
|
|
* |
2030
|
|
|
* Value is a local image filename, relative or absolute. GIF, JPG, BMP and PNG are supported, as well as PNG alpha. |
2031
|
|
|
* |
2032
|
|
|
* If set, this setting allow the use of all other settings starting with image_watermark_ |
2033
|
|
|
* |
2034
|
|
|
* Default value is null |
2035
|
|
|
* |
2036
|
|
|
* @access public |
2037
|
|
|
* @var string; |
2038
|
|
|
*/ |
2039
|
|
|
var $image_watermark; |
2040
|
|
|
|
2041
|
|
|
/** |
2042
|
|
|
* Sets the watermarkposition within the image |
2043
|
|
|
* |
2044
|
|
|
* Value is one or two out of 'TBLR' (top, bottom, left, right) |
2045
|
|
|
* |
2046
|
|
|
* The positions are as following: TL T TR |
2047
|
|
|
* L R |
2048
|
|
|
* BL B BR |
2049
|
|
|
* |
2050
|
|
|
* Default value is null (centered, horizontal and vertical) |
2051
|
|
|
* |
2052
|
|
|
* Note that is {@link image_watermark_x} and {@link image_watermark_y} are used, this setting has no effect |
2053
|
|
|
* |
2054
|
|
|
* @access public |
2055
|
|
|
* @var string; |
2056
|
|
|
*/ |
2057
|
|
|
var $image_watermark_position; |
2058
|
|
|
|
2059
|
|
|
/** |
2060
|
|
|
* Sets the watermark absolute X position within the image |
2061
|
|
|
* |
2062
|
|
|
* Value is in pixels, representing the distance between the top of the image and the watermark |
2063
|
|
|
* If a negative value is used, it will represent the distance between the bottom of the image and the watermark |
2064
|
|
|
* |
2065
|
|
|
* Default value is null (so {@link image_watermark_position} is used) |
2066
|
|
|
* |
2067
|
|
|
* @access public |
2068
|
|
|
* @var integer |
2069
|
|
|
*/ |
2070
|
|
|
var $image_watermark_x; |
2071
|
|
|
|
2072
|
|
|
/** |
2073
|
|
|
* Sets the twatermark absolute Y position within the image |
2074
|
|
|
* |
2075
|
|
|
* Value is in pixels, representing the distance between the left of the image and the watermark |
2076
|
|
|
* If a negative value is used, it will represent the distance between the right of the image and the watermark |
2077
|
|
|
* |
2078
|
|
|
* Default value is null (so {@link image_watermark_position} is used) |
2079
|
|
|
* |
2080
|
|
|
* @access public |
2081
|
|
|
* @var integer |
2082
|
|
|
*/ |
2083
|
|
|
var $image_watermark_y; |
2084
|
|
|
|
2085
|
|
|
/** |
2086
|
|
|
* Prevents the watermark to be resized up if it is smaller than the image |
2087
|
|
|
* |
2088
|
|
|
* If the watermark if smaller than the destination image, taking in account the desired watermark position |
2089
|
|
|
* then it will be resized up to fill in the image (minus the {@link image_watermark_x} or {@link image_watermark_y} values) |
2090
|
|
|
* |
2091
|
|
|
* If you don't want your watermark to be resized in any way, then |
2092
|
|
|
* set {@link image_watermark_no_zoom_in} and {@link image_watermark_no_zoom_out} to true |
2093
|
|
|
* If you want your watermark to be resized up or doan to fill in the image better, then |
2094
|
|
|
* set {@link image_watermark_no_zoom_in} and {@link image_watermark_no_zoom_out} to false |
2095
|
|
|
* |
2096
|
|
|
* Default value is true (so the watermark will not be resized up, which is the behaviour most people expect) |
2097
|
|
|
* |
2098
|
|
|
* @access public |
2099
|
|
|
* @var integer |
2100
|
|
|
*/ |
2101
|
|
|
var $image_watermark_no_zoom_in; |
2102
|
|
|
|
2103
|
|
|
/** |
2104
|
|
|
* Prevents the watermark to be resized down if it is bigger than the image |
2105
|
|
|
* |
2106
|
|
|
* If the watermark if bigger than the destination image, taking in account the desired watermark position |
2107
|
|
|
* then it will be resized down to fit in the image (minus the {@link image_watermark_x} or {@link image_watermark_y} values) |
2108
|
|
|
* |
2109
|
|
|
* If you don't want your watermark to be resized in any way, then |
2110
|
|
|
* set {@link image_watermark_no_zoom_in} and {@link image_watermark_no_zoom_out} to true |
2111
|
|
|
* If you want your watermark to be resized up or doan to fill in the image better, then |
2112
|
|
|
* set {@link image_watermark_no_zoom_in} and {@link image_watermark_no_zoom_out} to false |
2113
|
|
|
* |
2114
|
|
|
* Default value is false (so the watermark may be shrinked to fit in the image) |
2115
|
|
|
* |
2116
|
|
|
* @access public |
2117
|
|
|
* @var integer |
2118
|
|
|
*/ |
2119
|
|
|
var $image_watermark_no_zoom_out; |
2120
|
|
|
|
2121
|
|
|
/** |
2122
|
|
|
* List of MIME types per extension |
2123
|
|
|
* |
2124
|
|
|
* @access private |
2125
|
|
|
* @var array |
2126
|
|
|
*/ |
2127
|
|
|
var $mime_types; |
2128
|
|
|
|
2129
|
|
|
/** |
2130
|
|
|
* Allowed MIME types |
2131
|
|
|
* |
2132
|
|
|
* Default is a selection of safe mime-types, but you might want to change it |
2133
|
|
|
* |
2134
|
|
|
* Simple wildcards are allowed, such as image/* or application/* |
2135
|
|
|
* If there is only one MIME type allowed, then it can be a string instead of an array |
2136
|
|
|
* |
2137
|
|
|
* @access public |
2138
|
|
|
* @var array OR string |
2139
|
|
|
*/ |
2140
|
|
|
var $allowed; |
2141
|
|
|
|
2142
|
|
|
/** |
2143
|
|
|
* Forbidden MIME types |
2144
|
|
|
* |
2145
|
|
|
* Default is a selection of safe mime-types, but you might want to change it |
2146
|
|
|
* To only check for forbidden MIME types, and allow everything else, set {@link allowed} to array('* / *') without the spaces |
2147
|
|
|
* |
2148
|
|
|
* Simple wildcards are allowed, such as image/* or application/* |
2149
|
|
|
* If there is only one MIME type forbidden, then it can be a string instead of an array |
2150
|
|
|
* |
2151
|
|
|
* @access public |
2152
|
|
|
* @var array OR string |
2153
|
|
|
*/ |
2154
|
|
|
var $forbidden; |
2155
|
|
|
|
2156
|
|
|
/** |
2157
|
|
|
* Array of translated error messages |
2158
|
|
|
* |
2159
|
|
|
* By default, the language is english (en_GB) |
2160
|
|
|
* Translations can be in separate files, in a lang/ subdirectory |
2161
|
|
|
* |
2162
|
|
|
* @access public |
2163
|
|
|
* @var array |
2164
|
|
|
*/ |
2165
|
|
|
var $translation; |
2166
|
|
|
|
2167
|
|
|
/** |
2168
|
|
|
* Language selected for the translations |
2169
|
|
|
* |
2170
|
|
|
* By default, the language is english ("en_GB") |
2171
|
|
|
* |
2172
|
|
|
* @access public |
2173
|
|
|
* @var array |
2174
|
|
|
*/ |
2175
|
|
|
var $language; |
2176
|
|
|
|
2177
|
|
|
/** |
2178
|
|
|
* Init or re-init all the processing variables to their default values |
2179
|
|
|
* |
2180
|
|
|
* This function is called in the constructor, and after each call of {@link process} |
2181
|
|
|
* |
2182
|
|
|
* @access private |
2183
|
|
|
*/ |
2184
|
|
|
function init() { |
2185
|
|
|
|
2186
|
|
|
// overiddable variables |
2187
|
|
|
$this->file_new_name_body = null; // replace the name body |
2188
|
|
|
$this->file_name_body_add = null; // append to the name body |
2189
|
|
|
$this->file_name_body_pre = null; // prepend to the name body |
2190
|
|
|
$this->file_new_name_ext = null; // replace the file extension |
2191
|
|
|
$this->file_safe_name = true; // format safely the filename |
2192
|
|
|
$this->file_force_extension = true; // forces extension if there isn't one |
2193
|
|
|
$this->file_overwrite = false; // allows overwritting if the file already exists |
2194
|
|
|
$this->file_auto_rename = true; // auto-rename if the file already exists |
2195
|
|
|
$this->dir_auto_create = true; // auto-creates directory if missing |
2196
|
|
|
$this->dir_auto_chmod = true; // auto-chmod directory if not writeable |
2197
|
|
|
$this->dir_chmod = 0777; // default chmod to use |
|
|
|
|
2198
|
|
|
|
2199
|
|
|
$this->no_script = true; // turns scripts into test files |
2200
|
|
|
$this->mime_check = true; // checks the mime type against the allowed list |
2201
|
|
|
|
2202
|
|
|
// these are the different MIME detection methods. if one of these method doesn't work on your |
2203
|
|
|
// system, you can deactivate it here; just set it to false |
2204
|
|
|
$this->mime_fileinfo = true; // MIME detection with Fileinfo PECL extension |
2205
|
|
|
$this->mime_file = true; // MIME detection with UNIX file() command |
2206
|
|
|
$this->mime_magic = true; // MIME detection with mime_magic (mime_content_type()) |
2207
|
|
|
$this->mime_getimagesize = true; // MIME detection with getimagesize() |
2208
|
|
|
|
2209
|
|
|
// get the default max size from php.ini |
2210
|
|
|
$this->file_max_size_raw = trim(ini_get('upload_max_filesize')); |
2211
|
|
|
$this->file_max_size = $this->getsize($this->file_max_size_raw); |
|
|
|
|
2212
|
|
|
|
2213
|
|
|
$this->image_resize = false; // resize the image |
2214
|
|
|
$this->image_convert = ''; // convert. values :''; 'png'; 'jpeg'; 'gif'; 'bmp' |
2215
|
|
|
|
2216
|
|
|
$this->image_x = 150; |
2217
|
|
|
$this->image_y = 150; |
2218
|
|
|
$this->image_ratio = false; // keeps aspect ratio with x and y dimensions |
2219
|
|
|
$this->image_ratio_crop = false; // keeps aspect ratio with x and y dimensions, filling the space |
2220
|
|
|
$this->image_ratio_fill = false; // keeps aspect ratio with x and y dimensions, fitting the image in the space, and coloring the rest |
2221
|
|
|
$this->image_ratio_pixels = false; // keeps aspect ratio, calculating x and y so that the image is approx the set number of pixels |
2222
|
|
|
$this->image_ratio_no_zoom_in = false; |
2223
|
|
|
$this->image_ratio_no_zoom_out = false; |
2224
|
|
|
$this->image_ratio_x = false; // calculate the $image_x if true |
2225
|
|
|
$this->image_ratio_y = false; // calculate the $image_y if true |
2226
|
|
|
$this->jpeg_quality = 85; |
2227
|
|
|
$this->jpeg_size = null; |
2228
|
|
|
$this->preserve_transparency = false; |
|
|
|
|
2229
|
|
|
$this->image_is_transparent = false; |
2230
|
|
|
$this->image_transparent_color = null; |
2231
|
|
|
$this->image_background_color = null; |
2232
|
|
|
$this->image_default_color = '#ffffff'; |
|
|
|
|
2233
|
|
|
$this->image_is_palette = false; |
2234
|
|
|
|
2235
|
|
|
$this->image_max_width = null; |
2236
|
|
|
$this->image_max_height = null; |
2237
|
|
|
$this->image_max_pixels = null; |
2238
|
|
|
$this->image_max_ratio = null; |
2239
|
|
|
$this->image_min_width = null; |
2240
|
|
|
$this->image_min_height = null; |
2241
|
|
|
$this->image_min_pixels = null; |
2242
|
|
|
$this->image_min_ratio = null; |
2243
|
|
|
|
2244
|
|
|
$this->image_brightness = null; |
2245
|
|
|
$this->image_contrast = null; |
2246
|
|
|
$this->image_opacity = null; |
2247
|
|
|
$this->image_threshold = null; |
2248
|
|
|
$this->image_tint_color = null; |
2249
|
|
|
$this->image_overlay_color = null; |
2250
|
|
|
$this->image_overlay_opacity = null; |
2251
|
|
|
$this->image_overlay_percent = null; |
2252
|
|
|
$this->image_negative = false; |
2253
|
|
|
$this->image_greyscale = false; |
2254
|
|
|
$this->image_unsharp = false; |
2255
|
|
|
$this->image_unsharp_amount = 80; |
2256
|
|
|
$this->image_unsharp_radius = 0.5; |
|
|
|
|
2257
|
|
|
$this->image_unsharp_threshold = 1; |
2258
|
|
|
|
2259
|
|
|
$this->image_text = null; |
2260
|
|
|
$this->image_text_direction = null; |
2261
|
|
|
$this->image_text_color = '#FFFFFF'; |
2262
|
|
|
$this->image_text_opacity = 100; |
2263
|
|
|
$this->image_text_percent = 100; |
2264
|
|
|
$this->image_text_background = null; |
2265
|
|
|
$this->image_text_background_opacity = 100; |
2266
|
|
|
$this->image_text_background_percent = 100; |
2267
|
|
|
$this->image_text_font = 5; |
2268
|
|
|
$this->image_text_x = null; |
2269
|
|
|
$this->image_text_y = null; |
2270
|
|
|
$this->image_text_position = null; |
2271
|
|
|
$this->image_text_padding = 0; |
2272
|
|
|
$this->image_text_padding_x = null; |
2273
|
|
|
$this->image_text_padding_y = null; |
2274
|
|
|
$this->image_text_alignment = 'C'; |
2275
|
|
|
$this->image_text_line_spacing = 0; |
2276
|
|
|
|
2277
|
|
|
$this->image_reflection_height = null; |
2278
|
|
|
$this->image_reflection_space = 2; |
2279
|
|
|
$this->image_reflection_color = '#ffffff'; |
2280
|
|
|
$this->image_reflection_opacity = 60; |
2281
|
|
|
|
2282
|
|
|
$this->image_watermark = null; |
2283
|
|
|
$this->image_watermark_x = null; |
2284
|
|
|
$this->image_watermark_y = null; |
2285
|
|
|
$this->image_watermark_position = null; |
2286
|
|
|
$this->image_watermark_no_zoom_in = true; |
|
|
|
|
2287
|
|
|
$this->image_watermark_no_zoom_out = false; |
|
|
|
|
2288
|
|
|
|
2289
|
|
|
$this->image_flip = null; |
2290
|
|
|
$this->image_rotate = null; |
2291
|
|
|
$this->image_crop = null; |
2292
|
|
|
$this->image_precrop = null; |
2293
|
|
|
|
2294
|
|
|
$this->image_bevel = null; |
2295
|
|
|
$this->image_bevel_color1 = '#FFFFFF'; |
2296
|
|
|
$this->image_bevel_color2 = '#000000'; |
2297
|
|
|
$this->image_border = null; |
2298
|
|
|
$this->image_border_color = '#FFFFFF'; |
2299
|
|
|
$this->image_border_opacity = 100; |
2300
|
|
|
$this->image_border_transparent = null; |
2301
|
|
|
$this->image_frame = null; |
2302
|
|
|
$this->image_frame_colors = '#FFFFFF #999999 #666666 #000000'; |
2303
|
|
|
$this->image_frame_opacity = 100; |
2304
|
|
|
|
2305
|
|
|
$this->forbidden = array(); |
2306
|
|
|
$this->allowed = array( |
2307
|
|
|
'application/arj', |
2308
|
|
|
'application/excel', |
2309
|
|
|
'application/gnutar', |
2310
|
|
|
'application/mspowerpoint', |
2311
|
|
|
'application/msword', |
2312
|
|
|
'application/octet-stream', |
2313
|
|
|
'application/onenote', |
2314
|
|
|
'application/pdf', |
2315
|
|
|
'application/plain', |
2316
|
|
|
'application/postscript', |
2317
|
|
|
'application/powerpoint', |
2318
|
|
|
'application/rar', |
2319
|
|
|
'application/rtf', |
2320
|
|
|
'application/vnd.ms-excel', |
2321
|
|
|
'application/vnd.ms-excel.addin.macroEnabled.12', |
2322
|
|
|
'application/vnd.ms-excel.sheet.binary.macroEnabled.12', |
2323
|
|
|
'application/vnd.ms-excel.sheet.macroEnabled.12', |
2324
|
|
|
'application/vnd.ms-excel.template.macroEnabled.12', |
2325
|
|
|
'application/vnd.ms-office', |
2326
|
|
|
'application/vnd.ms-officetheme', |
2327
|
|
|
'application/vnd.ms-powerpoint', |
2328
|
|
|
'application/vnd.ms-powerpoint.addin.macroEnabled.12', |
2329
|
|
|
'application/vnd.ms-powerpoint.presentation.macroEnabled.12', |
2330
|
|
|
'application/vnd.ms-powerpoint.slide.macroEnabled.12', |
2331
|
|
|
'application/vnd.ms-powerpoint.slideshow.macroEnabled.12', |
2332
|
|
|
'application/vnd.ms-powerpoint.template.macroEnabled.12', |
2333
|
|
|
'application/vnd.ms-word', |
2334
|
|
|
'application/vnd.ms-word.document.macroEnabled.12', |
2335
|
|
|
'application/vnd.ms-word.template.macroEnabled.12', |
2336
|
|
|
'application/vnd.oasis.opendocument.chart', |
2337
|
|
|
'application/vnd.oasis.opendocument.database', |
2338
|
|
|
'application/vnd.oasis.opendocument.formula', |
2339
|
|
|
'application/vnd.oasis.opendocument.graphics', |
2340
|
|
|
'application/vnd.oasis.opendocument.graphics-template', |
2341
|
|
|
'application/vnd.oasis.opendocument.image', |
2342
|
|
|
'application/vnd.oasis.opendocument.presentation', |
2343
|
|
|
'application/vnd.oasis.opendocument.presentation-template', |
2344
|
|
|
'application/vnd.oasis.opendocument.spreadsheet', |
2345
|
|
|
'application/vnd.oasis.opendocument.spreadsheet-template', |
2346
|
|
|
'application/vnd.oasis.opendocument.text', |
2347
|
|
|
'application/vnd.oasis.opendocument.text-master', |
2348
|
|
|
'application/vnd.oasis.opendocument.text-template', |
2349
|
|
|
'application/vnd.oasis.opendocument.text-web', |
2350
|
|
|
'application/vnd.openofficeorg.extension', |
2351
|
|
|
'application/vnd.openxmlformats-officedocument.presentationml.presentation', |
2352
|
|
|
'application/vnd.openxmlformats-officedocument.presentationml.slide', |
2353
|
|
|
'application/vnd.openxmlformats-officedocument.presentationml.slideshow', |
2354
|
|
|
'application/vnd.openxmlformats-officedocument.presentationml.template', |
2355
|
|
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', |
2356
|
|
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.template', |
2357
|
|
|
'application/vnd.openxmlformats-officedocument.wordprocessingml.document', |
2358
|
|
|
'application/vnd.openxmlformats-officedocument.wordprocessingml.document', |
2359
|
|
|
'application/vnd.openxmlformats-officedocument.wordprocessingml.template', |
2360
|
|
|
'application/vocaltec-media-file', |
2361
|
|
|
'application/wordperfect', |
2362
|
|
|
'application/x-bittorrent', |
2363
|
|
|
'application/x-bzip', |
2364
|
|
|
'application/x-bzip2', |
2365
|
|
|
'application/x-compressed', |
2366
|
|
|
'application/x-excel', |
2367
|
|
|
'application/x-gzip', |
2368
|
|
|
'application/x-latex', |
2369
|
|
|
'application/x-midi', |
2370
|
|
|
'application/xml', |
2371
|
|
|
'application/x-msexcel', |
2372
|
|
|
'application/x-rar', |
2373
|
|
|
'application/x-rar-compressed', |
2374
|
|
|
'application/x-rtf', |
2375
|
|
|
'application/x-shockwave-flash', |
2376
|
|
|
'application/x-sit', |
2377
|
|
|
'application/x-stuffit', |
2378
|
|
|
'application/x-troff-msvideo', |
2379
|
|
|
'application/x-zip', |
2380
|
|
|
'application/x-zip-compressed', |
2381
|
|
|
'application/zip', |
2382
|
|
|
'audio/*', |
2383
|
|
|
'image/*', |
2384
|
|
|
'multipart/x-gzip', |
2385
|
|
|
'multipart/x-zip', |
2386
|
|
|
'text/plain', |
2387
|
|
|
'text/rtf', |
2388
|
|
|
'text/richtext', |
2389
|
|
|
'text/xml', |
2390
|
|
|
'video/*' |
2391
|
|
|
); |
2392
|
|
|
|
2393
|
|
|
$this->mime_types = array( |
2394
|
|
|
'jpg' => 'image/jpeg', |
2395
|
|
|
'jpeg' => 'image/jpeg', |
2396
|
|
|
'jpe' => 'image/jpeg', |
2397
|
|
|
'gif' => 'image/gif', |
2398
|
|
|
'png' => 'image/png', |
2399
|
|
|
'bmp' => 'image/bmp', |
2400
|
|
|
'flv' => 'video/x-flv', |
2401
|
|
|
'js' => 'application/x-javascript', |
2402
|
|
|
'json' => 'application/json', |
2403
|
|
|
'tiff' => 'image/tiff', |
2404
|
|
|
'css' => 'text/css', |
2405
|
|
|
'xml' => 'application/xml', |
2406
|
|
|
'doc' => 'application/msword', |
2407
|
|
|
'docx' => 'application/msword', |
2408
|
|
|
'xls' => 'application/vnd.ms-excel', |
2409
|
|
|
'xlt' => 'application/vnd.ms-excel', |
2410
|
|
|
'xlm' => 'application/vnd.ms-excel', |
2411
|
|
|
'xld' => 'application/vnd.ms-excel', |
2412
|
|
|
'xla' => 'application/vnd.ms-excel', |
2413
|
|
|
'xlc' => 'application/vnd.ms-excel', |
2414
|
|
|
'xlw' => 'application/vnd.ms-excel', |
2415
|
|
|
'xll' => 'application/vnd.ms-excel', |
2416
|
|
|
'ppt' => 'application/vnd.ms-powerpoint', |
2417
|
|
|
'pps' => 'application/vnd.ms-powerpoint', |
2418
|
|
|
'rtf' => 'application/rtf', |
2419
|
|
|
'pdf' => 'application/pdf', |
2420
|
|
|
'html' => 'text/html', |
2421
|
|
|
'htm' => 'text/html', |
2422
|
|
|
'php' => 'text/html', |
2423
|
|
|
'txt' => 'text/plain', |
2424
|
|
|
'mpeg' => 'video/mpeg', |
2425
|
|
|
'mpg' => 'video/mpeg', |
2426
|
|
|
'mpe' => 'video/mpeg', |
2427
|
|
|
'mp3' => 'audio/mpeg3', |
2428
|
|
|
'wav' => 'audio/wav', |
2429
|
|
|
'aiff' => 'audio/aiff', |
2430
|
|
|
'aif' => 'audio/aiff', |
2431
|
|
|
'avi' => 'video/msvideo', |
2432
|
|
|
'wmv' => 'video/x-ms-wmv', |
2433
|
|
|
'mov' => 'video/quicktime', |
2434
|
|
|
'zip' => 'application/zip', |
2435
|
|
|
'tar' => 'application/x-tar', |
2436
|
|
|
'swf' => 'application/x-shockwave-flash', |
2437
|
|
|
'odt' => 'application/vnd.oasis.opendocument.text', |
2438
|
|
|
'ott' => 'application/vnd.oasis.opendocument.text-template', |
2439
|
|
|
'oth' => 'application/vnd.oasis.opendocument.text-web', |
2440
|
|
|
'odm' => 'application/vnd.oasis.opendocument.text-master', |
2441
|
|
|
'odg' => 'application/vnd.oasis.opendocument.graphics', |
2442
|
|
|
'otg' => 'application/vnd.oasis.opendocument.graphics-template', |
2443
|
|
|
'odp' => 'application/vnd.oasis.opendocument.presentation', |
2444
|
|
|
'otp' => 'application/vnd.oasis.opendocument.presentation-template', |
2445
|
|
|
'ods' => 'application/vnd.oasis.opendocument.spreadsheet', |
2446
|
|
|
'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template', |
2447
|
|
|
'odc' => 'application/vnd.oasis.opendocument.chart', |
2448
|
|
|
'odf' => 'application/vnd.oasis.opendocument.formula', |
2449
|
|
|
'odb' => 'application/vnd.oasis.opendocument.database', |
2450
|
|
|
'odi' => 'application/vnd.oasis.opendocument.image', |
2451
|
|
|
'oxt' => 'application/vnd.openofficeorg.extension', |
2452
|
|
|
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', |
2453
|
|
|
'docm' => 'application/vnd.ms-word.document.macroEnabled.12', |
2454
|
|
|
'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template', |
2455
|
|
|
'dotm' => 'application/vnd.ms-word.template.macroEnabled.12', |
2456
|
|
|
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', |
2457
|
|
|
'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12', |
2458
|
|
|
'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template', |
2459
|
|
|
'xltm' => 'application/vnd.ms-excel.template.macroEnabled.12', |
2460
|
|
|
'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12', |
2461
|
|
|
'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12', |
2462
|
|
|
'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', |
2463
|
|
|
'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12', |
2464
|
|
|
'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', |
2465
|
|
|
'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12', |
2466
|
|
|
'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template', |
2467
|
|
|
'potm' => 'application/vnd.ms-powerpoint.template.macroEnabled.12', |
2468
|
|
|
'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12', |
2469
|
|
|
'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide', |
2470
|
|
|
'sldm' => 'application/vnd.ms-powerpoint.slide.macroEnabled.12', |
2471
|
|
|
'thmx' => 'application/vnd.ms-officetheme', |
2472
|
|
|
'onetoc' => 'application/onenote', |
2473
|
|
|
'onetoc2' => 'application/onenote', |
2474
|
|
|
'onetmp' => 'application/onenote', |
2475
|
|
|
'onepkg' => 'application/onenote', |
2476
|
|
|
); |
2477
|
|
|
|
2478
|
|
|
} |
2479
|
|
|
|
2480
|
|
|
/** |
2481
|
|
|
* Constructor. Checks if the file has been uploaded |
2482
|
|
|
* |
2483
|
|
|
* The constructor takes $_FILES['form_field'] array as argument |
2484
|
|
|
* where form_field is the form field name |
2485
|
|
|
* |
2486
|
|
|
* The constructor will check if the file has been uploaded in its temporary location, and |
2487
|
|
|
* accordingly will set {@link uploaded} (and {@link error} is an error occurred) |
2488
|
|
|
* |
2489
|
|
|
* If the file has been uploaded, the constructor will populate all the variables holding the upload |
2490
|
|
|
* information (none of the processing class variables are used here). |
2491
|
|
|
* You can have access to information about the file (name, size, MIME type...). |
2492
|
|
|
* |
2493
|
|
|
* |
2494
|
|
|
* Alternatively, you can set the first argument to be a local filename (string) |
2495
|
|
|
* This allows processing of a local file, as if the file was uploaded |
2496
|
|
|
* |
2497
|
|
|
* The optional second argument allows you to set the language for the error messages |
2498
|
|
|
* |
2499
|
|
|
* @access private |
2500
|
|
|
* @param array $file $_FILES['form_field'] |
2501
|
|
|
* or string $file Local filename |
2502
|
|
|
* @param string $lang Optional language code |
2503
|
|
|
*/ |
2504
|
|
|
function upload($file, $lang = 'en_GB') { |
2505
|
|
|
|
2506
|
|
|
$this->version = '0.31'; |
2507
|
|
|
|
2508
|
|
|
$this->file_src_name = ''; |
2509
|
|
|
$this->file_src_name_body = ''; |
2510
|
|
|
$this->file_src_name_ext = ''; |
2511
|
|
|
$this->file_src_mime = ''; |
2512
|
|
|
$this->file_src_size = ''; |
|
|
|
|
2513
|
|
|
$this->file_src_error = ''; |
2514
|
|
|
$this->file_src_pathname = ''; |
2515
|
|
|
$this->file_src_temp = ''; |
2516
|
|
|
|
2517
|
|
|
$this->file_dst_path = ''; |
2518
|
|
|
$this->file_dst_name = ''; |
2519
|
|
|
$this->file_dst_name_body = ''; |
2520
|
|
|
$this->file_dst_name_ext = ''; |
2521
|
|
|
$this->file_dst_pathname = ''; |
2522
|
|
|
|
2523
|
|
|
$this->image_src_x = null; |
2524
|
|
|
$this->image_src_y = null; |
2525
|
|
|
$this->image_src_bits = null; |
2526
|
|
|
$this->image_src_type = null; |
2527
|
|
|
$this->image_src_pixels = null; |
2528
|
|
|
$this->image_dst_x = 0; |
2529
|
|
|
$this->image_dst_y = 0; |
2530
|
|
|
|
2531
|
|
|
$this->uploaded = true; |
2532
|
|
|
$this->no_upload_check = false; |
2533
|
|
|
$this->processed = true; |
2534
|
|
|
$this->error = ''; |
2535
|
|
|
$this->log = ''; |
2536
|
|
|
$this->allowed = array(); |
2537
|
|
|
$this->forbidden = array(); |
2538
|
|
|
$this->file_is_image = false; |
2539
|
|
|
$this->init(); |
2540
|
|
|
$info = null; |
2541
|
|
|
$mime_from_browser = null; |
2542
|
|
|
|
2543
|
|
|
// sets default language |
2544
|
|
|
$this->translation = array(); |
2545
|
|
|
$this->translation['file_error'] = 'File error. Please try again.'; |
2546
|
|
|
$this->translation['local_file_missing'] = 'Local file doesn\'t exist.'; |
2547
|
|
|
$this->translation['local_file_not_readable'] = 'Local file is not readable.'; |
2548
|
|
|
$this->translation['uploaded_too_big_ini'] = 'File upload error (the uploaded file exceeds the upload_max_filesize directive in php.ini).'; |
2549
|
|
|
$this->translation['uploaded_too_big_html'] = 'File upload error (the uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form).'; |
2550
|
|
|
$this->translation['uploaded_partial'] = 'File upload error (the uploaded file was only partially uploaded).'; |
2551
|
|
|
$this->translation['uploaded_missing'] = 'File upload error (no file was uploaded).'; |
2552
|
|
|
$this->translation['uploaded_no_tmp_dir'] = 'File upload error (missing a temporary folder).'; |
2553
|
|
|
$this->translation['uploaded_cant_write'] = 'File upload error (failed to write file to disk).'; |
2554
|
|
|
$this->translation['uploaded_err_extension'] = 'File upload error (file upload stopped by extension).'; |
2555
|
|
|
$this->translation['uploaded_unknown'] = 'File upload error (unknown error code).'; |
2556
|
|
|
$this->translation['try_again'] = 'File upload error. Please try again.'; |
2557
|
|
|
$this->translation['file_too_big'] = 'File too big.'; |
2558
|
|
|
$this->translation['no_mime'] = 'MIME type can\'t be detected.'; |
2559
|
|
|
$this->translation['incorrect_file'] = 'Incorrect type of file.'; |
2560
|
|
|
$this->translation['image_too_wide'] = 'Image too wide.'; |
2561
|
|
|
$this->translation['image_too_narrow'] = 'Image too narrow.'; |
2562
|
|
|
$this->translation['image_too_high'] = 'Image too tall.'; |
2563
|
|
|
$this->translation['image_too_short'] = 'Image too short.'; |
2564
|
|
|
$this->translation['ratio_too_high'] = 'Image ratio too high (image too wide).'; |
2565
|
|
|
$this->translation['ratio_too_low'] = 'Image ratio too low (image too high).'; |
2566
|
|
|
$this->translation['too_many_pixels'] = 'Image has too many pixels.'; |
2567
|
|
|
$this->translation['not_enough_pixels'] = 'Image has not enough pixels.'; |
2568
|
|
|
$this->translation['file_not_uploaded'] = 'File not uploaded. Can\'t carry on a process.'; |
2569
|
|
|
$this->translation['already_exists'] = '%s already exists. Please change the file name.'; |
2570
|
|
|
$this->translation['temp_file_missing'] = 'No correct temp source file. Can\'t carry on a process.'; |
2571
|
|
|
$this->translation['source_missing'] = 'No correct uploaded source file. Can\'t carry on a process.'; |
2572
|
|
|
$this->translation['destination_dir'] = 'Destination directory can\'t be created. Can\'t carry on a process.'; |
2573
|
|
|
$this->translation['destination_dir_missing'] = 'Destination directory doesn\'t exist. Can\'t carry on a process.'; |
2574
|
|
|
$this->translation['destination_path_not_dir'] = 'Destination path is not a directory. Can\'t carry on a process.'; |
2575
|
|
|
$this->translation['destination_dir_write'] = 'Destination directory can\'t be made writeable. Can\'t carry on a process.'; |
2576
|
|
|
$this->translation['destination_path_write'] = 'Destination path is not a writeable. Can\'t carry on a process.'; |
2577
|
|
|
$this->translation['temp_file'] = 'Can\'t create the temporary file. Can\'t carry on a process.'; |
2578
|
|
|
$this->translation['source_not_readable'] = 'Source file is not readable. Can\'t carry on a process.'; |
2579
|
|
|
$this->translation['no_create_support'] = 'No create from %s support.'; |
2580
|
|
|
$this->translation['create_error'] = 'Error in creating %s image from source.'; |
2581
|
|
|
$this->translation['source_invalid'] = 'Can\'t read image source. Not an image?.'; |
2582
|
|
|
$this->translation['gd_missing'] = 'GD doesn\'t seem to be present.'; |
2583
|
|
|
$this->translation['watermark_no_create_support'] = 'No create from %s support, can\'t read watermark.'; |
2584
|
|
|
$this->translation['watermark_create_error'] = 'No %s read support, can\'t create watermark.'; |
2585
|
|
|
$this->translation['watermark_invalid'] = 'Unknown image format, can\'t read watermark.'; |
2586
|
|
|
$this->translation['file_create'] = 'No %s create support.'; |
2587
|
|
|
$this->translation['no_conversion_type'] = 'No conversion type defined.'; |
2588
|
|
|
$this->translation['copy_failed'] = 'Error copying file on the server. copy() failed.'; |
2589
|
|
|
$this->translation['reading_failed'] = 'Error reading the file.'; |
2590
|
|
|
|
2591
|
|
|
// determines the language |
2592
|
|
|
$this->lang = $lang; |
2593
|
|
|
if ($this->lang != 'en_GB' && file_exists(dirname(__FILE__).'/lang') && file_exists(dirname(__FILE__).'/lang/class.upload.' . $lang . '.php')) { |
2594
|
|
|
$translation = null; |
2595
|
|
|
include(dirname(__FILE__).'/lang/class.upload.' . $lang . '.php'); |
2596
|
|
|
if (is_array($translation)) { |
2597
|
|
|
$this->translation = array_merge($this->translation, $translation); |
2598
|
|
|
} else { |
2599
|
|
|
$this->lang = 'en_GB'; |
2600
|
|
|
} |
2601
|
|
|
} |
2602
|
|
|
|
2603
|
|
|
|
2604
|
|
|
// determines the supported MIME types, and matching image format |
2605
|
|
|
$this->image_supported = array(); |
2606
|
|
|
if ($this->gdversion()) { |
2607
|
|
|
if (imagetypes() & IMG_GIF) { |
2608
|
|
|
$this->image_supported['image/gif'] = 'gif'; |
2609
|
|
|
} |
2610
|
|
|
if (imagetypes() & IMG_JPG) { |
2611
|
|
|
$this->image_supported['image/jpg'] = 'jpg'; |
2612
|
|
|
$this->image_supported['image/jpeg'] = 'jpg'; |
2613
|
|
|
$this->image_supported['image/pjpeg'] = 'jpg'; |
2614
|
|
|
} |
2615
|
|
|
if (imagetypes() & IMG_PNG) { |
2616
|
|
|
$this->image_supported['image/png'] = 'png'; |
2617
|
|
|
$this->image_supported['image/x-png'] = 'png'; |
2618
|
|
|
} |
2619
|
|
|
if (imagetypes() & IMG_WBMP) { |
2620
|
|
|
$this->image_supported['image/bmp'] = 'bmp'; |
2621
|
|
|
$this->image_supported['image/x-ms-bmp'] = 'bmp'; |
2622
|
|
|
$this->image_supported['image/x-windows-bmp'] = 'bmp'; |
2623
|
|
|
} |
2624
|
|
|
} |
2625
|
|
|
|
2626
|
|
|
// display some system information |
2627
|
|
|
if (empty($this->log)) { |
2628
|
|
|
$this->log .= '<b>system information</b><br />'; |
2629
|
|
|
if (function_exists('ini_get_all')) { |
2630
|
|
|
$inis = ini_get_all(); |
2631
|
|
|
$open_basedir = (array_key_exists('open_basedir', $inis) && array_key_exists('local_value', $inis['open_basedir']) && !empty($inis['open_basedir']['local_value'])) ? $inis['open_basedir']['local_value'] : false; |
2632
|
|
|
} else { |
2633
|
|
|
$open_basedir = false; |
2634
|
|
|
} |
2635
|
|
|
$gd = $this->gdversion() ? $this->gdversion(true) : 'GD not present'; |
2636
|
|
|
$supported = trim((in_array('png', $this->image_supported) ? 'png' : '') . ' ' . (in_array('jpg', $this->image_supported) ? 'jpg' : '') . ' ' . (in_array('gif', $this->image_supported) ? 'gif' : '') . ' ' . (in_array('bmp', $this->image_supported) ? 'bmp' : '')); |
2637
|
|
|
$this->log .= '- class version : ' . $this->version . '<br />'; |
2638
|
|
|
$this->log .= '- operating system : ' . PHP_OS . '<br />'; |
2639
|
|
|
$this->log .= '- PHP version : ' . PHP_VERSION . '<br />'; |
2640
|
|
|
$this->log .= '- GD version : ' . $gd . '<br />'; |
2641
|
|
|
$this->log .= '- supported image types : ' . (!empty($supported) ? $supported : 'none') . '<br />'; |
2642
|
|
|
$this->log .= '- open_basedir : ' . (!empty($open_basedir) ? $open_basedir : 'no restriction') . '<br />'; |
2643
|
|
|
$this->log .= '- upload_max_filesize : ' . $this->file_max_size_raw . ' (' . $this->file_max_size . ' bytes)<br />'; |
2644
|
|
|
$this->log .= '- language : ' . $this->lang . '<br />'; |
2645
|
|
|
} |
2646
|
|
|
|
2647
|
|
|
if (!$file) { |
|
|
|
|
2648
|
|
|
$this->uploaded = false; |
2649
|
|
|
$this->error = $this->translate('file_error'); |
2650
|
|
|
} |
2651
|
|
|
|
2652
|
|
|
// check if we sent a local filename rather than a $_FILE element |
2653
|
|
|
if (!is_array($file)) { |
2654
|
|
|
if (empty($file)) { |
2655
|
|
|
$this->uploaded = false; |
2656
|
|
|
$this->error = $this->translate('file_error'); |
2657
|
|
|
} else { |
2658
|
|
|
$this->no_upload_check = TRUE; |
2659
|
|
|
// this is a local filename, i.e.not uploaded |
2660
|
|
|
$this->log .= '<b>' . $this->translate("source is a local file") . ' ' . $file . '</b><br />'; |
2661
|
|
|
|
2662
|
|
|
if ($this->uploaded && !file_exists($file)) { |
2663
|
|
|
$this->uploaded = false; |
2664
|
|
|
$this->error = $this->translate('local_file_missing'); |
2665
|
|
|
} |
2666
|
|
|
|
2667
|
|
|
if ($this->uploaded && !is_readable($file)) { |
2668
|
|
|
$this->uploaded = false; |
2669
|
|
|
$this->error = $this->translate('local_file_not_readable'); |
2670
|
|
|
} |
2671
|
|
|
|
2672
|
|
|
if ($this->uploaded) { |
2673
|
|
|
$this->file_src_pathname = $file; |
2674
|
|
|
$this->file_src_name = basename($file); |
2675
|
|
|
$this->log .= '- local file name OK<br />'; |
2676
|
|
|
preg_match('/\.([^\.]*$)/', $this->file_src_name, $extension); |
2677
|
|
|
if (is_array($extension) && sizeof($extension) > 0) { |
2678
|
|
|
$this->file_src_name_ext = strtolower($extension[1]); |
2679
|
|
|
$this->file_src_name_body = substr($this->file_src_name, 0, ((strlen($this->file_src_name) - strlen($this->file_src_name_ext)))-1); |
2680
|
|
|
} else { |
2681
|
|
|
$this->file_src_name_ext = ''; |
2682
|
|
|
$this->file_src_name_body = $this->file_src_name; |
2683
|
|
|
} |
2684
|
|
|
$this->file_src_size = (file_exists($file) ? filesize($file) : 0); |
|
|
|
|
2685
|
|
|
} |
2686
|
|
|
$this->file_src_error = 0; |
|
|
|
|
2687
|
|
|
} |
2688
|
|
|
} else { |
2689
|
|
|
// this is an element from $_FILE, i.e. an uploaded file |
2690
|
|
|
$this->log .= '<b>source is an uploaded file</b><br />'; |
2691
|
|
|
if ($this->uploaded) { |
2692
|
|
|
$this->file_src_error = trim($file['error']); |
2693
|
|
|
switch($this->file_src_error) { |
2694
|
|
|
case UPLOAD_ERR_OK: |
2695
|
|
|
// all is OK |
2696
|
|
|
$this->log .= '- upload OK<br />'; |
2697
|
|
|
break; |
2698
|
|
|
case UPLOAD_ERR_INI_SIZE: |
2699
|
|
|
$this->uploaded = false; |
2700
|
|
|
$this->error = $this->translate('uploaded_too_big_ini'); |
2701
|
|
|
break; |
2702
|
|
|
case UPLOAD_ERR_FORM_SIZE: |
2703
|
|
|
$this->uploaded = false; |
2704
|
|
|
$this->error = $this->translate('uploaded_too_big_html'); |
2705
|
|
|
break; |
2706
|
|
|
case UPLOAD_ERR_PARTIAL: |
2707
|
|
|
$this->uploaded = false; |
2708
|
|
|
$this->error = $this->translate('uploaded_partial'); |
2709
|
|
|
break; |
2710
|
|
|
case UPLOAD_ERR_NO_FILE: |
2711
|
|
|
$this->uploaded = false; |
2712
|
|
|
$this->error = $this->translate('uploaded_missing'); |
2713
|
|
|
break; |
2714
|
|
|
case @UPLOAD_ERR_NO_TMP_DIR: |
2715
|
|
|
$this->uploaded = false; |
2716
|
|
|
$this->error = $this->translate('uploaded_no_tmp_dir'); |
2717
|
|
|
break; |
2718
|
|
|
case @UPLOAD_ERR_CANT_WRITE: |
2719
|
|
|
$this->uploaded = false; |
2720
|
|
|
$this->error = $this->translate('uploaded_cant_write'); |
2721
|
|
|
break; |
2722
|
|
|
case @UPLOAD_ERR_EXTENSION: |
2723
|
|
|
$this->uploaded = false; |
2724
|
|
|
$this->error = $this->translate('uploaded_err_extension'); |
2725
|
|
|
break; |
2726
|
|
|
default: |
2727
|
|
|
$this->uploaded = false; |
2728
|
|
|
$this->error = $this->translate('uploaded_unknown') . ' ('.$this->file_src_error.')'; |
2729
|
|
|
} |
2730
|
|
|
} |
2731
|
|
|
|
2732
|
|
|
if ($this->uploaded) { |
2733
|
|
|
$this->file_src_pathname = $file['tmp_name']; |
2734
|
|
|
$this->file_src_name = $file['name']; |
2735
|
|
|
if ($this->file_src_name == '') { |
2736
|
|
|
$this->uploaded = false; |
2737
|
|
|
$this->error = $this->translate('try_again'); |
2738
|
|
|
} |
2739
|
|
|
} |
2740
|
|
|
|
2741
|
|
|
if ($this->uploaded) { |
2742
|
|
|
$this->log .= '- file name OK<br />'; |
2743
|
|
|
preg_match('/\.([^\.]*$)/', $this->file_src_name, $extension); |
2744
|
|
|
if (is_array($extension) && sizeof($extension) > 0) { |
2745
|
|
|
$this->file_src_name_ext = strtolower($extension[1]); |
2746
|
|
|
$this->file_src_name_body = substr($this->file_src_name, 0, ((strlen($this->file_src_name) - strlen($this->file_src_name_ext)))-1); |
2747
|
|
|
} else { |
2748
|
|
|
$this->file_src_name_ext = ''; |
2749
|
|
|
$this->file_src_name_body = $this->file_src_name; |
2750
|
|
|
} |
2751
|
|
|
$this->file_src_size = $file['size']; |
2752
|
|
|
$mime_from_browser = $file['type']; |
2753
|
|
|
} |
2754
|
|
|
} |
2755
|
|
|
|
2756
|
|
|
if ($this->uploaded) { |
2757
|
|
|
$this->log .= '<b>determining MIME type</b><br />'; |
2758
|
|
|
$this->file_src_mime = null; |
2759
|
|
|
|
2760
|
|
|
// checks MIME type with Fileinfo PECL extension |
2761
|
|
|
if (!$this->file_src_mime || !is_string($this->file_src_mime) || empty($this->file_src_mime) || strpos($this->file_src_mime, '/') === FALSE) { |
2762
|
|
|
if ($this->mime_fileinfo) { |
2763
|
|
|
$this->log .= '- Checking MIME type with Fileinfo PECL extension<br />'; |
2764
|
|
|
if (function_exists('finfo_open')) { |
2765
|
|
|
if ($this->mime_fileinfo !== '') { |
2766
|
|
|
if ($this->mime_fileinfo === true) { |
2767
|
|
|
if (getenv('MAGIC') === FALSE) { |
2768
|
|
|
if (substr(PHP_OS, 0, 3) == 'WIN') { |
2769
|
|
|
$path = realpath(ini_get('extension_dir') . '/../') . 'extras/magic'; |
2770
|
|
|
} else { |
2771
|
|
|
$path = '/usr/share/file/magic'; |
2772
|
|
|
} |
2773
|
|
|
$this->log .= ' MAGIC path defaults to ' . $path . '<br />'; |
2774
|
|
|
} else { |
2775
|
|
|
$path = getenv('MAGIC'); |
2776
|
|
|
$this->log .= ' MAGIC path is set to ' . $path . ' from MAGIC variable<br />'; |
2777
|
|
|
} |
2778
|
|
|
} else { |
2779
|
|
|
$path = $this->mime_fileinfo; |
2780
|
|
|
$this->log .= ' MAGIC path is set to ' . $path . '<br />'; |
2781
|
|
|
} |
2782
|
|
|
$f = @finfo_open(FILEINFO_MIME, $path); |
2783
|
|
|
} else { |
2784
|
|
|
$this->log .= ' MAGIC path will not be used<br />'; |
2785
|
|
|
$f = @finfo_open(FILEINFO_MIME); |
2786
|
|
|
} |
2787
|
|
|
if (is_resource($f)) { |
2788
|
|
|
$mime = finfo_file($f, realpath($this->file_src_pathname)); |
2789
|
|
|
finfo_close($f); |
2790
|
|
|
$this->file_src_mime = $mime; |
2791
|
|
|
$this->log .= ' MIME type detected as ' . $this->file_src_mime . ' by Fileinfo PECL extension<br />'; |
2792
|
|
|
if (preg_match("/^([\.-\w]+)\/([\.-\w]+)(.*)$/i", $this->file_src_mime)) { |
2793
|
|
|
$this->file_src_mime = preg_replace("/^([\.-\w]+)\/([\.-\w]+)(.*)$/i", '$1/$2', $this->file_src_mime); |
|
|
|
|
2794
|
|
|
$this->log .= '- MIME validated as ' . $this->file_src_mime . '<br />'; |
2795
|
|
|
} else { |
2796
|
|
|
$this->file_src_mime = null; |
2797
|
|
|
} |
2798
|
|
|
} else { |
2799
|
|
|
$this->log .= ' Fileinfo PECL extension failed (finfo_open)<br />'; |
2800
|
|
|
} |
2801
|
|
|
} elseif (@class_exists('finfo')) { |
2802
|
|
|
$f = new finfo( FILEINFO_MIME ); |
2803
|
|
|
if ($f) { |
2804
|
|
|
$this->file_src_mime = $f->file(realpath($this->file_src_pathname)); |
2805
|
|
|
$this->log .= '- MIME type detected as ' . $this->file_src_mime . ' by Fileinfo PECL extension<br />'; |
2806
|
|
|
if (preg_match("/^([\.-\w]+)\/([\.-\w]+)(.*)$/i", $this->file_src_mime)) { |
2807
|
|
|
$this->file_src_mime = preg_replace("/^([\.-\w]+)\/([\.-\w]+)(.*)$/i", '$1/$2', $this->file_src_mime); |
2808
|
|
|
$this->log .= '- MIME validated as ' . $this->file_src_mime . '<br />'; |
2809
|
|
|
} else { |
2810
|
|
|
$this->file_src_mime = null; |
2811
|
|
|
} |
2812
|
|
|
} else { |
2813
|
|
|
$this->log .= ' Fileinfo PECL extension failed (finfo)<br />'; |
2814
|
|
|
} |
2815
|
|
|
} else { |
2816
|
|
|
$this->log .= ' Fileinfo PECL extension not available<br />'; |
2817
|
|
|
} |
2818
|
|
|
} else { |
2819
|
|
|
$this->log .= '- Fileinfo PECL extension deactivated<br />'; |
2820
|
|
|
} |
2821
|
|
|
} |
2822
|
|
|
|
2823
|
|
|
// checks MIME type with shell if unix access is authorized |
2824
|
|
|
if (!$this->file_src_mime || !is_string($this->file_src_mime) || empty($this->file_src_mime) || strpos($this->file_src_mime, '/') === FALSE) { |
2825
|
|
|
if ($this->mime_file) { |
2826
|
|
|
$this->log .= '- Checking MIME type with UNIX file() command<br />'; |
2827
|
|
|
if (substr(PHP_OS, 0, 3) != 'WIN') { |
2828
|
|
|
if (function_exists('exec')) { |
2829
|
|
|
if (strlen($mime = @exec("file -bi ".escapeshellarg($this->file_src_pathname))) != 0) { |
2830
|
|
|
$this->file_src_mime = trim($mime); |
2831
|
|
|
$this->log .= ' MIME type detected as ' . $this->file_src_mime . ' by UNIX file() command<br />'; |
2832
|
|
|
if (preg_match("/^([\.-\w]+)\/([\.-\w]+)(.*)$/i", $this->file_src_mime)) { |
2833
|
|
|
$this->file_src_mime = preg_replace("/^([\.-\w]+)\/([\.-\w]+)(.*)$/i", '$1/$2', $this->file_src_mime); |
2834
|
|
|
$this->log .= '- MIME validated as ' . $this->file_src_mime . '<br />'; |
2835
|
|
|
} else { |
2836
|
|
|
$this->file_src_mime = null; |
2837
|
|
|
} |
2838
|
|
|
} else { |
2839
|
|
|
$this->log .= ' UNIX file() command failed<br />'; |
2840
|
|
|
} |
2841
|
|
|
} else { |
2842
|
|
|
$this->log .= ' PHP exec() function is disabled<br />'; |
2843
|
|
|
} |
2844
|
|
|
} else { |
2845
|
|
|
$this->log .= ' UNIX file() command not availabled<br />'; |
2846
|
|
|
} |
2847
|
|
|
} else { |
2848
|
|
|
$this->log .= '- UNIX file() command is deactivated<br />'; |
2849
|
|
|
} |
2850
|
|
|
} |
2851
|
|
|
|
2852
|
|
|
// checks MIME type with mime_magic |
2853
|
|
|
if (!$this->file_src_mime || !is_string($this->file_src_mime) || empty($this->file_src_mime) || strpos($this->file_src_mime, '/') === FALSE) { |
2854
|
|
|
if ($this->mime_magic) { |
2855
|
|
|
$this->log .= '- Checking MIME type with mime.magic file (mime_content_type())<br />'; |
2856
|
|
|
if (function_exists('mime_content_type')) { |
2857
|
|
|
$this->file_src_mime = mime_content_type($this->file_src_pathname); |
2858
|
|
|
$this->log .= ' MIME type detected as ' . $this->file_src_mime . ' by mime_content_type()<br />'; |
2859
|
|
|
if (preg_match("/^([\.-\w]+)\/([\.-\w]+)(.*)$/i", $this->file_src_mime)) { |
2860
|
|
|
$this->file_src_mime = preg_replace("/^([\.-\w]+)\/([\.-\w]+)(.*)$/i", '$1/$2', $this->file_src_mime); |
2861
|
|
|
$this->log .= '- MIME validated as ' . $this->file_src_mime . '<br />'; |
2862
|
|
|
} else { |
2863
|
|
|
$this->file_src_mime = null; |
2864
|
|
|
} |
2865
|
|
|
} else { |
2866
|
|
|
$this->log .= ' mime_content_type() is not available<br />'; |
2867
|
|
|
} |
2868
|
|
|
} else { |
2869
|
|
|
$this->log .= '- mime.magic file (mime_content_type()) is deactivated<br />'; |
2870
|
|
|
} |
2871
|
|
|
} |
2872
|
|
|
|
2873
|
|
|
// checks MIME type with getimagesize() |
2874
|
|
|
if (!$this->file_src_mime || !is_string($this->file_src_mime) || empty($this->file_src_mime) || strpos($this->file_src_mime, '/') === FALSE) { |
2875
|
|
|
if ($this->mime_getimagesize) { |
2876
|
|
|
$this->log .= '- Checking MIME type with getimagesize()<br />'; |
2877
|
|
|
$info = getimagesize($this->file_src_pathname); |
2878
|
|
|
if (is_array($info) && array_key_exists('mime', $info)) { |
2879
|
|
|
$this->file_src_mime = trim($info['mime']); |
2880
|
|
|
if (empty($this->file_src_mime)) { |
2881
|
|
|
$this->log .= ' MIME empty, guessing from type<br />'; |
2882
|
|
|
$mime = (is_array($info) && array_key_exists(2, $info) ? $info[2] : null); // 1 = GIF, 2 = JPG, 3 = PNG |
2883
|
|
|
$this->file_src_mime = ($mime==IMAGETYPE_GIF ? 'image/gif' : ($mime==IMAGETYPE_JPEG ? 'image/jpeg' : ($mime==IMAGETYPE_PNG ? 'image/png' : ($mime==IMAGETYPE_BMP ? 'image/bmp' : null)))); |
2884
|
|
|
} |
2885
|
|
|
$this->log .= ' MIME type detected as ' . $this->file_src_mime . ' by PHP getimagesize() function<br />'; |
2886
|
|
|
if (preg_match("/^([\.-\w]+)\/([\.-\w]+)(.*)$/i", $this->file_src_mime)) { |
2887
|
|
|
$this->file_src_mime = preg_replace("/^([\.-\w]+)\/([\.-\w]+)(.*)$/i", '$1/$2', $this->file_src_mime); |
2888
|
|
|
$this->log .= '- MIME validated as ' . $this->file_src_mime . '<br />'; |
2889
|
|
|
} else { |
2890
|
|
|
$this->file_src_mime = null; |
2891
|
|
|
} |
2892
|
|
|
} else { |
2893
|
|
|
$this->log .= ' getimagesize() failed<br />'; |
2894
|
|
|
} |
2895
|
|
|
} else { |
2896
|
|
|
$this->log .= '- getimagesize() is deactivated<br />'; |
2897
|
|
|
} |
2898
|
|
|
} |
2899
|
|
|
|
2900
|
|
|
// default to MIME from browser (or Flash) |
2901
|
|
|
if (!empty($mime_from_browser) && !$this->file_src_mime || !is_string($this->file_src_mime) || empty($this->file_src_mime)) { |
2902
|
|
|
$this->file_src_mime =$mime_from_browser; |
2903
|
|
|
$this->log .= '- MIME type detected as ' . $this->file_src_mime . ' by browser<br />'; |
2904
|
|
|
if (preg_match("/^([\.-\w]+)\/([\.-\w]+)(.*)$/i", $this->file_src_mime)) { |
2905
|
|
|
$this->file_src_mime = preg_replace("/^([\.-\w]+)\/([\.-\w]+)(.*)$/i", '$1/$2', $this->file_src_mime); |
2906
|
|
|
$this->log .= '- MIME validated as ' . $this->file_src_mime . '<br />'; |
2907
|
|
|
} else { |
2908
|
|
|
$this->file_src_mime = null; |
2909
|
|
|
} |
2910
|
|
|
} |
2911
|
|
|
|
2912
|
|
|
// we need to work some magic if we upload via Flash |
2913
|
|
|
if ($this->file_src_mime == 'application/octet-stream' || !$this->file_src_mime || !is_string($this->file_src_mime) || empty($this->file_src_mime) || strpos($this->file_src_mime, '/') === FALSE) { |
2914
|
|
|
if ($this->file_src_mime == 'application/octet-stream') $this->log .= '- Flash may be rewriting MIME as application/octet-stream<br />'; |
2915
|
|
|
$this->log .= '- Try to guess MIME type from file extension (' . $this->file_src_name_ext . '): '; |
2916
|
|
|
if (array_key_exists($this->file_src_name_ext, $this->mime_types)) $this->file_src_mime = $this->mime_types[$this->file_src_name_ext]; |
2917
|
|
|
if ($this->file_src_mime == 'application/octet-stream') { |
2918
|
|
|
$this->log .= 'doesn\'t look like anything known<br />'; |
2919
|
|
|
} else { |
2920
|
|
|
$this->log .= 'MIME type set to ' . $this->file_src_mime . '<br />'; |
2921
|
|
|
} |
2922
|
|
|
} |
2923
|
|
|
|
2924
|
|
|
if (!$this->file_src_mime || !is_string($this->file_src_mime) || empty($this->file_src_mime) || strpos($this->file_src_mime, '/') === FALSE) { |
2925
|
|
|
$this->log .= '- MIME type couldn\'t be detected! (' . (string) $this->file_src_mime . ')<br />'; |
2926
|
|
|
} |
2927
|
|
|
|
2928
|
|
|
// determine whether the file is an image |
2929
|
|
|
if ($this->file_src_mime && is_string($this->file_src_mime) && !empty($this->file_src_mime) && array_key_exists($this->file_src_mime, $this->image_supported)) { |
2930
|
|
|
$this->file_is_image = true; |
2931
|
|
|
$this->image_src_type = $this->image_supported[$this->file_src_mime]; |
2932
|
|
|
} |
2933
|
|
|
|
2934
|
|
|
// if the file is an image, we gather some useful data |
2935
|
|
|
if ($this->file_is_image) { |
2936
|
|
|
if ($h = fopen($this->file_src_pathname, 'r')) { |
2937
|
|
|
fclose($h); |
2938
|
|
|
$info = getimagesize($this->file_src_pathname); |
2939
|
|
|
if (is_array($info)) { |
2940
|
|
|
$this->image_src_x = $info[0]; |
2941
|
|
|
$this->image_src_y = $info[1]; |
2942
|
|
|
$this->image_dst_x = $this->image_src_x; |
2943
|
|
|
$this->image_dst_y = $this->image_src_y; |
2944
|
|
|
$this->image_src_pixels = $this->image_src_x * $this->image_src_y; |
2945
|
|
|
$this->image_src_bits = array_key_exists('bits', $info) ? $info['bits'] : null; |
2946
|
|
|
} else { |
2947
|
|
|
$this->file_is_image = false; |
2948
|
|
|
$this->uploaded = false; |
2949
|
|
|
$this->log .= '- can\'t retrieve image information, image may have been tampered with<br />'; |
2950
|
|
|
$this->error = $this->translate('source_invalid'); |
2951
|
|
|
} |
2952
|
|
|
} else { |
2953
|
|
|
$this->log .= '- can\'t read source file directly. open_basedir restriction in place?<br />'; |
2954
|
|
|
} |
2955
|
|
|
} |
2956
|
|
|
|
2957
|
|
|
$this->log .= '<b>source variables</b><br />'; |
2958
|
|
|
$this->log .= '- You can use all these before calling process()<br />'; |
2959
|
|
|
$this->log .= ' file_src_name : ' . $this->file_src_name . '<br />'; |
2960
|
|
|
$this->log .= ' file_src_name_body : ' . $this->file_src_name_body . '<br />'; |
2961
|
|
|
$this->log .= ' file_src_name_ext : ' . $this->file_src_name_ext . '<br />'; |
2962
|
|
|
$this->log .= ' file_src_pathname : ' . $this->file_src_pathname . '<br />'; |
2963
|
|
|
$this->log .= ' file_src_mime : ' . $this->file_src_mime . '<br />'; |
2964
|
|
|
$this->log .= ' file_src_size : ' . $this->file_src_size . ' (max= ' . $this->file_max_size . ')<br />'; |
2965
|
|
|
$this->log .= ' file_src_error : ' . $this->file_src_error . '<br />'; |
2966
|
|
|
|
2967
|
|
|
if ($this->file_is_image) { |
2968
|
|
|
$this->log .= '- source file is an image<br />'; |
2969
|
|
|
$this->log .= ' image_src_x : ' . $this->image_src_x . '<br />'; |
2970
|
|
|
$this->log .= ' image_src_y : ' . $this->image_src_y . '<br />'; |
2971
|
|
|
$this->log .= ' image_src_pixels : ' . $this->image_src_pixels . '<br />'; |
2972
|
|
|
$this->log .= ' image_src_type : ' . $this->image_src_type . '<br />'; |
2973
|
|
|
$this->log .= ' image_src_bits : ' . $this->image_src_bits . '<br />'; |
2974
|
|
|
} |
2975
|
|
|
} |
2976
|
|
|
|
2977
|
|
|
} |
2978
|
|
|
|
2979
|
|
|
/** |
2980
|
|
|
* Returns the version of GD |
2981
|
|
|
* |
2982
|
|
|
* @access public |
2983
|
|
|
* @param boolean $full Optional flag to get precise version |
2984
|
|
|
* @return float GD version |
2985
|
|
|
*/ |
2986
|
|
|
function gdversion($full = false) { |
2987
|
|
|
static $gd_version = null; |
2988
|
|
|
static $gd_full_version = null; |
2989
|
|
|
if ($gd_version === null) { |
2990
|
|
|
if (function_exists('gd_info')) { |
2991
|
|
|
$gd = gd_info(); |
2992
|
|
|
$gd = $gd["GD Version"]; |
2993
|
|
|
$regex = "/([\d\.]+)/i"; |
2994
|
|
|
} else { |
2995
|
|
|
ob_start(); |
2996
|
|
|
phpinfo(8); |
2997
|
|
|
$gd = ob_get_contents(); |
2998
|
|
|
ob_end_clean(); |
2999
|
|
|
$regex = "/\bgd\s+version\b[^\d\n\r]+?([\d\.]+)/i"; |
3000
|
|
|
} |
3001
|
|
|
if (preg_match($regex, $gd, $m)) { |
3002
|
|
|
$gd_full_version = (string) $m[1]; |
3003
|
|
|
$gd_version = (float) $m[1]; |
3004
|
|
|
} else { |
3005
|
|
|
$gd_full_version = 'none'; |
3006
|
|
|
$gd_version = 0; |
3007
|
|
|
} |
3008
|
|
|
} |
3009
|
|
|
if ($full) { |
3010
|
|
|
return $gd_full_version; |
3011
|
|
|
} else { |
3012
|
|
|
return $gd_version; |
3013
|
|
|
} |
3014
|
|
|
} |
3015
|
|
|
|
3016
|
|
|
/** |
3017
|
|
|
* Creates directories recursively |
3018
|
|
|
* |
3019
|
|
|
* @access private |
3020
|
|
|
* @param string $path Path to create |
3021
|
|
|
* @param integer $mode Optional permissions |
3022
|
|
|
* @return boolean Success |
3023
|
|
|
*/ |
3024
|
|
|
function rmkdir($path, $mode = 0777) { |
3025
|
|
|
return is_dir($path) || ( $this->rmkdir(dirname($path), $mode) && $this->_mkdir($path, $mode) ); |
3026
|
|
|
} |
3027
|
|
|
|
3028
|
|
|
/** |
3029
|
|
|
* Creates directory |
3030
|
|
|
* |
3031
|
|
|
* @access private |
3032
|
|
|
* @param string $path Path to create |
3033
|
|
|
* @param integer $mode Optional permissions |
3034
|
|
|
* @return boolean Success |
3035
|
|
|
*/ |
3036
|
|
|
function _mkdir($path, $mode = 0777) { |
3037
|
|
|
$old = umask(0); |
3038
|
|
|
$res = @mkdir($path, $mode); |
3039
|
|
|
umask($old); |
3040
|
|
|
return $res; |
3041
|
|
|
} |
3042
|
|
|
|
3043
|
|
|
/** |
3044
|
|
|
* Translate error messages |
3045
|
|
|
* |
3046
|
|
|
* @access private |
3047
|
|
|
* @param string $str Message to translate |
3048
|
|
|
* @param array $tokens Optional token values |
3049
|
|
|
* @return string Translated string |
3050
|
|
|
*/ |
3051
|
|
|
function translate($str, $tokens = array()) { |
3052
|
|
|
if (array_key_exists($str, $this->translation)) $str = $this->translation[$str]; |
3053
|
|
|
if (is_array($tokens) && sizeof($tokens) > 0) $str = vsprintf($str, $tokens); |
3054
|
|
|
return $str; |
3055
|
|
|
} |
3056
|
|
|
|
3057
|
|
|
/** |
3058
|
|
|
* Decodes colors |
3059
|
|
|
* |
3060
|
|
|
* @access private |
3061
|
|
|
* @param string $color Color string |
3062
|
|
|
* @return array RGB colors |
3063
|
|
|
*/ |
3064
|
|
|
function getcolors($color) { |
3065
|
|
|
$r = sscanf($color, "#%2x%2x%2x"); |
3066
|
|
|
$red = (array_key_exists(0, $r) && is_numeric($r[0]) ? $r[0] : 0); |
3067
|
|
|
$green = (array_key_exists(1, $r) && is_numeric($r[1]) ? $r[1] : 0); |
3068
|
|
|
$blue = (array_key_exists(2, $r) && is_numeric($r[2]) ? $r[2] : 0); |
3069
|
|
|
return array($red, $green, $blue); |
3070
|
|
|
} |
3071
|
|
|
|
3072
|
|
|
/** |
3073
|
|
|
* Decodes sizes |
3074
|
|
|
* |
3075
|
|
|
* @access private |
3076
|
|
|
* @param string $size Size in bytes, or shorthand byte options |
3077
|
|
|
* @return integer Size in bytes |
3078
|
|
|
*/ |
3079
|
|
|
function getsize($size) { |
3080
|
|
|
$last = strtolower($size{strlen($size)-1}); |
3081
|
|
|
switch($last) { |
3082
|
|
|
case 'g': |
3083
|
|
|
$size *= 1024; |
3084
|
|
|
case 'm': |
3085
|
|
|
$size *= 1024; |
3086
|
|
|
case 'k': |
3087
|
|
|
$size *= 1024; |
3088
|
|
|
} |
3089
|
|
|
return $size; |
3090
|
|
|
} |
3091
|
|
|
|
3092
|
|
|
/** |
3093
|
|
|
* Decodes offsets |
3094
|
|
|
* |
3095
|
|
|
* @access private |
3096
|
|
|
* @param misc $offsets Offsets, as an integer, a string or an array |
3097
|
|
|
* @param integer $x Reference picture width |
3098
|
|
|
* @param integer $y Reference picture height |
3099
|
|
|
* @param boolean $round Round offsets before returning them |
3100
|
|
|
* @param boolean $negative Allow negative offsets to be returned |
3101
|
|
|
* @return array Array of four offsets (TRBL) |
3102
|
|
|
*/ |
3103
|
|
|
function getoffsets($offsets, $x, $y, $round = true, $negative = true) { |
3104
|
|
|
if (!is_array($offsets)) $offsets = explode(' ', $offsets); |
3105
|
|
|
if (sizeof($offsets) == 4) { |
3106
|
|
|
$ct = $offsets[0]; $cr = $offsets[1]; $cb = $offsets[2]; $cl = $offsets[3]; |
3107
|
|
|
} else if (sizeof($offsets) == 2) { |
3108
|
|
|
$ct = $offsets[0]; $cr = $offsets[1]; $cb = $offsets[0]; $cl = $offsets[1]; |
3109
|
|
|
} else { |
3110
|
|
|
$ct = $offsets[0]; $cr = $offsets[0]; $cb = $offsets[0]; $cl = $offsets[0]; |
3111
|
|
|
} |
3112
|
|
|
if (strpos($ct, '%')>0) $ct = $y * (str_replace('%','',$ct) / 100); |
3113
|
|
|
if (strpos($cr, '%')>0) $cr = $x * (str_replace('%','',$cr) / 100); |
3114
|
|
|
if (strpos($cb, '%')>0) $cb = $y * (str_replace('%','',$cb) / 100); |
3115
|
|
|
if (strpos($cl, '%')>0) $cl = $x * (str_replace('%','',$cl) / 100); |
3116
|
|
|
if (strpos($ct, 'px')>0) $ct = str_replace('px','',$ct); |
3117
|
|
|
if (strpos($cr, 'px')>0) $cr = str_replace('px','',$cr); |
3118
|
|
|
if (strpos($cb, 'px')>0) $cb = str_replace('px','',$cb); |
3119
|
|
|
if (strpos($cl, 'px')>0) $cl = str_replace('px','',$cl); |
3120
|
|
|
$ct = (int) $ct; $cr = (int) $cr; $cb = (int) $cb; $cl = (int) $cl; |
3121
|
|
|
if ($round) { |
3122
|
|
|
$ct = round($ct); |
3123
|
|
|
$cr = round($cr); |
3124
|
|
|
$cb = round($cb); |
3125
|
|
|
$cl = round($cl); |
3126
|
|
|
} |
3127
|
|
|
if (!$negative) { |
3128
|
|
|
if ($ct < 0) $ct = 0; |
3129
|
|
|
if ($cr < 0) $cr = 0; |
3130
|
|
|
if ($cb < 0) $cb = 0; |
3131
|
|
|
if ($cl < 0) $cl = 0; |
3132
|
|
|
} |
3133
|
|
|
return array($ct, $cr, $cb, $cl); |
3134
|
|
|
} |
3135
|
|
|
|
3136
|
|
|
/** |
3137
|
|
|
* Creates a container image |
3138
|
|
|
* |
3139
|
|
|
* @access private |
3140
|
|
|
* @param integer $x Width |
3141
|
|
|
* @param integer $y Height |
3142
|
|
|
* @param boolean $fill Optional flag to draw the background color or not |
3143
|
|
|
* @param boolean $trsp Optional flag to set the background to be transparent |
3144
|
|
|
* @return resource Container image |
3145
|
|
|
*/ |
3146
|
|
|
function imagecreatenew($x, $y, $fill = true, $trsp = false) { |
3147
|
|
|
if ($x < 1) $x = 1; if ($y < 1) $y = 1; |
3148
|
|
|
if ($this->gdversion() >= 2 && !$this->image_is_palette) { |
3149
|
|
|
// create a true color image |
3150
|
|
|
$dst_im = imagecreatetruecolor($x, $y); |
3151
|
|
|
// this preserves transparency in PNGs, in true color |
3152
|
|
|
if (empty($this->image_background_color) || $trsp) { |
3153
|
|
|
imagealphablending($dst_im, false ); |
3154
|
|
|
imagefilledrectangle($dst_im, 0, 0, $x, $y, imagecolorallocatealpha($dst_im, 0, 0, 0, 127)); |
3155
|
|
|
} |
3156
|
|
|
} else { |
3157
|
|
|
// creates a palette image |
3158
|
|
|
$dst_im = imagecreate($x, $y); |
3159
|
|
|
// preserves transparency for palette images, if the original image has transparency |
3160
|
|
|
if (($fill && $this->image_is_transparent && empty($this->image_background_color)) || $trsp) { |
3161
|
|
|
imagefilledrectangle($dst_im, 0, 0, $x, $y, $this->image_transparent_color); |
3162
|
|
|
imagecolortransparent($dst_im, $this->image_transparent_color); |
3163
|
|
|
} |
3164
|
|
|
} |
3165
|
|
|
// fills with background color if any is set |
3166
|
|
|
if ($fill && !empty($this->image_background_color) && !$trsp) { |
3167
|
|
|
list($red, $green, $blue) = $this->getcolors($this->image_background_color); |
3168
|
|
|
$background_color = imagecolorallocate($dst_im, $red, $green, $blue); |
3169
|
|
|
imagefilledrectangle($dst_im, 0, 0, $x, $y, $background_color); |
3170
|
|
|
} |
3171
|
|
|
return $dst_im; |
3172
|
|
|
} |
3173
|
|
|
|
3174
|
|
|
|
3175
|
|
|
/** |
3176
|
|
|
* Transfers an image from the container to the destination image |
3177
|
|
|
* |
3178
|
|
|
* @access private |
3179
|
|
|
* @param resource $src_im Container image |
3180
|
|
|
* @param resource $dst_im Destination image |
3181
|
|
|
* @return resource Destination image |
3182
|
|
|
*/ |
3183
|
|
|
function imagetransfer($src_im, $dst_im) { |
3184
|
|
|
if (is_resource($dst_im)) imagedestroy($dst_im); |
3185
|
|
|
$dst_im = & $src_im; |
3186
|
|
|
return $dst_im; |
3187
|
|
|
} |
3188
|
|
|
|
3189
|
|
|
/** |
3190
|
|
|
* Merges two images |
3191
|
|
|
* |
3192
|
|
|
* If the output format is PNG, then we do it pixel per pixel to retain the alpha channel |
3193
|
|
|
* |
3194
|
|
|
* @access private |
3195
|
|
|
* @param resource $dst_img Destination image |
|
|
|
|
3196
|
|
|
* @param resource $src_img Overlay image |
|
|
|
|
3197
|
|
|
* @param int $dst_x x-coordinate of destination point |
3198
|
|
|
* @param int $dst_y y-coordinate of destination point |
3199
|
|
|
* @param int $src_x x-coordinate of source point |
3200
|
|
|
* @param int $src_y y-coordinate of source point |
3201
|
|
|
* @param int $src_w Source width |
3202
|
|
|
* @param int $src_h Source height |
3203
|
|
|
* @param int $pct Optional percentage of the overlay, between 0 and 100 (default: 100) |
3204
|
|
|
* @return resource Destination image |
3205
|
|
|
*/ |
3206
|
|
|
function imagecopymergealpha(&$dst_im, &$src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct = 0) { |
3207
|
|
|
$dst_x = (int) $dst_x; |
3208
|
|
|
$dst_y = (int) $dst_y; |
3209
|
|
|
$src_x = (int) $src_x; |
3210
|
|
|
$src_y = (int) $src_y; |
3211
|
|
|
$src_w = (int) $src_w; |
3212
|
|
|
$src_h = (int) $src_h; |
3213
|
|
|
$pct = (int) $pct; |
3214
|
|
|
$dst_w = imagesx($dst_im); |
3215
|
|
|
$dst_h = imagesy($dst_im); |
3216
|
|
|
|
3217
|
|
|
for ($y = $src_y; $y < $src_h; $y++) { |
3218
|
|
|
for ($x = $src_x; $x < $src_w; $x++) { |
3219
|
|
|
|
3220
|
|
|
if ($x + $dst_x >= 0 && $x + $dst_x < $dst_w && $x + $src_x >= 0 && $x + $src_x < $src_w |
3221
|
|
|
&& $y + $dst_y >= 0 && $y + $dst_y < $dst_h && $y + $src_y >= 0 && $y + $src_y < $src_h) { |
3222
|
|
|
|
3223
|
|
|
$dst_pixel = imagecolorsforindex($dst_im, imagecolorat($dst_im, $x + $dst_x, $y + $dst_y)); |
3224
|
|
|
$src_pixel = imagecolorsforindex($src_im, imagecolorat($src_im, $x + $src_x, $y + $src_y)); |
3225
|
|
|
|
3226
|
|
|
$src_alpha = 1 - ($src_pixel['alpha'] / 127); |
3227
|
|
|
$dst_alpha = 1 - ($dst_pixel['alpha'] / 127); |
3228
|
|
|
$opacity = $src_alpha * $pct / 100; |
3229
|
|
|
if ($dst_alpha >= $opacity) $alpha = $dst_alpha; |
3230
|
|
|
if ($dst_alpha < $opacity) $alpha = $opacity; |
3231
|
|
|
if ($alpha > 1) $alpha = 1; |
3232
|
|
|
|
3233
|
|
|
if ($opacity > 0) { |
3234
|
|
|
$dst_red = round(( ($dst_pixel['red'] * $dst_alpha * (1 - $opacity)) ) ); |
3235
|
|
|
$dst_green = round(( ($dst_pixel['green'] * $dst_alpha * (1 - $opacity)) ) ); |
3236
|
|
|
$dst_blue = round(( ($dst_pixel['blue'] * $dst_alpha * (1 - $opacity)) ) ); |
3237
|
|
|
$src_red = round((($src_pixel['red'] * $opacity)) ); |
3238
|
|
|
$src_green = round((($src_pixel['green'] * $opacity)) ); |
3239
|
|
|
$src_blue = round((($src_pixel['blue'] * $opacity)) ); |
3240
|
|
|
$red = round(($dst_red + $src_red ) / ($dst_alpha * (1 - $opacity) + $opacity)); |
3241
|
|
|
$green = round(($dst_green + $src_green) / ($dst_alpha * (1 - $opacity) + $opacity)); |
3242
|
|
|
$blue = round(($dst_blue + $src_blue ) / ($dst_alpha * (1 - $opacity) + $opacity)); |
3243
|
|
|
if ($red > 255) $red = 255; |
3244
|
|
|
if ($green > 255) $green = 255; |
3245
|
|
|
if ($blue > 255) $blue = 255; |
3246
|
|
|
$alpha = round((1 - $alpha) * 127); |
3247
|
|
|
$color = imagecolorallocatealpha($dst_im, $red, $green, $blue, $alpha); |
3248
|
|
|
imagesetpixel($dst_im, $x + $dst_x, $y + $dst_y, $color); |
3249
|
|
|
} |
3250
|
|
|
} |
3251
|
|
|
} |
3252
|
|
|
} |
3253
|
|
|
return true; |
3254
|
|
|
} |
3255
|
|
|
|
3256
|
|
|
|
3257
|
|
|
|
3258
|
|
|
/** |
3259
|
|
|
* Actually uploads the file, and act on it according to the set processing class variables |
3260
|
|
|
* |
3261
|
|
|
* This function copies the uploaded file to the given location, eventually performing actions on it. |
3262
|
|
|
* Typically, you can call {@link process} several times for the same file, |
3263
|
|
|
* for instance to create a resized image and a thumbnail of the same file. |
3264
|
|
|
* The original uploaded file remains intact in its temporary location, so you can use {@link process} several times. |
3265
|
|
|
* You will be able to delete the uploaded file with {@link clean} when you have finished all your {@link process} calls. |
3266
|
|
|
* |
3267
|
|
|
* According to the processing class variables set in the calling file, the file can be renamed, |
3268
|
|
|
* and if it is an image, can be resized or converted. |
3269
|
|
|
* |
3270
|
|
|
* When the processing is completed, and the file copied to its new location, the |
3271
|
|
|
* processing class variables will be reset to their default value. |
3272
|
|
|
* This allows you to set new properties, and perform another {@link process} on the same uploaded file |
3273
|
|
|
* |
3274
|
|
|
* If the function is called with a null or empty argument, then it will return the content of the picture |
3275
|
|
|
* |
3276
|
|
|
* It will set {@link processed} (and {@link error} is an error occurred) |
3277
|
|
|
* |
3278
|
|
|
* @access public |
3279
|
|
|
* @param string $server_path Optional path location of the uploaded file, with an ending slash |
3280
|
|
|
* @return string Optional content of the image |
3281
|
|
|
*/ |
3282
|
|
|
function process($server_path = null) { |
3283
|
|
|
$this->error = ''; |
3284
|
|
|
$this->processed = true; |
3285
|
|
|
$return_mode = false; |
3286
|
|
|
$return_content = null; |
3287
|
|
|
|
3288
|
|
|
// clean up dst variables |
3289
|
|
|
$this->file_dst_path = ''; |
3290
|
|
|
$this->file_dst_pathname = ''; |
3291
|
|
|
$this->file_dst_name = ''; |
3292
|
|
|
$this->file_dst_name_body = ''; |
3293
|
|
|
$this->file_dst_name_ext = ''; |
3294
|
|
|
|
3295
|
|
|
// clean up some parameters |
3296
|
|
|
$this->file_max_size = $this->getsize($this->file_max_size); |
|
|
|
|
3297
|
|
|
$this->jpeg_size = $this->getsize($this->jpeg_size); |
|
|
|
|
3298
|
|
|
// some parameters are being deprecated, and replaced with others |
3299
|
|
|
if (is_null($this->image_overlay_opacity)) $this->image_overlay_opacity = $this->image_overlay_percent; |
3300
|
|
|
if ($this->image_text_opacity == 100) $this->image_text_opacity = $this->image_text_percent; |
3301
|
|
|
if ($this->image_text_background_opacity == 100) $this->image_text_background_opacity = $this->image_text_background_percent; |
3302
|
|
|
|
3303
|
|
|
// copy some variables as we need to keep them clean |
3304
|
|
|
$file_src_name = $this->file_src_name; |
3305
|
|
|
$file_src_name_body = $this->file_src_name_body; |
3306
|
|
|
$file_src_name_ext = $this->file_src_name_ext; |
3307
|
|
|
|
3308
|
|
|
if (!$this->uploaded) { |
3309
|
|
|
$this->error = $this->translate('file_not_uploaded'); |
3310
|
|
|
$this->processed = false; |
3311
|
|
|
} |
3312
|
|
|
|
3313
|
|
|
if ($this->processed) { |
3314
|
|
|
if (empty($server_path) || is_null($server_path)) { |
3315
|
|
|
$this->log .= '<b>process file and return the content</b><br />'; |
3316
|
|
|
$return_mode = true; |
3317
|
|
|
} else { |
3318
|
|
|
if(strtolower(substr(PHP_OS, 0, 3)) === 'win') { |
3319
|
|
|
if (substr($server_path, -1, 1) != '\\') $server_path = $server_path . '\\'; |
3320
|
|
|
} else { |
3321
|
|
|
if (substr($server_path, -1, 1) != '/') $server_path = $server_path . '/'; |
3322
|
|
|
} |
3323
|
|
|
$this->log .= '<b>process file to ' . $server_path . '</b><br />'; |
3324
|
|
|
} |
3325
|
|
|
} |
3326
|
|
|
|
3327
|
|
|
if ($this->processed) { |
3328
|
|
|
// checks file max size |
3329
|
|
|
if ($this->file_src_size > $this->file_max_size) { |
3330
|
|
|
$this->processed = false; |
3331
|
|
|
$this->error = $this->translate('file_too_big'); |
3332
|
|
|
} else { |
3333
|
|
|
$this->log .= '- file size OK<br />'; |
3334
|
|
|
} |
3335
|
|
|
} |
3336
|
|
|
|
3337
|
|
|
if ($this->processed) { |
3338
|
|
|
// if we have an image without extension, set it |
3339
|
|
|
if ($this->file_force_extension && $this->file_is_image && !$this->file_src_name_ext) $file_src_name_ext = $this->image_src_type; |
3340
|
|
|
// turn dangerous scripts into text files |
3341
|
|
|
if ($this->no_script) { |
3342
|
|
|
// if the file has no extension, we try to guess it from the MIME type |
3343
|
|
|
if ($this->file_force_extension && empty($file_src_name_ext)) { |
3344
|
|
|
if ($key = array_search($this->file_src_mime, $this->mime_types)) { |
3345
|
|
|
$file_src_name_ext = $key; |
3346
|
|
|
$file_src_name = $file_src_name_body . '.' . $file_src_name_ext; |
3347
|
|
|
$this->log .= '- file renamed as ' . $file_src_name_body . '.' . $file_src_name_ext . '!<br />'; |
3348
|
|
|
} |
3349
|
|
|
} |
3350
|
|
|
// if the file is text based, or has a dangerous extension, we rename it as .txt |
3351
|
|
|
if ((((substr($this->file_src_mime, 0, 5) == 'text/' && $this->file_src_mime != 'text/rtf') || strpos($this->file_src_mime, 'javascript') !== false) && (substr($file_src_name, -4) != '.txt')) |
3352
|
|
|
|| preg_match('/\.(php|pl|py|cgi|asp|js)$/i', $this->file_src_name) |
3353
|
|
|
|| $this->file_force_extension && empty($file_src_name_ext)) { |
3354
|
|
|
$this->file_src_mime = 'text/plain'; |
3355
|
|
|
if ($this->file_src_name_ext) $file_src_name_body = $file_src_name_body . '.' . $this->file_src_name_ext; |
3356
|
|
|
$file_src_name_ext = 'txt'; |
3357
|
|
|
$file_src_name = $file_src_name_body . '.' . $file_src_name_ext; |
3358
|
|
|
$this->log .= '- script renamed as ' . $file_src_name_body . '.' . $file_src_name_ext . '!<br />'; |
3359
|
|
|
} |
3360
|
|
|
} |
3361
|
|
|
|
3362
|
|
|
if ($this->mime_check && empty($this->file_src_mime)) { |
3363
|
|
|
$this->processed = false; |
3364
|
|
|
$this->error = $this->translate('no_mime'); |
3365
|
|
|
} else if ($this->mime_check && !empty($this->file_src_mime) && strpos($this->file_src_mime, '/') !== false) { |
3366
|
|
|
list($m1, $m2) = explode('/', $this->file_src_mime); |
3367
|
|
|
$allowed = false; |
3368
|
|
|
// check wether the mime type is allowed |
3369
|
|
|
if (!is_array($this->allowed)) $this->allowed = array($this->allowed); |
3370
|
|
|
foreach($this->allowed as $k => $v) { |
3371
|
|
|
list($v1, $v2) = explode('/', $v); |
3372
|
|
|
if (($v1 == '*' && $v2 == '*') || ($v1 == $m1 && ($v2 == $m2 || $v2 == '*'))) { |
3373
|
|
|
$allowed = true; |
3374
|
|
|
break; |
3375
|
|
|
} |
3376
|
|
|
} |
3377
|
|
|
// check wether the mime type is forbidden |
3378
|
|
|
if (!is_array($this->forbidden)) $this->forbidden = array($this->forbidden); |
3379
|
|
|
foreach($this->forbidden as $k => $v) { |
3380
|
|
|
list($v1, $v2) = explode('/', $v); |
3381
|
|
|
if (($v1 == '*' && $v2 == '*') || ($v1 == $m1 && ($v2 == $m2 || $v2 == '*'))) { |
3382
|
|
|
$allowed = false; |
3383
|
|
|
break; |
3384
|
|
|
} |
3385
|
|
|
} |
3386
|
|
|
if (!$allowed) { |
3387
|
|
|
$this->processed = false; |
3388
|
|
|
$this->error = $this->translate('incorrect_file'); |
3389
|
|
|
} else { |
3390
|
|
|
$this->log .= '- file mime OK : ' . $this->file_src_mime . '<br />'; |
3391
|
|
|
} |
3392
|
|
|
} else { |
3393
|
|
|
$this->log .= '- file mime (not checked) : ' . $this->file_src_mime . '<br />'; |
3394
|
|
|
} |
3395
|
|
|
|
3396
|
|
|
// if the file is an image, we can check on its dimensions |
3397
|
|
|
// these checks are not available if open_basedir restrictions are in place |
3398
|
|
|
if ($this->file_is_image) { |
3399
|
|
|
if (is_numeric($this->image_src_x) && is_numeric($this->image_src_y)) { |
3400
|
|
|
$ratio = $this->image_src_x / $this->image_src_y; |
3401
|
|
|
if (!is_null($this->image_max_width) && $this->image_src_x > $this->image_max_width) { |
3402
|
|
|
$this->processed = false; |
3403
|
|
|
$this->error = $this->translate('image_too_wide'); |
3404
|
|
|
} |
3405
|
|
|
if (!is_null($this->image_min_width) && $this->image_src_x < $this->image_min_width) { |
3406
|
|
|
$this->processed = false; |
3407
|
|
|
$this->error = $this->translate('image_too_narrow'); |
3408
|
|
|
} |
3409
|
|
|
if (!is_null($this->image_max_height) && $this->image_src_y > $this->image_max_height) { |
3410
|
|
|
$this->processed = false; |
3411
|
|
|
$this->error = $this->translate('image_too_high'); |
3412
|
|
|
} |
3413
|
|
|
if (!is_null($this->image_min_height) && $this->image_src_y < $this->image_min_height) { |
3414
|
|
|
$this->processed = false; |
3415
|
|
|
$this->error = $this->translate('image_too_short'); |
3416
|
|
|
} |
3417
|
|
|
if (!is_null($this->image_max_ratio) && $ratio > $this->image_max_ratio) { |
3418
|
|
|
$this->processed = false; |
3419
|
|
|
$this->error = $this->translate('ratio_too_high'); |
3420
|
|
|
} |
3421
|
|
|
if (!is_null($this->image_min_ratio) && $ratio < $this->image_min_ratio) { |
3422
|
|
|
$this->processed = false; |
3423
|
|
|
$this->error = $this->translate('ratio_too_low'); |
3424
|
|
|
} |
3425
|
|
|
if (!is_null($this->image_max_pixels) && $this->image_src_pixels > $this->image_max_pixels) { |
3426
|
|
|
$this->processed = false; |
3427
|
|
|
$this->error = $this->translate('too_many_pixels'); |
3428
|
|
|
} |
3429
|
|
|
if (!is_null($this->image_min_pixels) && $this->image_src_pixels < $this->image_min_pixels) { |
3430
|
|
|
$this->processed = false; |
3431
|
|
|
$this->error = $this->translate('not_enough_pixels'); |
3432
|
|
|
} |
3433
|
|
|
} else { |
3434
|
|
|
$this->log .= '- no image properties available, can\'t enforce dimension checks : ' . $this->file_src_mime . '<br />'; |
3435
|
|
|
} |
3436
|
|
|
} |
3437
|
|
|
} |
3438
|
|
|
|
3439
|
|
|
if ($this->processed) { |
3440
|
|
|
$this->file_dst_path = $server_path; |
3441
|
|
|
|
3442
|
|
|
// repopulate dst variables from src |
3443
|
|
|
$this->file_dst_name = $file_src_name; |
3444
|
|
|
$this->file_dst_name_body = $file_src_name_body; |
3445
|
|
|
$this->file_dst_name_ext = $file_src_name_ext; |
|
|
|
|
3446
|
|
|
if ($this->file_overwrite) $this->file_auto_rename = false; |
3447
|
|
|
|
3448
|
|
|
if ($this->image_convert && $this->file_is_image) { // if we convert as an image |
3449
|
|
|
if ($this->file_src_name_ext) $this->file_dst_name_ext = $this->image_convert; |
3450
|
|
|
$this->log .= '- new file name ext : ' . $this->image_convert . '<br />'; |
3451
|
|
|
} |
3452
|
|
|
if (!is_null($this->file_new_name_body)) { // rename file body |
3453
|
|
|
$this->file_dst_name_body = $this->file_new_name_body; |
3454
|
|
|
$this->log .= '- new file name body : ' . $this->file_new_name_body . '<br />'; |
3455
|
|
|
} |
3456
|
|
|
if (!is_null($this->file_new_name_ext)) { // rename file ext |
3457
|
|
|
$this->file_dst_name_ext = $this->file_new_name_ext; |
3458
|
|
|
$this->log .= '- new file name ext : ' . $this->file_new_name_ext . '<br />'; |
3459
|
|
|
} |
3460
|
|
|
if (!is_null($this->file_name_body_add)) { // append a string to the name |
3461
|
|
|
$this->file_dst_name_body = $this->file_dst_name_body . $this->file_name_body_add; |
3462
|
|
|
$this->log .= '- file name body append : ' . $this->file_name_body_add . '<br />'; |
3463
|
|
|
} |
3464
|
|
|
if (!is_null($this->file_name_body_pre)) { // prepend a string to the name |
3465
|
|
|
$this->file_dst_name_body = $this->file_name_body_pre . $this->file_dst_name_body; |
3466
|
|
|
$this->log .= '- file name body prepend : ' . $this->file_name_body_pre . '<br />'; |
3467
|
|
|
} |
3468
|
|
|
if ($this->file_safe_name) { // formats the name |
3469
|
|
|
$this->file_dst_name_body = strtr($this->file_dst_name_body, 'ŠŽšžŸÀÃÂÃÄÅÇÈÉÊËÌÃÃŽÃÑÒÓÔÕÖØÙÚÛÜÃà áâãäåçèéêëìÃîïñòóôõöøùúûüýÿ', 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy'); |
3470
|
|
|
$this->file_dst_name_body = strtr($this->file_dst_name_body, array('Þ' => 'TH', 'þ' => 'th', 'Ã' => 'DH', 'ð' => 'dh', 'ß' => 'ss', 'Å’' => 'OE', 'Å“' => 'oe', 'Æ' => 'AE', 'æ' => 'ae', 'µ' => 'u')); |
3471
|
|
|
$this->file_dst_name_body = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $this->file_dst_name_body); |
3472
|
|
|
$this->log .= '- file name safe format<br />'; |
3473
|
|
|
} |
3474
|
|
|
|
3475
|
|
|
$this->log .= '- destination variables<br />'; |
3476
|
|
|
if (empty($this->file_dst_path) || is_null($this->file_dst_path)) { |
3477
|
|
|
$this->log .= ' file_dst_path : n/a<br />'; |
3478
|
|
|
} else { |
3479
|
|
|
$this->log .= ' file_dst_path : ' . $this->file_dst_path . '<br />'; |
3480
|
|
|
} |
3481
|
|
|
$this->log .= ' file_dst_name_body : ' . $this->file_dst_name_body . '<br />'; |
3482
|
|
|
$this->log .= ' file_dst_name_ext : ' . $this->file_dst_name_ext . '<br />'; |
3483
|
|
|
|
3484
|
|
|
// do we do some image manipulation? |
3485
|
|
|
$image_manipulation = ($this->file_is_image && ( |
3486
|
|
|
$this->image_resize |
3487
|
|
|
|| $this->image_convert != '' |
3488
|
|
|
|| is_numeric($this->image_brightness) |
3489
|
|
|
|| is_numeric($this->image_contrast) |
3490
|
|
|
|| is_numeric($this->image_opacity) |
3491
|
|
|
|| is_numeric($this->image_threshold) |
3492
|
|
|
|| !empty($this->image_tint_color) |
3493
|
|
|
|| !empty($this->image_overlay_color) |
3494
|
|
|
|| $this->image_unsharp |
3495
|
|
|
|| !empty($this->image_text) |
3496
|
|
|
|| $this->image_greyscale |
3497
|
|
|
|| $this->image_negative |
3498
|
|
|
|| !empty($this->image_watermark) |
3499
|
|
|
|| is_numeric($this->image_rotate) |
3500
|
|
|
|| is_numeric($this->jpeg_size) |
3501
|
|
|
|| !empty($this->image_flip) |
3502
|
|
|
|| !empty($this->image_crop) |
3503
|
|
|
|| !empty($this->image_precrop) |
3504
|
|
|
|| !empty($this->image_border) |
3505
|
|
|
|| !empty($this->image_border_transparent) |
3506
|
|
|
|| $this->image_frame > 0 |
3507
|
|
|
|| $this->image_bevel > 0 |
3508
|
|
|
|| $this->image_reflection_height)); |
3509
|
|
|
|
3510
|
|
|
// set the destination file name |
3511
|
|
|
$this->file_dst_name = $this->file_dst_name_body . (!empty($this->file_dst_name_ext) ? '.' . $this->file_dst_name_ext : ''); |
3512
|
|
|
|
3513
|
|
|
if (!$return_mode) { |
3514
|
|
|
if (!$this->file_auto_rename) { |
3515
|
|
|
$this->log .= '- no auto_rename if same filename exists<br />'; |
3516
|
|
|
$this->file_dst_pathname = $this->file_dst_path . $this->file_dst_name; |
3517
|
|
|
} else { |
3518
|
|
|
$this->log .= '- checking for auto_rename<br />'; |
3519
|
|
|
$this->file_dst_pathname = $this->file_dst_path . $this->file_dst_name; |
3520
|
|
|
$body = $this->file_dst_name_body; |
3521
|
|
|
$ext = ''; |
3522
|
|
|
// if we have changed the extension, then we add our increment before |
3523
|
|
|
if ($file_src_name_ext != $this->file_src_name_ext) { |
3524
|
|
|
if (substr($this->file_dst_name_body, -1 - strlen($this->file_src_name_ext)) == '.' . $this->file_src_name_ext) { |
3525
|
|
|
$body = substr($this->file_dst_name_body, 0, strlen($this->file_dst_name_body) - 1 - strlen($this->file_src_name_ext)); |
3526
|
|
|
$ext = '.' . $this->file_src_name_ext; |
3527
|
|
|
} |
3528
|
|
|
} |
3529
|
|
|
$cpt = 1; |
3530
|
|
|
while (@file_exists($this->file_dst_pathname)) { |
3531
|
|
|
$this->file_dst_name_body = $body . '_' . $cpt . $ext; |
3532
|
|
|
$this->file_dst_name = $this->file_dst_name_body . (!empty($this->file_dst_name_ext) ? '.' . $this->file_dst_name_ext : ''); |
3533
|
|
|
$cpt++; |
3534
|
|
|
$this->file_dst_pathname = $this->file_dst_path . $this->file_dst_name; |
3535
|
|
|
} |
3536
|
|
|
if ($cpt>1) $this->log .= ' auto_rename to ' . $this->file_dst_name . '<br />'; |
3537
|
|
|
} |
3538
|
|
|
|
3539
|
|
|
$this->log .= '- destination file details<br />'; |
3540
|
|
|
$this->log .= ' file_dst_name : ' . $this->file_dst_name . '<br />'; |
3541
|
|
|
$this->log .= ' file_dst_pathname : ' . $this->file_dst_pathname . '<br />'; |
3542
|
|
|
|
3543
|
|
|
if ($this->file_overwrite) { |
3544
|
|
|
$this->log .= '- no overwrite checking<br />'; |
3545
|
|
|
} else { |
3546
|
|
|
if (@file_exists($this->file_dst_pathname)) { |
3547
|
|
|
$this->processed = false; |
3548
|
|
|
$this->error = $this->translate('already_exists', array($this->file_dst_name)); |
3549
|
|
|
} else { |
3550
|
|
|
$this->log .= '- ' . $this->file_dst_name . ' doesn\'t exist already<br />'; |
3551
|
|
|
} |
3552
|
|
|
} |
3553
|
|
|
} |
3554
|
|
|
} |
3555
|
|
|
|
3556
|
|
|
if ($this->processed) { |
3557
|
|
|
// if we have already moved the uploaded file, we use the temporary copy as source file, and check if it exists |
3558
|
|
|
if (!empty($this->file_src_temp)) { |
3559
|
|
|
$this->log .= '- use the temp file instead of the original file since it is a second process<br />'; |
3560
|
|
|
$this->file_src_pathname = $this->file_src_temp; |
3561
|
|
|
if (!file_exists($this->file_src_pathname)) { |
3562
|
|
|
$this->processed = false; |
3563
|
|
|
$this->error = $this->translate('temp_file_missing'); |
3564
|
|
|
} |
3565
|
|
|
// if we haven't a temp file, and that we do check on uploads, we use is_uploaded_file() |
3566
|
|
|
} else if (!$this->no_upload_check) { |
3567
|
|
|
if (!is_uploaded_file($this->file_src_pathname)) { |
3568
|
|
|
$this->processed = false; |
3569
|
|
|
$this->error = $this->translate('source_missing'); |
3570
|
|
|
} |
3571
|
|
|
// otherwise, if we don't check on uploaded files (local file for instance), we use file_exists() |
3572
|
|
|
} else { |
3573
|
|
|
if (!file_exists($this->file_src_pathname)) { |
3574
|
|
|
$this->processed = false; |
3575
|
|
|
$this->error = $this->translate('source_missing'); |
3576
|
|
|
} |
3577
|
|
|
} |
3578
|
|
|
|
3579
|
|
|
// checks if the destination directory exists, and attempt to create it |
3580
|
|
|
if (!$return_mode) { |
3581
|
|
|
if ($this->processed && !file_exists($this->file_dst_path)) { |
3582
|
|
|
if ($this->dir_auto_create) { |
3583
|
|
|
$this->log .= '- ' . $this->file_dst_path . ' doesn\'t exist. Attempting creation:'; |
3584
|
|
|
if (!$this->rmkdir($this->file_dst_path, $this->dir_chmod)) { |
3585
|
|
|
$this->log .= ' failed<br />'; |
3586
|
|
|
$this->processed = false; |
3587
|
|
|
$this->error = $this->translate('destination_dir'); |
3588
|
|
|
} else { |
3589
|
|
|
$this->log .= ' success<br />'; |
3590
|
|
|
} |
3591
|
|
|
} else { |
3592
|
|
|
$this->error = $this->translate('destination_dir_missing'); |
3593
|
|
|
} |
3594
|
|
|
} |
3595
|
|
|
|
3596
|
|
|
if ($this->processed && !is_dir($this->file_dst_path)) { |
3597
|
|
|
$this->processed = false; |
3598
|
|
|
$this->error = $this->translate('destination_path_not_dir'); |
3599
|
|
|
} |
3600
|
|
|
|
3601
|
|
|
// checks if the destination directory is writeable, and attempt to make it writeable |
3602
|
|
|
$hash = md5($this->file_dst_name_body . rand(1, 1000)); |
3603
|
|
|
if ($this->processed && !($f = @fopen($this->file_dst_path . $hash . (!empty($this->file_dst_name_ext) ? '.' . $this->file_dst_name_ext : ''), 'a+'))) { |
3604
|
|
|
if ($this->dir_auto_chmod) { |
3605
|
|
|
$this->log .= '- ' . $this->file_dst_path . ' is not writeable. Attempting chmod:'; |
3606
|
|
|
if (!@chmod($this->file_dst_path, $this->dir_chmod)) { |
3607
|
|
|
$this->log .= ' failed<br />'; |
3608
|
|
|
$this->processed = false; |
3609
|
|
|
$this->error = $this->translate('destination_dir_write'); |
3610
|
|
|
} else { |
3611
|
|
|
$this->log .= ' success<br />'; |
3612
|
|
|
if (!($f = @fopen($this->file_dst_path . $hash . (!empty($this->file_dst_name_ext) ? '.' . $this->file_dst_name_ext : ''), 'a+'))) { // we re-check |
3613
|
|
|
$this->processed = false; |
3614
|
|
|
$this->error = $this->translate('destination_dir_write'); |
3615
|
|
|
} else { |
3616
|
|
|
@fclose($f); |
|
|
|
|
3617
|
|
|
} |
3618
|
|
|
} |
3619
|
|
|
} else { |
3620
|
|
|
$this->processed = false; |
3621
|
|
|
$this->error = $this->translate('destination_path_write'); |
3622
|
|
|
} |
3623
|
|
|
} else { |
3624
|
|
|
if ($this->processed) @fclose($f); |
|
|
|
|
3625
|
|
|
@unlink($this->file_dst_path . $hash . (!empty($this->file_dst_name_ext) ? '.' . $this->file_dst_name_ext : '')); |
|
|
|
|
3626
|
|
|
} |
3627
|
|
|
|
3628
|
|
|
|
3629
|
|
|
// if we have an uploaded file, and if it is the first process, and if we can't access the file directly (open_basedir restriction) |
3630
|
|
|
// then we create a temp file that will be used as the source file in subsequent processes |
3631
|
|
|
// the third condition is there to check if the file is not accessible *directly* (it already has positively gone through is_uploaded_file(), so it exists) |
3632
|
|
|
if (!$this->no_upload_check && empty($this->file_src_temp) && !@file_exists($this->file_src_pathname)) { |
3633
|
|
|
$this->log .= '- attempting to use a temp file:'; |
3634
|
|
|
$hash = md5($this->file_dst_name_body . rand(1, 1000)); |
3635
|
|
|
if (move_uploaded_file($this->file_src_pathname, $this->file_dst_path . $hash . (!empty($this->file_dst_name_ext) ? '.' . $this->file_dst_name_ext : ''))) { |
3636
|
|
|
$this->file_src_pathname = $this->file_dst_path . $hash . (!empty($this->file_dst_name_ext) ? '.' . $this->file_dst_name_ext : ''); |
3637
|
|
|
$this->file_src_temp = $this->file_src_pathname; |
3638
|
|
|
$this->log .= ' file created<br />'; |
3639
|
|
|
$this->log .= ' temp file is: ' . $this->file_src_temp . '<br />'; |
3640
|
|
|
} else { |
3641
|
|
|
$this->log .= ' failed<br />'; |
3642
|
|
|
$this->processed = false; |
3643
|
|
|
$this->error = $this->translate('temp_file'); |
3644
|
|
|
} |
3645
|
|
|
} |
3646
|
|
|
} |
3647
|
|
|
} |
3648
|
|
|
|
3649
|
|
|
if ($this->processed) { |
3650
|
|
|
|
3651
|
|
|
// we do a quick check to ensure the file is really an image |
3652
|
|
|
// we can do this only now, as it would have failed before in case of open_basedir |
3653
|
|
|
if ($image_manipulation && !@getimagesize($this->file_src_pathname)) { |
3654
|
|
|
$this->log .= '- the file is not an image!<br />'; |
3655
|
|
|
$image_manipulation = false; |
3656
|
|
|
} |
3657
|
|
|
|
3658
|
|
|
if ($image_manipulation) { |
3659
|
|
|
|
3660
|
|
|
// checks if the source file is readable |
3661
|
|
|
if ($this->processed && !($f = @fopen($this->file_src_pathname, 'r'))) { |
3662
|
|
|
$this->processed = false; |
3663
|
|
|
$this->error = $this->translate('source_not_readable'); |
3664
|
|
|
} else { |
3665
|
|
|
@fclose($f); |
|
|
|
|
3666
|
|
|
} |
3667
|
|
|
|
3668
|
|
|
// we now do all the image manipulations |
3669
|
|
|
$this->log .= '- image resizing or conversion wanted<br />'; |
3670
|
|
|
if ($this->gdversion()) { |
3671
|
|
|
switch($this->image_src_type) { |
3672
|
|
|
case 'jpg': |
3673
|
|
|
if (!function_exists('imagecreatefromjpeg')) { |
3674
|
|
|
$this->processed = false; |
3675
|
|
|
$this->error = $this->translate('no_create_support', array('JPEG')); |
3676
|
|
|
} else { |
3677
|
|
|
$image_src = @imagecreatefromjpeg($this->file_src_pathname); |
3678
|
|
|
if (!$image_src) { |
3679
|
|
|
$this->processed = false; |
3680
|
|
|
$this->error = $this->translate('create_error', array('JPEG')); |
3681
|
|
|
} else { |
3682
|
|
|
$this->log .= '- source image is JPEG<br />'; |
3683
|
|
|
} |
3684
|
|
|
} |
3685
|
|
|
break; |
3686
|
|
|
case 'png': |
3687
|
|
|
if (!function_exists('imagecreatefrompng')) { |
3688
|
|
|
$this->processed = false; |
3689
|
|
|
$this->error = $this->translate('no_create_support', array('PNG')); |
3690
|
|
|
} else { |
3691
|
|
|
$image_src = @imagecreatefrompng($this->file_src_pathname); |
3692
|
|
|
if (!$image_src) { |
3693
|
|
|
$this->processed = false; |
3694
|
|
|
$this->error = $this->translate('create_error', array('PNG')); |
3695
|
|
|
} else { |
3696
|
|
|
$this->log .= '- source image is PNG<br />'; |
3697
|
|
|
} |
3698
|
|
|
} |
3699
|
|
|
break; |
3700
|
|
|
case 'gif': |
3701
|
|
|
if (!function_exists('imagecreatefromgif')) { |
3702
|
|
|
$this->processed = false; |
3703
|
|
|
$this->error = $this->translate('no_create_support', array('GIF')); |
3704
|
|
|
} else { |
3705
|
|
|
$image_src = @imagecreatefromgif($this->file_src_pathname); |
3706
|
|
|
if (!$image_src) { |
3707
|
|
|
$this->processed = false; |
3708
|
|
|
$this->error = $this->translate('create_error', array('GIF')); |
3709
|
|
|
} else { |
3710
|
|
|
$this->log .= '- source image is GIF<br />'; |
3711
|
|
|
} |
3712
|
|
|
} |
3713
|
|
|
break; |
3714
|
|
|
case 'bmp': |
3715
|
|
|
if (!method_exists($this, 'imagecreatefrombmp')) { |
3716
|
|
|
$this->processed = false; |
3717
|
|
|
$this->error = $this->translate('no_create_support', array('BMP')); |
3718
|
|
|
} else { |
3719
|
|
|
$image_src = @$this->imagecreatefrombmp($this->file_src_pathname); |
3720
|
|
|
if (!$image_src) { |
3721
|
|
|
$this->processed = false; |
3722
|
|
|
$this->error = $this->translate('create_error', array('BMP')); |
3723
|
|
|
} else { |
3724
|
|
|
$this->log .= '- source image is BMP<br />'; |
3725
|
|
|
} |
3726
|
|
|
} |
3727
|
|
|
break; |
3728
|
|
|
default: |
3729
|
|
|
$this->processed = false; |
3730
|
|
|
$this->error = $this->translate('source_invalid'); |
3731
|
|
|
} |
3732
|
|
|
} else { |
3733
|
|
|
$this->processed = false; |
3734
|
|
|
$this->error = $this->translate('gd_missing'); |
3735
|
|
|
} |
3736
|
|
|
|
3737
|
|
|
if ($this->processed && $image_src) { |
3738
|
|
|
|
3739
|
|
|
// we have to set image_convert if it is not already |
3740
|
|
|
if (empty($this->image_convert)) { |
3741
|
|
|
$this->log .= '- setting destination file type to ' . $this->image_src_type . '<br />'; |
3742
|
|
|
$this->image_convert = $this->image_src_type; |
3743
|
|
|
} |
3744
|
|
|
|
3745
|
|
|
if (!in_array($this->image_convert, $this->image_supported)) { |
3746
|
|
|
$this->image_convert = 'jpg'; |
3747
|
|
|
} |
3748
|
|
|
|
3749
|
|
|
// we set the default color to be the background color if we don't output in a transparent format |
3750
|
|
|
if ($this->image_convert != 'png' && $this->image_convert != 'gif' && !empty($this->image_default_color) && empty($this->image_background_color)) $this->image_background_color = $this->image_default_color; |
|
|
|
|
3751
|
|
|
if (!empty($this->image_background_color)) $this->image_default_color = $this->image_background_color; |
|
|
|
|
3752
|
|
|
if (empty($this->image_default_color)) $this->image_default_color = '#FFFFFF'; |
|
|
|
|
3753
|
|
|
|
3754
|
|
|
$this->image_src_x = imagesx($image_src); |
3755
|
|
|
$this->image_src_y = imagesy($image_src); |
3756
|
|
|
$gd_version = $this->gdversion(); |
3757
|
|
|
$ratio_crop = null; |
3758
|
|
|
|
3759
|
|
|
if (!imageistruecolor($image_src)) { // $this->image_src_type == 'gif' |
3760
|
|
|
$this->log .= '- image is detected as having a palette<br />'; |
3761
|
|
|
$this->image_is_palette = true; |
3762
|
|
|
$this->image_transparent_color = imagecolortransparent($image_src); |
|
|
|
|
3763
|
|
|
if ($this->image_transparent_color >= 0 && imagecolorstotal($image_src) > $this->image_transparent_color) { |
3764
|
|
|
$this->image_is_transparent = true; |
3765
|
|
|
$this->log .= ' palette image is detected as transparent<br />'; |
3766
|
|
|
} |
3767
|
|
|
// if the image has a palette (GIF), we convert it to true color, preserving transparency |
3768
|
|
|
$this->log .= ' convert palette image to true color<br />'; |
3769
|
|
|
$true_color = imagecreatetruecolor($this->image_src_x, $this->image_src_y); |
3770
|
|
|
imagealphablending($true_color, false); |
3771
|
|
|
imagesavealpha($true_color, true); |
3772
|
|
|
for ($x = 0; $x < $this->image_src_x; $x++) { |
3773
|
|
|
for ($y = 0; $y < $this->image_src_y; $y++) { |
3774
|
|
|
if ($this->image_transparent_color >= 0 && imagecolorat($image_src, $x, $y) == $this->image_transparent_color) { |
3775
|
|
|
imagesetpixel($true_color, $x, $y, 127 << 24); |
3776
|
|
|
} else { |
3777
|
|
|
$rgb = imagecolorsforindex($image_src, imagecolorat($image_src, $x, $y)); |
3778
|
|
|
imagesetpixel($true_color, $x, $y, ($rgb['alpha'] << 24) | ($rgb['red'] << 16) | ($rgb['green'] << 8) | $rgb['blue']); |
3779
|
|
|
} |
3780
|
|
|
} |
3781
|
|
|
} |
3782
|
|
|
$image_src = $this->imagetransfer($true_color, $image_src); |
3783
|
|
|
imagealphablending($image_src, false); |
3784
|
|
|
imagesavealpha($image_src, true); |
3785
|
|
|
$this->image_is_palette = false; |
3786
|
|
|
} |
3787
|
|
|
|
3788
|
|
|
|
3789
|
|
|
$image_dst = & $image_src; |
3790
|
|
|
|
3791
|
|
|
// pre-crop image, before resizing |
3792
|
|
|
if ((!empty($this->image_precrop))) { |
3793
|
|
|
list($ct, $cr, $cb, $cl) = $this->getoffsets($this->image_precrop, $this->image_src_x, $this->image_src_y, true, true); |
3794
|
|
|
$this->log .= '- pre-crop image : ' . $ct . ' ' . $cr . ' ' . $cb . ' ' . $cl . ' <br />'; |
3795
|
|
|
$this->image_src_x = $this->image_src_x - $cl - $cr; |
|
|
|
|
3796
|
|
|
$this->image_src_y = $this->image_src_y - $ct - $cb; |
|
|
|
|
3797
|
|
|
if ($this->image_src_x < 1) $this->image_src_x = 1; |
3798
|
|
|
if ($this->image_src_y < 1) $this->image_src_y = 1; |
3799
|
|
|
$tmp = $this->imagecreatenew($this->image_src_x, $this->image_src_y); |
3800
|
|
|
|
3801
|
|
|
// we copy the image into the recieving image |
3802
|
|
|
imagecopy($tmp, $image_dst, 0, 0, $cl, $ct, $this->image_src_x, $this->image_src_y); |
3803
|
|
|
|
3804
|
|
|
// if we crop with negative margins, we have to make sure the extra bits are the right color, or transparent |
3805
|
|
|
if ($ct < 0 || $cr < 0 || $cb < 0 || $cl < 0 ) { |
3806
|
|
|
// use the background color if present |
3807
|
|
|
if (!empty($this->image_background_color)) { |
3808
|
|
|
list($red, $green, $blue) = $this->getcolors($this->image_background_color); |
|
|
|
|
3809
|
|
|
$fill = imagecolorallocate($tmp, $red, $green, $blue); |
3810
|
|
|
} else { |
3811
|
|
|
$fill = imagecolorallocatealpha($tmp, 0, 0, 0, 127); |
3812
|
|
|
} |
3813
|
|
|
// fills eventual negative margins |
3814
|
|
|
if ($ct < 0) imagefilledrectangle($tmp, 0, 0, $this->image_src_x, -$ct, $fill); |
3815
|
|
|
if ($cr < 0) imagefilledrectangle($tmp, $this->image_src_x + $cr, 0, $this->image_src_x, $this->image_src_y, $fill); |
3816
|
|
|
if ($cb < 0) imagefilledrectangle($tmp, 0, $this->image_src_y + $cb, $this->image_src_x, $this->image_src_y, $fill); |
3817
|
|
|
if ($cl < 0) imagefilledrectangle($tmp, 0, 0, -$cl, $this->image_src_y, $fill); |
3818
|
|
|
} |
3819
|
|
|
|
3820
|
|
|
// we transfert tmp into image_dst |
3821
|
|
|
$image_dst = $this->imagetransfer($tmp, $image_dst); |
3822
|
|
|
} |
3823
|
|
|
|
3824
|
|
|
// resize image (and move image_src_x, image_src_y dimensions into image_dst_x, image_dst_y) |
3825
|
|
|
if ($this->image_resize) { |
3826
|
|
|
$this->log .= '- resizing...<br />'; |
3827
|
|
|
|
3828
|
|
|
if ($this->image_ratio_x) { |
3829
|
|
|
$this->log .= ' calculate x size<br />'; |
3830
|
|
|
$this->image_dst_x = round(($this->image_src_x * $this->image_y) / $this->image_src_y); |
|
|
|
|
3831
|
|
|
$this->image_dst_y = $this->image_y; |
3832
|
|
|
} else if ($this->image_ratio_y) { |
3833
|
|
|
$this->log .= ' calculate y size<br />'; |
3834
|
|
|
$this->image_dst_x = $this->image_x; |
3835
|
|
|
$this->image_dst_y = round(($this->image_src_y * $this->image_x) / $this->image_src_x); |
|
|
|
|
3836
|
|
|
} else if (is_numeric($this->image_ratio_pixels)) { |
3837
|
|
|
$this->log .= ' calculate x/y size to match a number of pixels<br />'; |
3838
|
|
|
$pixels = $this->image_src_y * $this->image_src_x; |
3839
|
|
|
$diff = sqrt($this->image_ratio_pixels / $pixels); |
3840
|
|
|
$this->image_dst_x = round($this->image_src_x * $diff); |
|
|
|
|
3841
|
|
|
$this->image_dst_y = round($this->image_src_y * $diff); |
|
|
|
|
3842
|
|
|
} else if ($this->image_ratio || $this->image_ratio_crop || $this->image_ratio_fill || $this->image_ratio_no_zoom_in || $this->image_ratio_no_zoom_out) { |
3843
|
|
|
$this->log .= ' check x/y sizes<br />'; |
3844
|
|
|
if ((!$this->image_ratio_no_zoom_in && !$this->image_ratio_no_zoom_out) |
3845
|
|
|
|| ($this->image_ratio_no_zoom_in && ($this->image_src_x > $this->image_x || $this->image_src_y > $this->image_y)) |
3846
|
|
|
|| ($this->image_ratio_no_zoom_out && $this->image_src_x < $this->image_x && $this->image_src_y < $this->image_y)) { |
3847
|
|
|
$this->image_dst_x = $this->image_x; |
3848
|
|
|
$this->image_dst_y = $this->image_y; |
3849
|
|
|
if ($this->image_ratio_crop) { |
3850
|
|
|
if (!is_string($this->image_ratio_crop)) $this->image_ratio_crop = ''; |
3851
|
|
|
$this->image_ratio_crop = strtolower($this->image_ratio_crop); |
3852
|
|
|
if (($this->image_src_x/$this->image_x) > ($this->image_src_y/$this->image_y)) { |
3853
|
|
|
$this->image_dst_y = $this->image_y; |
3854
|
|
|
$this->image_dst_x = intval($this->image_src_x*($this->image_y / $this->image_src_y)); |
3855
|
|
|
$ratio_crop = array(); |
3856
|
|
|
$ratio_crop['x'] = $this->image_dst_x - $this->image_x; |
3857
|
|
|
if (strpos($this->image_ratio_crop, 'l') !== false) { |
3858
|
|
|
$ratio_crop['l'] = 0; |
3859
|
|
|
$ratio_crop['r'] = $ratio_crop['x']; |
3860
|
|
|
} else if (strpos($this->image_ratio_crop, 'r') !== false) { |
3861
|
|
|
$ratio_crop['l'] = $ratio_crop['x']; |
3862
|
|
|
$ratio_crop['r'] = 0; |
3863
|
|
|
} else { |
3864
|
|
|
$ratio_crop['l'] = round($ratio_crop['x']/2); |
3865
|
|
|
$ratio_crop['r'] = $ratio_crop['x'] - $ratio_crop['l']; |
3866
|
|
|
} |
3867
|
|
|
$this->log .= ' ratio_crop_x : ' . $ratio_crop['x'] . ' (' . $ratio_crop['l'] . ';' . $ratio_crop['r'] . ')<br />'; |
3868
|
|
|
if (is_null($this->image_crop)) $this->image_crop = array(0, 0, 0, 0); |
3869
|
|
|
} else { |
3870
|
|
|
$this->image_dst_x = $this->image_x; |
3871
|
|
|
$this->image_dst_y = intval($this->image_src_y*($this->image_x / $this->image_src_x)); |
3872
|
|
|
$ratio_crop = array(); |
3873
|
|
|
$ratio_crop['y'] = $this->image_dst_y - $this->image_y; |
3874
|
|
|
if (strpos($this->image_ratio_crop, 't') !== false) { |
3875
|
|
|
$ratio_crop['t'] = 0; |
3876
|
|
|
$ratio_crop['b'] = $ratio_crop['y']; |
3877
|
|
|
} else if (strpos($this->image_ratio_crop, 'b') !== false) { |
3878
|
|
|
$ratio_crop['t'] = $ratio_crop['y']; |
3879
|
|
|
$ratio_crop['b'] = 0; |
3880
|
|
|
} else { |
3881
|
|
|
$ratio_crop['t'] = round($ratio_crop['y']/2); |
3882
|
|
|
$ratio_crop['b'] = $ratio_crop['y'] - $ratio_crop['t']; |
3883
|
|
|
} |
3884
|
|
|
$this->log .= ' ratio_crop_y : ' . $ratio_crop['y'] . ' (' . $ratio_crop['t'] . ';' . $ratio_crop['b'] . ')<br />'; |
3885
|
|
|
if (is_null($this->image_crop)) $this->image_crop = array(0, 0, 0, 0); |
3886
|
|
|
} |
3887
|
|
|
} else if ($this->image_ratio_fill) { |
3888
|
|
|
if (!is_string($this->image_ratio_fill)) $this->image_ratio_fill = ''; |
3889
|
|
|
$this->image_ratio_fill = strtolower($this->image_ratio_fill); |
3890
|
|
|
if (($this->image_src_x/$this->image_x) < ($this->image_src_y/$this->image_y)) { |
3891
|
|
|
$this->image_dst_y = $this->image_y; |
3892
|
|
|
$this->image_dst_x = intval($this->image_src_x*($this->image_y / $this->image_src_y)); |
3893
|
|
|
$ratio_crop = array(); |
3894
|
|
|
$ratio_crop['x'] = $this->image_dst_x - $this->image_x; |
3895
|
|
|
if (strpos($this->image_ratio_fill, 'l') !== false) { |
3896
|
|
|
$ratio_crop['l'] = 0; |
3897
|
|
|
$ratio_crop['r'] = $ratio_crop['x']; |
3898
|
|
|
} else if (strpos($this->image_ratio_fill, 'r') !== false) { |
3899
|
|
|
$ratio_crop['l'] = $ratio_crop['x']; |
3900
|
|
|
$ratio_crop['r'] = 0; |
3901
|
|
|
} else { |
3902
|
|
|
$ratio_crop['l'] = round($ratio_crop['x']/2); |
3903
|
|
|
$ratio_crop['r'] = $ratio_crop['x'] - $ratio_crop['l']; |
3904
|
|
|
} |
3905
|
|
|
$this->log .= ' ratio_fill_x : ' . $ratio_crop['x'] . ' (' . $ratio_crop['l'] . ';' . $ratio_crop['r'] . ')<br />'; |
3906
|
|
|
if (is_null($this->image_crop)) $this->image_crop = array(0, 0, 0, 0); |
3907
|
|
|
} else { |
3908
|
|
|
$this->image_dst_x = $this->image_x; |
3909
|
|
|
$this->image_dst_y = intval($this->image_src_y*($this->image_x / $this->image_src_x)); |
3910
|
|
|
$ratio_crop = array(); |
3911
|
|
|
$ratio_crop['y'] = $this->image_dst_y - $this->image_y; |
3912
|
|
|
if (strpos($this->image_ratio_fill, 't') !== false) { |
3913
|
|
|
$ratio_crop['t'] = 0; |
3914
|
|
|
$ratio_crop['b'] = $ratio_crop['y']; |
3915
|
|
|
} else if (strpos($this->image_ratio_fill, 'b') !== false) { |
3916
|
|
|
$ratio_crop['t'] = $ratio_crop['y']; |
3917
|
|
|
$ratio_crop['b'] = 0; |
3918
|
|
|
} else { |
3919
|
|
|
$ratio_crop['t'] = round($ratio_crop['y']/2); |
3920
|
|
|
$ratio_crop['b'] = $ratio_crop['y'] - $ratio_crop['t']; |
3921
|
|
|
} |
3922
|
|
|
$this->log .= ' ratio_fill_y : ' . $ratio_crop['y'] . ' (' . $ratio_crop['t'] . ';' . $ratio_crop['b'] . ')<br />'; |
3923
|
|
|
if (is_null($this->image_crop)) $this->image_crop = array(0, 0, 0, 0); |
3924
|
|
|
} |
3925
|
|
|
} else { |
3926
|
|
|
if (($this->image_src_x/$this->image_x) > ($this->image_src_y/$this->image_y)) { |
3927
|
|
|
$this->image_dst_x = $this->image_x; |
3928
|
|
|
$this->image_dst_y = intval($this->image_src_y*($this->image_x / $this->image_src_x)); |
3929
|
|
|
} else { |
3930
|
|
|
$this->image_dst_y = $this->image_y; |
3931
|
|
|
$this->image_dst_x = intval($this->image_src_x*($this->image_y / $this->image_src_y)); |
3932
|
|
|
} |
3933
|
|
|
} |
3934
|
|
|
} else { |
3935
|
|
|
$this->log .= ' doesn\'t calculate x/y sizes<br />'; |
3936
|
|
|
$this->image_dst_x = $this->image_src_x; |
|
|
|
|
3937
|
|
|
$this->image_dst_y = $this->image_src_y; |
|
|
|
|
3938
|
|
|
} |
3939
|
|
|
} else { |
3940
|
|
|
$this->log .= ' use plain sizes<br />'; |
3941
|
|
|
$this->image_dst_x = $this->image_x; |
3942
|
|
|
$this->image_dst_y = $this->image_y; |
3943
|
|
|
} |
3944
|
|
|
|
3945
|
|
|
if ($this->image_dst_x < 1) $this->image_dst_x = 1; |
3946
|
|
|
if ($this->image_dst_y < 1) $this->image_dst_y = 1; |
3947
|
|
|
$tmp = $this->imagecreatenew($this->image_dst_x, $this->image_dst_y); |
3948
|
|
|
|
3949
|
|
|
if ($gd_version >= 2) { |
3950
|
|
|
$res = imagecopyresampled($tmp, $image_src, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y, $this->image_src_x, $this->image_src_y); |
3951
|
|
|
} else { |
3952
|
|
|
$res = imagecopyresized($tmp, $image_src, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y, $this->image_src_x, $this->image_src_y); |
3953
|
|
|
} |
3954
|
|
|
|
3955
|
|
|
$this->log .= ' resized image object created<br />'; |
3956
|
|
|
$this->log .= ' image_src_x y : ' . $this->image_src_x . ' x ' . $this->image_src_y . '<br />'; |
3957
|
|
|
$this->log .= ' image_dst_x y : ' . $this->image_dst_x . ' x ' . $this->image_dst_y . '<br />'; |
3958
|
|
|
// we transfert tmp into image_dst |
3959
|
|
|
$image_dst = $this->imagetransfer($tmp, $image_dst); |
3960
|
|
|
|
3961
|
|
|
} else { |
3962
|
|
|
$this->image_dst_x = $this->image_src_x; |
3963
|
|
|
$this->image_dst_y = $this->image_src_y; |
3964
|
|
|
} |
3965
|
|
|
|
3966
|
|
|
// crop image (and also crops if image_ratio_crop is used) |
3967
|
|
|
if ((!empty($this->image_crop) || !is_null($ratio_crop))) { |
3968
|
|
|
list($ct, $cr, $cb, $cl) = $this->getoffsets($this->image_crop, $this->image_dst_x, $this->image_dst_y, true, true); |
3969
|
|
|
// we adjust the cropping if we use image_ratio_crop |
3970
|
|
|
if (!is_null($ratio_crop)) { |
3971
|
|
|
if (array_key_exists('t', $ratio_crop)) $ct += $ratio_crop['t']; |
3972
|
|
|
if (array_key_exists('r', $ratio_crop)) $cr += $ratio_crop['r']; |
3973
|
|
|
if (array_key_exists('b', $ratio_crop)) $cb += $ratio_crop['b']; |
3974
|
|
|
if (array_key_exists('l', $ratio_crop)) $cl += $ratio_crop['l']; |
3975
|
|
|
} |
3976
|
|
|
$this->log .= '- crop image : ' . $ct . ' ' . $cr . ' ' . $cb . ' ' . $cl . ' <br />'; |
3977
|
|
|
$this->image_dst_x = $this->image_dst_x - $cl - $cr; |
|
|
|
|
3978
|
|
|
$this->image_dst_y = $this->image_dst_y - $ct - $cb; |
|
|
|
|
3979
|
|
|
if ($this->image_dst_x < 1) $this->image_dst_x = 1; |
3980
|
|
|
if ($this->image_dst_y < 1) $this->image_dst_y = 1; |
3981
|
|
|
$tmp = $this->imagecreatenew($this->image_dst_x, $this->image_dst_y); |
3982
|
|
|
|
3983
|
|
|
// we copy the image into the recieving image |
3984
|
|
|
imagecopy($tmp, $image_dst, 0, 0, $cl, $ct, $this->image_dst_x, $this->image_dst_y); |
3985
|
|
|
|
3986
|
|
|
// if we crop with negative margins, we have to make sure the extra bits are the right color, or transparent |
3987
|
|
|
if ($ct < 0 || $cr < 0 || $cb < 0 || $cl < 0 ) { |
3988
|
|
|
// use the background color if present |
3989
|
|
|
if (!empty($this->image_background_color)) { |
3990
|
|
|
list($red, $green, $blue) = $this->getcolors($this->image_background_color); |
|
|
|
|
3991
|
|
|
$fill = imagecolorallocate($tmp, $red, $green, $blue); |
3992
|
|
|
} else { |
3993
|
|
|
$fill = imagecolorallocatealpha($tmp, 0, 0, 0, 127); |
3994
|
|
|
} |
3995
|
|
|
// fills eventual negative margins |
3996
|
|
|
if ($ct < 0) imagefilledrectangle($tmp, 0, 0, $this->image_dst_x, -$ct-1, $fill); |
3997
|
|
|
if ($cr < 0) imagefilledrectangle($tmp, $this->image_dst_x + $cr, 0, $this->image_dst_x, $this->image_dst_y, $fill); |
3998
|
|
|
if ($cb < 0) imagefilledrectangle($tmp, 0, $this->image_dst_y + $cb, $this->image_dst_x, $this->image_dst_y, $fill); |
3999
|
|
|
if ($cl < 0) imagefilledrectangle($tmp, 0, 0, -$cl-1, $this->image_dst_y, $fill); |
4000
|
|
|
} |
4001
|
|
|
|
4002
|
|
|
// we transfert tmp into image_dst |
4003
|
|
|
$image_dst = $this->imagetransfer($tmp, $image_dst); |
4004
|
|
|
} |
4005
|
|
|
|
4006
|
|
|
// flip image |
4007
|
|
|
if ($gd_version >= 2 && !empty($this->image_flip)) { |
4008
|
|
|
$this->image_flip = strtolower($this->image_flip); |
4009
|
|
|
$this->log .= '- flip image : ' . $this->image_flip . '<br />'; |
4010
|
|
|
$tmp = $this->imagecreatenew($this->image_dst_x, $this->image_dst_y); |
4011
|
|
|
for ($x = 0; $x < $this->image_dst_x; $x++) { |
4012
|
|
|
for ($y = 0; $y < $this->image_dst_y; $y++){ |
4013
|
|
|
if (strpos($this->image_flip, 'v') !== false) { |
4014
|
|
|
imagecopy($tmp, $image_dst, $this->image_dst_x - $x - 1, $y, $x, $y, 1, 1); |
4015
|
|
|
} else { |
4016
|
|
|
imagecopy($tmp, $image_dst, $x, $this->image_dst_y - $y - 1, $x, $y, 1, 1); |
4017
|
|
|
} |
4018
|
|
|
} |
4019
|
|
|
} |
4020
|
|
|
// we transfert tmp into image_dst |
4021
|
|
|
$image_dst = $this->imagetransfer($tmp, $image_dst); |
4022
|
|
|
} |
4023
|
|
|
|
4024
|
|
|
// rotate image |
4025
|
|
|
if ($gd_version >= 2 && is_numeric($this->image_rotate)) { |
4026
|
|
|
if (!in_array($this->image_rotate, array(0, 90, 180, 270))) $this->image_rotate = 0; |
4027
|
|
|
if ($this->image_rotate != 0) { |
4028
|
|
|
if ($this->image_rotate == 90 || $this->image_rotate == 270) { |
4029
|
|
|
$tmp = $this->imagecreatenew($this->image_dst_y, $this->image_dst_x); |
4030
|
|
|
} else { |
4031
|
|
|
$tmp = $this->imagecreatenew($this->image_dst_x, $this->image_dst_y); |
4032
|
|
|
} |
4033
|
|
|
$this->log .= '- rotate image : ' . $this->image_rotate . '<br />'; |
4034
|
|
|
for ($x = 0; $x < $this->image_dst_x; $x++) { |
4035
|
|
|
for ($y = 0; $y < $this->image_dst_y; $y++){ |
4036
|
|
|
if ($this->image_rotate == 90) { |
4037
|
|
|
imagecopy($tmp, $image_dst, $y, $x, $x, $this->image_dst_y - $y - 1, 1, 1); |
4038
|
|
|
} else if ($this->image_rotate == 180) { |
4039
|
|
|
imagecopy($tmp, $image_dst, $x, $y, $this->image_dst_x - $x - 1, $this->image_dst_y - $y - 1, 1, 1); |
4040
|
|
|
} else if ($this->image_rotate == 270) { |
4041
|
|
|
imagecopy($tmp, $image_dst, $y, $x, $this->image_dst_x - $x - 1, $y, 1, 1); |
4042
|
|
|
} else { |
4043
|
|
|
imagecopy($tmp, $image_dst, $x, $y, $x, $y, 1, 1); |
4044
|
|
|
} |
4045
|
|
|
} |
4046
|
|
|
} |
4047
|
|
|
if ($this->image_rotate == 90 || $this->image_rotate == 270) { |
4048
|
|
|
$t = $this->image_dst_y; |
4049
|
|
|
$this->image_dst_y = $this->image_dst_x; |
|
|
|
|
4050
|
|
|
$this->image_dst_x = $t; |
|
|
|
|
4051
|
|
|
} |
4052
|
|
|
// we transfert tmp into image_dst |
4053
|
|
|
$image_dst = $this->imagetransfer($tmp, $image_dst); |
4054
|
|
|
} |
4055
|
|
|
} |
4056
|
|
|
|
4057
|
|
|
// unsharp mask |
4058
|
|
|
if ($gd_version >= 2 && $this->image_unsharp && is_numeric($this->image_unsharp_amount) && is_numeric($this->image_unsharp_radius) && is_numeric($this->image_unsharp_threshold)) { |
4059
|
|
|
// Unsharp Mask for PHP - version 2.1.1 |
4060
|
|
|
// Unsharp mask algorithm by Torstein Hønsi 2003-07. |
4061
|
|
|
// Used with permission |
4062
|
|
|
// Modified to support alpha transparency |
4063
|
|
|
if ($this->image_unsharp_amount > 500) $this->image_unsharp_amount = 500; |
4064
|
|
|
$this->image_unsharp_amount = $this->image_unsharp_amount * 0.016; |
|
|
|
|
4065
|
|
|
if ($this->image_unsharp_radius > 50) $this->image_unsharp_radius = 50; |
4066
|
|
|
$this->image_unsharp_radius = $this->image_unsharp_radius * 2; |
|
|
|
|
4067
|
|
|
if ($this->image_unsharp_threshold > 255) $this->image_unsharp_threshold = 255; |
4068
|
|
|
$this->image_unsharp_radius = abs(round($this->image_unsharp_radius)); |
|
|
|
|
4069
|
|
|
if ($this->image_unsharp_radius != 0) { |
4070
|
|
|
$this->image_dst_x = imagesx($image_dst); $this->image_dst_y = imagesy($image_dst); |
4071
|
|
|
$canvas = $this->imagecreatenew($this->image_dst_x, $this->image_dst_y, false, true); |
4072
|
|
|
$blur = $this->imagecreatenew($this->image_dst_x, $this->image_dst_y, false, true); |
4073
|
|
|
if (function_exists('imageconvolution')) { // PHP >= 5.1 |
4074
|
|
|
$matrix = array(array( 1, 2, 1 ), array( 2, 4, 2 ), array( 1, 2, 1 )); |
4075
|
|
|
imagecopy($blur, $image_dst, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y); |
4076
|
|
|
imageconvolution($blur, $matrix, 16, 0); |
4077
|
|
|
} else { |
4078
|
|
|
for ($i = 0; $i < $this->image_unsharp_radius; $i++) { |
4079
|
|
|
imagecopy($blur, $image_dst, 0, 0, 1, 0, $this->image_dst_x - 1, $this->image_dst_y); // left |
4080
|
|
|
$this->imagecopymergealpha($blur, $image_dst, 1, 0, 0, 0, $this->image_dst_x, $this->image_dst_y, 50); // right |
4081
|
|
|
$this->imagecopymergealpha($blur, $image_dst, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y, 50); // center |
4082
|
|
|
imagecopy($canvas, $blur, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y); |
4083
|
|
|
$this->imagecopymergealpha($blur, $canvas, 0, 0, 0, 1, $this->image_dst_x, $this->image_dst_y - 1, 33.33333 ); // up |
4084
|
|
|
$this->imagecopymergealpha($blur, $canvas, 0, 1, 0, 0, $this->image_dst_x, $this->image_dst_y, 25); // down |
4085
|
|
|
} |
4086
|
|
|
} |
4087
|
|
|
$p_new = array(); |
4088
|
|
|
if($this->image_unsharp_threshold>0) { |
4089
|
|
|
for ($x = 0; $x < $this->image_dst_x-1; $x++) { |
4090
|
|
|
for ($y = 0; $y < $this->image_dst_y; $y++) { |
4091
|
|
|
$p_orig = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); |
4092
|
|
|
$p_blur = imagecolorsforindex($blur, imagecolorat($blur, $x, $y)); |
4093
|
|
|
$p_new['red'] = (abs($p_orig['red'] - $p_blur['red']) >= $this->image_unsharp_threshold) ? max(0, min(255, ($this->image_unsharp_amount * ($p_orig['red'] - $p_blur['red'])) + $p_orig['red'])) : $p_orig['red']; |
4094
|
|
|
$p_new['green'] = (abs($p_orig['green'] - $p_blur['green']) >= $this->image_unsharp_threshold) ? max(0, min(255, ($this->image_unsharp_amount * ($p_orig['green'] - $p_blur['green'])) + $p_orig['green'])) : $p_orig['green']; |
4095
|
|
|
$p_new['blue'] = (abs($p_orig['blue'] - $p_blur['blue']) >= $this->image_unsharp_threshold) ? max(0, min(255, ($this->image_unsharp_amount * ($p_orig['blue'] - $p_blur['blue'])) + $p_orig['blue'])) : $p_orig['blue']; |
4096
|
|
|
if (($p_orig['red'] != $p_new['red']) || ($p_orig['green'] != $p_new['green']) || ($p_orig['blue'] != $p_new['blue'])) { |
4097
|
|
|
$color = imagecolorallocatealpha($image_dst, $p_new['red'], $p_new['green'], $p_new['blue'], $p_orig['alpha']); |
4098
|
|
|
imagesetpixel($image_dst, $x, $y, $color); |
4099
|
|
|
} |
4100
|
|
|
} |
4101
|
|
|
} |
4102
|
|
|
} else { |
4103
|
|
|
for ($x = 0; $x < $this->image_dst_x; $x++) { |
4104
|
|
|
for ($y = 0; $y < $this->image_dst_y; $y++) { |
4105
|
|
|
$p_orig = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); |
4106
|
|
|
$p_blur = imagecolorsforindex($blur, imagecolorat($blur, $x, $y)); |
4107
|
|
|
$p_new['red'] = ($this->image_unsharp_amount * ($p_orig['red'] - $p_blur['red'])) + $p_orig['red']; |
4108
|
|
|
if ($p_new['red']>255) { $p_new['red']=255; } elseif ($p_new['red']<0) { $p_new['red']=0; } |
4109
|
|
|
$p_new['green'] = ($this->image_unsharp_amount * ($p_orig['green'] - $p_blur['green'])) + $p_orig['green']; |
4110
|
|
|
if ($p_new['green']>255) { $p_new['green']=255; } elseif ($p_new['green']<0) { $p_new['green']=0; } |
4111
|
|
|
$p_new['blue'] = ($this->image_unsharp_amount * ($p_orig['blue'] - $p_blur['blue'])) + $p_orig['blue']; |
4112
|
|
|
if ($p_new['blue']>255) { $p_new['blue']=255; } elseif ($p_new['blue']<0) { $p_new['blue']=0; } |
4113
|
|
|
$color = imagecolorallocatealpha($image_dst, $p_new['red'], $p_new['green'], $p_new['blue'], $p_orig['alpha']); |
4114
|
|
|
imagesetpixel($image_dst, $x, $y, $color); |
4115
|
|
|
} |
4116
|
|
|
} |
4117
|
|
|
} |
4118
|
|
|
imagedestroy($canvas); |
4119
|
|
|
imagedestroy($blur); |
4120
|
|
|
} |
4121
|
|
|
} |
4122
|
|
|
|
4123
|
|
|
// add color overlay |
4124
|
|
|
if ($gd_version >= 2 && (is_numeric($this->image_overlay_opacity) && $this->image_overlay_opacity > 0 && !empty($this->image_overlay_color))) { |
4125
|
|
|
$this->log .= '- apply color overlay<br />'; |
4126
|
|
|
list($red, $green, $blue) = $this->getcolors($this->image_overlay_color); |
4127
|
|
|
$filter = imagecreatetruecolor($this->image_dst_x, $this->image_dst_y); |
4128
|
|
|
$color = imagecolorallocate($filter, $red, $green, $blue); |
4129
|
|
|
imagefilledrectangle($filter, 0, 0, $this->image_dst_x, $this->image_dst_y, $color); |
4130
|
|
|
$this->imagecopymergealpha($image_dst, $filter, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y, $this->image_overlay_opacity); |
4131
|
|
|
imagedestroy($filter); |
4132
|
|
|
} |
4133
|
|
|
|
4134
|
|
|
// add brightness, contrast and tint, turns to greyscale and inverts colors |
4135
|
|
|
if ($gd_version >= 2 && ($this->image_negative || $this->image_greyscale || is_numeric($this->image_threshold)|| is_numeric($this->image_brightness) || is_numeric($this->image_contrast) || !empty($this->image_tint_color))) { |
4136
|
|
|
$this->log .= '- apply tint, light, contrast correction, negative, greyscale and threshold<br />'; |
4137
|
|
|
if (!empty($this->image_tint_color)) list($tint_red, $tint_green, $tint_blue) = $this->getcolors($this->image_tint_color); |
4138
|
|
|
//imagealphablending($image_dst, true); |
4139
|
|
|
for($y=0; $y < $this->image_dst_y; $y++) { |
4140
|
|
|
for($x=0; $x < $this->image_dst_x; $x++) { |
4141
|
|
|
if ($this->image_greyscale) { |
4142
|
|
|
$pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); |
4143
|
|
|
$r = $g = $b = round((0.2125 * $pixel['red']) + (0.7154 * $pixel['green']) + (0.0721 * $pixel['blue'])); |
4144
|
|
|
$color = imagecolorallocatealpha($image_dst, $r, $g, $b, $pixel['alpha']); |
4145
|
|
|
imagesetpixel($image_dst, $x, $y, $color); |
4146
|
|
|
unset($color); unset($pixel); |
4147
|
|
|
} |
4148
|
|
|
if (is_numeric($this->image_threshold)) { |
4149
|
|
|
$pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); |
4150
|
|
|
$c = (round($pixel['red'] + $pixel['green'] + $pixel['blue']) / 3) - 127; |
4151
|
|
|
$r = $g = $b = ($c > $this->image_threshold ? 255 : 0); |
4152
|
|
|
$color = imagecolorallocatealpha($image_dst, $r, $g, $b, $pixel['alpha']); |
4153
|
|
|
imagesetpixel($image_dst, $x, $y, $color); |
4154
|
|
|
unset($color); unset($pixel); |
4155
|
|
|
} |
4156
|
|
|
if (is_numeric($this->image_brightness)) { |
4157
|
|
|
$pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); |
4158
|
|
|
$r = max(min(round($pixel['red'] + (($this->image_brightness * 2))), 255), 0); |
4159
|
|
|
$g = max(min(round($pixel['green'] + (($this->image_brightness * 2))), 255), 0); |
4160
|
|
|
$b = max(min(round($pixel['blue'] + (($this->image_brightness * 2))), 255), 0); |
4161
|
|
|
$color = imagecolorallocatealpha($image_dst, $r, $g, $b, $pixel['alpha']); |
4162
|
|
|
imagesetpixel($image_dst, $x, $y, $color); |
4163
|
|
|
unset($color); unset($pixel); |
4164
|
|
|
} |
4165
|
|
|
if (is_numeric($this->image_contrast)) { |
4166
|
|
|
$pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); |
4167
|
|
|
$r = max(min(round(($this->image_contrast + 128) * $pixel['red'] / 128), 255), 0); |
4168
|
|
|
$g = max(min(round(($this->image_contrast + 128) * $pixel['green'] / 128), 255), 0); |
4169
|
|
|
$b = max(min(round(($this->image_contrast + 128) * $pixel['blue'] / 128), 255), 0); |
4170
|
|
|
$color = imagecolorallocatealpha($image_dst, $r, $g, $b, $pixel['alpha']); |
4171
|
|
|
imagesetpixel($image_dst, $x, $y, $color); |
4172
|
|
|
unset($color); unset($pixel); |
4173
|
|
|
} |
4174
|
|
|
if (!empty($this->image_tint_color)) { |
4175
|
|
|
$pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); |
4176
|
|
|
$r = min(round($tint_red * $pixel['red'] / 169), 255); |
4177
|
|
|
$g = min(round($tint_green * $pixel['green'] / 169), 255); |
4178
|
|
|
$b = min(round($tint_blue * $pixel['blue'] / 169), 255); |
4179
|
|
|
$color = imagecolorallocatealpha($image_dst, $r, $g, $b, $pixel['alpha']); |
4180
|
|
|
imagesetpixel($image_dst, $x, $y, $color); |
4181
|
|
|
unset($color); unset($pixel); |
4182
|
|
|
} |
4183
|
|
|
if (!empty($this->image_negative)) { |
4184
|
|
|
$pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); |
4185
|
|
|
$r = round(255 - $pixel['red']); |
4186
|
|
|
$g = round(255 - $pixel['green']); |
4187
|
|
|
$b = round(255 - $pixel['blue']); |
4188
|
|
|
$color = imagecolorallocatealpha($image_dst, $r, $g, $b, $pixel['alpha']); |
4189
|
|
|
imagesetpixel($image_dst, $x, $y, $color); |
4190
|
|
|
unset($color); unset($pixel); |
4191
|
|
|
} |
4192
|
|
|
} |
4193
|
|
|
} |
4194
|
|
|
} |
4195
|
|
|
|
4196
|
|
|
// adds a border |
4197
|
|
|
if ($gd_version >= 2 && !empty($this->image_border)) { |
4198
|
|
|
list($ct, $cr, $cb, $cl) = $this->getoffsets($this->image_border, $this->image_dst_x, $this->image_dst_y, true, false); |
4199
|
|
|
$this->log .= '- add border : ' . $ct . ' ' . $cr . ' ' . $cb . ' ' . $cl . '<br />'; |
4200
|
|
|
$this->image_dst_x = $this->image_dst_x + $cl + $cr; |
|
|
|
|
4201
|
|
|
$this->image_dst_y = $this->image_dst_y + $ct + $cb; |
|
|
|
|
4202
|
|
|
if (!empty($this->image_border_color)) list($red, $green, $blue) = $this->getcolors($this->image_border_color); |
4203
|
|
|
$opacity = (is_numeric($this->image_border_opacity) ? (int) (127 - $this->image_border_opacity / 100 * 127): 0); |
4204
|
|
|
// we now create an image, that we fill with the border color |
4205
|
|
|
$tmp = $this->imagecreatenew($this->image_dst_x, $this->image_dst_y); |
4206
|
|
|
$background = imagecolorallocatealpha($tmp, $red, $green, $blue, $opacity); |
4207
|
|
|
imagefilledrectangle($tmp, 0, 0, $this->image_dst_x, $this->image_dst_y, $background); |
4208
|
|
|
// we then copy the source image into the new image, without merging so that only the border is actually kept |
4209
|
|
|
imagecopy($tmp, $image_dst, $cl, $ct, 0, 0, $this->image_dst_x - $cr - $cl, $this->image_dst_y - $cb - $ct); |
4210
|
|
|
// we transfert tmp into image_dst |
4211
|
|
|
$image_dst = $this->imagetransfer($tmp, $image_dst); |
4212
|
|
|
} |
4213
|
|
|
|
4214
|
|
|
// adds a fading-to-transparent border |
4215
|
|
|
if ($gd_version >= 2 && !empty($this->image_border_transparent)) { |
4216
|
|
|
list($ct, $cr, $cb, $cl) = $this->getoffsets($this->image_border_transparent, $this->image_dst_x, $this->image_dst_y, true, false); |
4217
|
|
|
$this->log .= '- add transparent border : ' . $ct . ' ' . $cr . ' ' . $cb . ' ' . $cl . '<br />'; |
4218
|
|
|
// we now create an image, that we fill with the border color |
4219
|
|
|
$tmp = $this->imagecreatenew($this->image_dst_x, $this->image_dst_y); |
4220
|
|
|
// we then copy the source image into the new image, without the borders |
4221
|
|
|
imagecopy($tmp, $image_dst, $cl, $ct, $cl, $ct, $this->image_dst_x - $cr - $cl, $this->image_dst_y - $cb - $ct); |
4222
|
|
|
// we now add the top border |
4223
|
|
|
$opacity = 100; |
4224
|
|
|
for ($y = $ct - 1; $y >= 0; $y--) { |
4225
|
|
|
$il = (int) ($ct > 0 ? ($cl * ($y / $ct)) : 0); |
4226
|
|
|
$ir = (int) ($ct > 0 ? ($cr * ($y / $ct)) : 0); |
4227
|
|
|
for ($x = $il; $x < $this->image_dst_x - $ir; $x++) { |
4228
|
|
|
$pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); |
4229
|
|
|
$alpha = (1 - ($pixel['alpha'] / 127)) * $opacity / 100; |
4230
|
|
|
if ($alpha > 0) { |
4231
|
|
|
if ($alpha > 1) $alpha = 1; |
4232
|
|
|
$color = imagecolorallocatealpha($tmp, $pixel['red'] , $pixel['green'], $pixel['blue'], round((1 - $alpha) * 127)); |
4233
|
|
|
imagesetpixel($tmp, $x, $y, $color); |
4234
|
|
|
} |
4235
|
|
|
} |
4236
|
|
|
if ($opacity > 0) $opacity = $opacity - (100 / $ct); |
4237
|
|
|
} |
4238
|
|
|
// we now add the right border |
4239
|
|
|
$opacity = 100; |
4240
|
|
|
for ($x = $this->image_dst_x - $cr; $x < $this->image_dst_x; $x++) { |
4241
|
|
|
$it = (int) ($cr > 0 ? ($ct * (($this->image_dst_x - $x - 1) / $cr)) : 0); |
4242
|
|
|
$ib = (int) ($cr > 0 ? ($cb * (($this->image_dst_x - $x - 1) / $cr)) : 0); |
4243
|
|
|
for ($y = $it; $y < $this->image_dst_y - $ib; $y++) { |
4244
|
|
|
$pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); |
4245
|
|
|
$alpha = (1 - ($pixel['alpha'] / 127)) * $opacity / 100; |
4246
|
|
|
if ($alpha > 0) { |
4247
|
|
|
if ($alpha > 1) $alpha = 1; |
4248
|
|
|
$color = imagecolorallocatealpha($tmp, $pixel['red'] , $pixel['green'], $pixel['blue'], round((1 - $alpha) * 127)); |
4249
|
|
|
imagesetpixel($tmp, $x, $y, $color); |
4250
|
|
|
} |
4251
|
|
|
} |
4252
|
|
|
if ($opacity > 0) $opacity = $opacity - (100 / $cr); |
4253
|
|
|
} |
4254
|
|
|
// we now add the bottom border |
4255
|
|
|
$opacity = 100; |
4256
|
|
|
for ($y = $this->image_dst_y - $cb; $y < $this->image_dst_y; $y++) { |
4257
|
|
|
$il = (int) ($cb > 0 ? ($cl * (($this->image_dst_y - $y - 1) / $cb)) : 0); |
4258
|
|
|
$ir = (int) ($cb > 0 ? ($cr * (($this->image_dst_y - $y - 1) / $cb)) : 0); |
4259
|
|
|
for ($x = $il; $x < $this->image_dst_x - $ir; $x++) { |
4260
|
|
|
$pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); |
4261
|
|
|
$alpha = (1 - ($pixel['alpha'] / 127)) * $opacity / 100; |
4262
|
|
|
if ($alpha > 0) { |
4263
|
|
|
if ($alpha > 1) $alpha = 1; |
4264
|
|
|
$color = imagecolorallocatealpha($tmp, $pixel['red'] , $pixel['green'], $pixel['blue'], round((1 - $alpha) * 127)); |
4265
|
|
|
imagesetpixel($tmp, $x, $y, $color); |
4266
|
|
|
} |
4267
|
|
|
} |
4268
|
|
|
if ($opacity > 0) $opacity = $opacity - (100 / $cb); |
4269
|
|
|
} |
4270
|
|
|
// we now add the left border |
4271
|
|
|
$opacity = 100; |
4272
|
|
|
for ($x = $cl - 1; $x >= 0; $x--) { |
4273
|
|
|
$it = (int) ($cl > 0 ? ($ct * ($x / $cl)) : 0); |
4274
|
|
|
$ib = (int) ($cl > 0 ? ($cb * ($x / $cl)) : 0); |
4275
|
|
|
for ($y = $it; $y < $this->image_dst_y - $ib; $y++) { |
4276
|
|
|
$pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); |
4277
|
|
|
$alpha = (1 - ($pixel['alpha'] / 127)) * $opacity / 100; |
4278
|
|
|
if ($alpha > 0) { |
4279
|
|
|
if ($alpha > 1) $alpha = 1; |
4280
|
|
|
$color = imagecolorallocatealpha($tmp, $pixel['red'] , $pixel['green'], $pixel['blue'], round((1 - $alpha) * 127)); |
4281
|
|
|
imagesetpixel($tmp, $x, $y, $color); |
4282
|
|
|
} |
4283
|
|
|
} |
4284
|
|
|
if ($opacity > 0) $opacity = $opacity - (100 / $cl); |
4285
|
|
|
} |
4286
|
|
|
// we transfert tmp into image_dst |
4287
|
|
|
$image_dst = $this->imagetransfer($tmp, $image_dst); |
4288
|
|
|
} |
4289
|
|
|
|
4290
|
|
|
// add frame border |
4291
|
|
|
if ($gd_version >= 2 && is_numeric($this->image_frame)) { |
4292
|
|
|
if (is_array($this->image_frame_colors)) { |
4293
|
|
|
$vars = $this->image_frame_colors; |
4294
|
|
|
$this->log .= '- add frame : ' . implode(' ', $this->image_frame_colors) . '<br />'; |
4295
|
|
|
} else { |
4296
|
|
|
$this->log .= '- add frame : ' . $this->image_frame_colors . '<br />'; |
4297
|
|
|
$vars = explode(' ', $this->image_frame_colors); |
4298
|
|
|
} |
4299
|
|
|
$nb = sizeof($vars); |
4300
|
|
|
$this->image_dst_x = $this->image_dst_x + ($nb * 2); |
|
|
|
|
4301
|
|
|
$this->image_dst_y = $this->image_dst_y + ($nb * 2); |
|
|
|
|
4302
|
|
|
$tmp = $this->imagecreatenew($this->image_dst_x, $this->image_dst_y); |
4303
|
|
|
imagecopy($tmp, $image_dst, $nb, $nb, 0, 0, $this->image_dst_x - ($nb * 2), $this->image_dst_y - ($nb * 2)); |
4304
|
|
|
$opacity = (is_numeric($this->image_frame_opacity) ? (int) (127 - $this->image_frame_opacity / 100 * 127): 0); |
4305
|
|
|
for ($i=0; $i<$nb; $i++) { |
4306
|
|
|
list($red, $green, $blue) = $this->getcolors($vars[$i]); |
4307
|
|
|
$c = imagecolorallocatealpha($tmp, $red, $green, $blue, $opacity); |
4308
|
|
|
if ($this->image_frame == 1) { |
4309
|
|
|
imageline($tmp, $i, $i, $this->image_dst_x - $i -1, $i, $c); |
4310
|
|
|
imageline($tmp, $this->image_dst_x - $i -1, $this->image_dst_y - $i -1, $this->image_dst_x - $i -1, $i, $c); |
4311
|
|
|
imageline($tmp, $this->image_dst_x - $i -1, $this->image_dst_y - $i -1, $i, $this->image_dst_y - $i -1, $c); |
4312
|
|
|
imageline($tmp, $i, $i, $i, $this->image_dst_y - $i -1, $c); |
4313
|
|
|
} else { |
4314
|
|
|
imageline($tmp, $i, $i, $this->image_dst_x - $i -1, $i, $c); |
4315
|
|
|
imageline($tmp, $this->image_dst_x - $nb + $i, $this->image_dst_y - $nb + $i, $this->image_dst_x - $nb + $i, $nb - $i, $c); |
4316
|
|
|
imageline($tmp, $this->image_dst_x - $nb + $i, $this->image_dst_y - $nb + $i, $nb - $i, $this->image_dst_y - $nb + $i, $c); |
4317
|
|
|
imageline($tmp, $i, $i, $i, $this->image_dst_y - $i -1, $c); |
4318
|
|
|
} |
4319
|
|
|
} |
4320
|
|
|
// we transfert tmp into image_dst |
4321
|
|
|
$image_dst = $this->imagetransfer($tmp, $image_dst); |
4322
|
|
|
} |
4323
|
|
|
|
4324
|
|
|
// add bevel border |
4325
|
|
|
if ($gd_version >= 2 && $this->image_bevel > 0) { |
4326
|
|
|
if (empty($this->image_bevel_color1)) $this->image_bevel_color1 = '#FFFFFF'; |
4327
|
|
|
if (empty($this->image_bevel_color2)) $this->image_bevel_color2 = '#000000'; |
4328
|
|
|
list($red1, $green1, $blue1) = $this->getcolors($this->image_bevel_color1); |
4329
|
|
|
list($red2, $green2, $blue2) = $this->getcolors($this->image_bevel_color2); |
4330
|
|
|
$tmp = $this->imagecreatenew($this->image_dst_x, $this->image_dst_y); |
4331
|
|
|
imagecopy($tmp, $image_dst, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y); |
4332
|
|
|
imagealphablending($tmp, true); |
4333
|
|
|
for ($i=0; $i<$this->image_bevel; $i++) { |
4334
|
|
|
$alpha = round(($i / $this->image_bevel) * 127); |
4335
|
|
|
$c1 = imagecolorallocatealpha($tmp, $red1, $green1, $blue1, $alpha); |
4336
|
|
|
$c2 = imagecolorallocatealpha($tmp, $red2, $green2, $blue2, $alpha); |
4337
|
|
|
imageline($tmp, $i, $i, $this->image_dst_x - $i -1, $i, $c1); |
4338
|
|
|
imageline($tmp, $this->image_dst_x - $i -1, $this->image_dst_y - $i, $this->image_dst_x - $i -1, $i, $c2); |
4339
|
|
|
imageline($tmp, $this->image_dst_x - $i -1, $this->image_dst_y - $i -1, $i, $this->image_dst_y - $i -1, $c2); |
4340
|
|
|
imageline($tmp, $i, $i, $i, $this->image_dst_y - $i -1, $c1); |
4341
|
|
|
} |
4342
|
|
|
// we transfert tmp into image_dst |
4343
|
|
|
$image_dst = $this->imagetransfer($tmp, $image_dst); |
4344
|
|
|
} |
4345
|
|
|
|
4346
|
|
|
// add watermark image |
4347
|
|
|
if ($this->image_watermark!='' && file_exists($this->image_watermark)) { |
4348
|
|
|
$this->log .= '- add watermark<br />'; |
4349
|
|
|
$this->image_watermark_position = strtolower($this->image_watermark_position); |
4350
|
|
|
$watermark_info = getimagesize($this->image_watermark); |
4351
|
|
|
$watermark_type = (array_key_exists(2, $watermark_info) ? $watermark_info[2] : null); // 1 = GIF, 2 = JPG, 3 = PNG |
4352
|
|
|
$watermark_checked = false; |
4353
|
|
|
if ($watermark_type == IMAGETYPE_GIF) { |
4354
|
|
|
if (!function_exists('imagecreatefromgif')) { |
4355
|
|
|
$this->error = $this->translate('watermark_no_create_support', array('GIF')); |
4356
|
|
|
} else { |
4357
|
|
|
$filter = @imagecreatefromgif($this->image_watermark); |
4358
|
|
|
if (!$filter) { |
4359
|
|
|
$this->error = $this->translate('watermark_create_error', array('GIF')); |
4360
|
|
|
} else { |
4361
|
|
|
$this->log .= ' watermark source image is GIF<br />'; |
4362
|
|
|
$watermark_checked = true; |
4363
|
|
|
} |
4364
|
|
|
} |
4365
|
|
|
} else if ($watermark_type == IMAGETYPE_JPEG) { |
4366
|
|
|
if (!function_exists('imagecreatefromjpeg')) { |
4367
|
|
|
$this->error = $this->translate('watermark_no_create_support', array('JPEG')); |
4368
|
|
|
} else { |
4369
|
|
|
$filter = @imagecreatefromjpeg($this->image_watermark); |
4370
|
|
|
if (!$filter) { |
4371
|
|
|
$this->error = $this->translate('watermark_create_error', array('JPEG')); |
4372
|
|
|
} else { |
4373
|
|
|
$this->log .= ' watermark source image is JPEG<br />'; |
4374
|
|
|
$watermark_checked = true; |
4375
|
|
|
} |
4376
|
|
|
} |
4377
|
|
|
} else if ($watermark_type == IMAGETYPE_PNG) { |
4378
|
|
|
if (!function_exists('imagecreatefrompng')) { |
4379
|
|
|
$this->error = $this->translate('watermark_no_create_support', array('PNG')); |
4380
|
|
|
} else { |
4381
|
|
|
$filter = @imagecreatefrompng($this->image_watermark); |
4382
|
|
|
if (!$filter) { |
4383
|
|
|
$this->error = $this->translate('watermark_create_error', array('PNG')); |
4384
|
|
|
} else { |
4385
|
|
|
$this->log .= ' watermark source image is PNG<br />'; |
4386
|
|
|
$watermark_checked = true; |
4387
|
|
|
} |
4388
|
|
|
} |
4389
|
|
|
} else if ($watermark_type == IMAGETYPE_BMP) { |
4390
|
|
|
if (!method_exists($this, 'imagecreatefrombmp')) { |
4391
|
|
|
$this->error = $this->translate('watermark_no_create_support', array('BMP')); |
4392
|
|
|
} else { |
4393
|
|
|
$filter = @$this->imagecreatefrombmp($this->image_watermark); |
4394
|
|
|
if (!$filter) { |
4395
|
|
|
$this->error = $this->translate('watermark_create_error', array('BMP')); |
4396
|
|
|
} else { |
4397
|
|
|
$this->log .= ' watermark source image is BMP<br />'; |
4398
|
|
|
$watermark_checked = true; |
4399
|
|
|
} |
4400
|
|
|
} |
4401
|
|
|
} else { |
4402
|
|
|
$this->error = $this->translate('watermark_invalid'); |
4403
|
|
|
} |
4404
|
|
|
if ($watermark_checked) { |
4405
|
|
|
$watermark_dst_width = $watermark_src_width = imagesx($filter); |
4406
|
|
|
$watermark_dst_height = $watermark_src_height = imagesy($filter); |
4407
|
|
|
|
4408
|
|
|
// if watermark is too large/tall, resize it first |
4409
|
|
|
if ((!$this->image_watermark_no_zoom_out && ($watermark_dst_width > $this->image_dst_x || $watermark_dst_height > $this->image_dst_y)) |
4410
|
|
|
|| (!$this->image_watermark_no_zoom_in && $watermark_dst_width < $this->image_dst_x && $watermark_dst_height < $this->image_dst_y)) { |
4411
|
|
|
$canvas_width = $this->image_dst_x - abs($this->image_watermark_x); |
4412
|
|
|
$canvas_height = $this->image_dst_y - abs($this->image_watermark_y); |
4413
|
|
|
if (($watermark_src_width/$canvas_width) > ($watermark_src_height/$canvas_height)) { |
4414
|
|
|
$watermark_dst_width = $canvas_width; |
4415
|
|
|
$watermark_dst_height = intval($watermark_src_height*($canvas_width / $watermark_src_width)); |
4416
|
|
|
} else { |
4417
|
|
|
$watermark_dst_height = $canvas_height; |
4418
|
|
|
$watermark_dst_width = intval($watermark_src_width*($canvas_height / $watermark_src_height)); |
4419
|
|
|
} |
4420
|
|
|
$this->log .= ' watermark resized from '.$watermark_src_width.'x'.$watermark_src_height.' to '.$watermark_dst_width.'x'.$watermark_dst_height.'<br />'; |
4421
|
|
|
|
4422
|
|
|
} |
4423
|
|
|
// determine watermark position |
4424
|
|
|
$watermark_x = 0; |
4425
|
|
|
$watermark_y = 0; |
4426
|
|
|
if (is_numeric($this->image_watermark_x)) { |
4427
|
|
|
if ($this->image_watermark_x < 0) { |
4428
|
|
|
$watermark_x = $this->image_dst_x - $watermark_dst_width + $this->image_watermark_x; |
4429
|
|
|
} else { |
4430
|
|
|
$watermark_x = $this->image_watermark_x; |
4431
|
|
|
} |
4432
|
|
|
} else { |
4433
|
|
|
if (strpos($this->image_watermark_position, 'r') !== false) { |
4434
|
|
|
$watermark_x = $this->image_dst_x - $watermark_dst_width; |
4435
|
|
|
} else if (strpos($this->image_watermark_position, 'l') !== false) { |
4436
|
|
|
$watermark_x = 0; |
4437
|
|
|
} else { |
4438
|
|
|
$watermark_x = ($this->image_dst_x - $watermark_dst_width) / 2; |
4439
|
|
|
} |
4440
|
|
|
} |
4441
|
|
|
if (is_numeric($this->image_watermark_y)) { |
4442
|
|
|
if ($this->image_watermark_y < 0) { |
4443
|
|
|
$watermark_y = $this->image_dst_y - $watermark_dst_height + $this->image_watermark_y; |
4444
|
|
|
} else { |
4445
|
|
|
$watermark_y = $this->image_watermark_y; |
4446
|
|
|
} |
4447
|
|
|
} else { |
4448
|
|
|
if (strpos($this->image_watermark_position, 'b') !== false) { |
4449
|
|
|
$watermark_y = $this->image_dst_y - $watermark_dst_height; |
4450
|
|
|
} else if (strpos($this->image_watermark_position, 't') !== false) { |
4451
|
|
|
$watermark_y = 0; |
4452
|
|
|
} else { |
4453
|
|
|
$watermark_y = ($this->image_dst_y - $watermark_dst_height) / 2; |
4454
|
|
|
} |
4455
|
|
|
} |
4456
|
|
|
imagealphablending($image_dst, true); |
4457
|
|
|
imagecopyresampled($image_dst, $filter, $watermark_x, $watermark_y, 0, 0, $watermark_dst_width, $watermark_dst_height, $watermark_src_width, $watermark_src_height); |
4458
|
|
|
} else { |
4459
|
|
|
$this->error = $this->translate('watermark_invalid'); |
4460
|
|
|
} |
4461
|
|
|
} |
4462
|
|
|
|
4463
|
|
|
// add text |
4464
|
|
|
if (!empty($this->image_text)) { |
4465
|
|
|
$this->log .= '- add text<br />'; |
4466
|
|
|
|
4467
|
|
|
// calculate sizes in human readable format |
4468
|
|
|
$src_size = $this->file_src_size / 1024; |
4469
|
|
|
$src_size_mb = number_format($src_size / 1024, 1, ".", " "); |
4470
|
|
|
$src_size_kb = number_format($src_size, 1, ".", " "); |
4471
|
|
|
$src_size_human = ($src_size > 1024 ? $src_size_mb . " MB" : $src_size_kb . " kb"); |
4472
|
|
|
|
4473
|
|
|
$this->image_text = str_replace( |
4474
|
|
|
array('[src_name]', |
4475
|
|
|
'[src_name_body]', |
4476
|
|
|
'[src_name_ext]', |
4477
|
|
|
'[src_pathname]', |
4478
|
|
|
'[src_mime]', |
4479
|
|
|
'[src_size]', |
4480
|
|
|
'[src_size_kb]', |
4481
|
|
|
'[src_size_mb]', |
4482
|
|
|
'[src_size_human]', |
4483
|
|
|
'[src_x]', |
4484
|
|
|
'[src_y]', |
4485
|
|
|
'[src_pixels]', |
4486
|
|
|
'[src_type]', |
4487
|
|
|
'[src_bits]', |
4488
|
|
|
'[dst_path]', |
4489
|
|
|
'[dst_name_body]', |
4490
|
|
|
'[dst_name_ext]', |
4491
|
|
|
'[dst_name]', |
4492
|
|
|
'[dst_pathname]', |
4493
|
|
|
'[dst_x]', |
4494
|
|
|
'[dst_y]', |
4495
|
|
|
'[date]', |
4496
|
|
|
'[time]', |
4497
|
|
|
'[host]', |
4498
|
|
|
'[server]', |
4499
|
|
|
'[ip]', |
4500
|
|
|
'[gd_version]'), |
4501
|
|
|
array($this->file_src_name, |
4502
|
|
|
$this->file_src_name_body, |
4503
|
|
|
$this->file_src_name_ext, |
4504
|
|
|
$this->file_src_pathname, |
4505
|
|
|
$this->file_src_mime, |
4506
|
|
|
$this->file_src_size, |
4507
|
|
|
$src_size_kb, |
4508
|
|
|
$src_size_mb, |
4509
|
|
|
$src_size_human, |
4510
|
|
|
$this->image_src_x, |
4511
|
|
|
$this->image_src_y, |
4512
|
|
|
$this->image_src_pixels, |
4513
|
|
|
$this->image_src_type, |
4514
|
|
|
$this->image_src_bits, |
4515
|
|
|
$this->file_dst_path, |
4516
|
|
|
$this->file_dst_name_body, |
4517
|
|
|
$this->file_dst_name_ext, |
4518
|
|
|
$this->file_dst_name, |
4519
|
|
|
$this->file_dst_pathname, |
4520
|
|
|
$this->image_dst_x, |
4521
|
|
|
$this->image_dst_y, |
4522
|
|
|
date('Y-m-d'), |
4523
|
|
|
date('H:i:s'), |
4524
|
|
|
(isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'n/a'), |
4525
|
|
|
(isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'n/a'), |
4526
|
|
|
(isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'n/a'), |
4527
|
|
|
$this->gdversion(true)), |
4528
|
|
|
$this->image_text); |
4529
|
|
|
|
4530
|
|
|
if (!is_numeric($this->image_text_padding)) $this->image_text_padding = 0; |
4531
|
|
|
if (!is_numeric($this->image_text_line_spacing)) $this->image_text_line_spacing = 0; |
4532
|
|
|
if (!is_numeric($this->image_text_padding_x)) $this->image_text_padding_x = $this->image_text_padding; |
|
|
|
|
4533
|
|
|
if (!is_numeric($this->image_text_padding_y)) $this->image_text_padding_y = $this->image_text_padding; |
|
|
|
|
4534
|
|
|
$this->image_text_position = strtolower($this->image_text_position); |
4535
|
|
|
$this->image_text_direction = strtolower($this->image_text_direction); |
4536
|
|
|
$this->image_text_alignment = strtolower($this->image_text_alignment); |
4537
|
|
|
|
4538
|
|
|
// if the font is a string, we assume that we might want to load a font |
4539
|
|
|
if (!is_numeric($this->image_text_font) && strlen($this->image_text_font) > 4 && substr(strtolower($this->image_text_font), -4) == '.gdf') { |
4540
|
|
|
$this->log .= ' try to load font ' . $this->image_text_font . '... '; |
4541
|
|
|
if ($this->image_text_font = @imageloadfont($this->image_text_font)) { |
4542
|
|
|
$this->log .= 'success<br />'; |
4543
|
|
|
} else { |
4544
|
|
|
$this->log .= 'error<br />'; |
4545
|
|
|
$this->image_text_font = 5; |
4546
|
|
|
} |
4547
|
|
|
} |
4548
|
|
|
|
4549
|
|
|
$text = explode("\n", $this->image_text); |
4550
|
|
|
$char_width = imagefontwidth($this->image_text_font); |
4551
|
|
|
$char_height = imagefontheight($this->image_text_font); |
4552
|
|
|
$text_height = 0; |
4553
|
|
|
$text_width = 0; |
4554
|
|
|
$line_height = 0; |
4555
|
|
|
$line_width = 0; |
4556
|
|
|
|
4557
|
|
|
foreach ($text as $k => $v) { |
4558
|
|
|
if ($this->image_text_direction == 'v') { |
4559
|
|
|
$h = ($char_width * strlen($v)); |
4560
|
|
|
if ($h > $text_height) $text_height = $h; |
4561
|
|
|
$line_width = $char_height; |
4562
|
|
|
$text_width += $line_width + ($k < (sizeof($text)-1) ? $this->image_text_line_spacing : 0); |
4563
|
|
|
} else { |
4564
|
|
|
$w = ($char_width * strlen($v)); |
4565
|
|
|
if ($w > $text_width) $text_width = $w; |
4566
|
|
|
$line_height = $char_height; |
4567
|
|
|
$text_height += $line_height + ($k < (sizeof($text)-1) ? $this->image_text_line_spacing : 0); |
4568
|
|
|
} |
4569
|
|
|
} |
4570
|
|
|
$text_width += (2 * $this->image_text_padding_x); |
4571
|
|
|
$text_height += (2 * $this->image_text_padding_y); |
4572
|
|
|
$text_x = 0; |
4573
|
|
|
$text_y = 0; |
4574
|
|
|
if (is_numeric($this->image_text_x)) { |
4575
|
|
|
if ($this->image_text_x < 0) { |
4576
|
|
|
$text_x = $this->image_dst_x - $text_width + $this->image_text_x; |
4577
|
|
|
} else { |
4578
|
|
|
$text_x = $this->image_text_x; |
4579
|
|
|
} |
4580
|
|
|
} else { |
4581
|
|
|
if (strpos($this->image_text_position, 'r') !== false) { |
4582
|
|
|
$text_x = $this->image_dst_x - $text_width; |
4583
|
|
|
} else if (strpos($this->image_text_position, 'l') !== false) { |
4584
|
|
|
$text_x = 0; |
4585
|
|
|
} else { |
4586
|
|
|
$text_x = ($this->image_dst_x - $text_width) / 2; |
4587
|
|
|
} |
4588
|
|
|
} |
4589
|
|
|
if (is_numeric($this->image_text_y)) { |
4590
|
|
|
if ($this->image_text_y < 0) { |
4591
|
|
|
$text_y = $this->image_dst_y - $text_height + $this->image_text_y; |
4592
|
|
|
} else { |
4593
|
|
|
$text_y = $this->image_text_y; |
4594
|
|
|
} |
4595
|
|
|
} else { |
4596
|
|
|
if (strpos($this->image_text_position, 'b') !== false) { |
4597
|
|
|
$text_y = $this->image_dst_y - $text_height; |
4598
|
|
|
} else if (strpos($this->image_text_position, 't') !== false) { |
4599
|
|
|
$text_y = 0; |
4600
|
|
|
} else { |
4601
|
|
|
$text_y = ($this->image_dst_y - $text_height) / 2; |
4602
|
|
|
} |
4603
|
|
|
} |
4604
|
|
|
|
4605
|
|
|
// add a background, maybe transparent |
4606
|
|
|
if (!empty($this->image_text_background)) { |
4607
|
|
|
list($red, $green, $blue) = $this->getcolors($this->image_text_background); |
4608
|
|
|
if ($gd_version >= 2 && (is_numeric($this->image_text_background_opacity)) && $this->image_text_background_opacity >= 0 && $this->image_text_background_opacity <= 100) { |
4609
|
|
|
$filter = imagecreatetruecolor($text_width, $text_height); |
4610
|
|
|
$background_color = imagecolorallocate($filter, $red, $green, $blue); |
4611
|
|
|
imagefilledrectangle($filter, 0, 0, $text_width, $text_height, $background_color); |
4612
|
|
|
$this->imagecopymergealpha($image_dst, $filter, $text_x, $text_y, 0, 0, $text_width, $text_height, $this->image_text_background_opacity); |
4613
|
|
|
imagedestroy($filter); |
4614
|
|
|
} else { |
4615
|
|
|
$background_color = imagecolorallocate($image_dst ,$red, $green, $blue); |
4616
|
|
|
imagefilledrectangle($image_dst, $text_x, $text_y, $text_x + $text_width, $text_y + $text_height, $background_color); |
4617
|
|
|
} |
4618
|
|
|
} |
4619
|
|
|
|
4620
|
|
|
$text_x += $this->image_text_padding_x; |
4621
|
|
|
$text_y += $this->image_text_padding_y; |
4622
|
|
|
$t_width = $text_width - (2 * $this->image_text_padding_x); |
4623
|
|
|
$t_height = $text_height - (2 * $this->image_text_padding_y); |
4624
|
|
|
list($red, $green, $blue) = $this->getcolors($this->image_text_color); |
4625
|
|
|
|
4626
|
|
|
// add the text, maybe transparent |
4627
|
|
|
if ($gd_version >= 2 && (is_numeric($this->image_text_opacity)) && $this->image_text_opacity >= 0 && $this->image_text_opacity <= 100) { |
4628
|
|
|
if ($t_width < 0) $t_width = 0; |
4629
|
|
|
if ($t_height < 0) $t_height = 0; |
4630
|
|
|
$filter = $this->imagecreatenew($t_width, $t_height, false, true); |
4631
|
|
|
$text_color = imagecolorallocate($filter ,$red, $green, $blue); |
4632
|
|
|
|
4633
|
|
|
foreach ($text as $k => $v) { |
4634
|
|
|
if ($this->image_text_direction == 'v') { |
4635
|
|
|
imagestringup($filter, |
4636
|
|
|
$this->image_text_font, |
4637
|
|
|
$k * ($line_width + ($k > 0 && $k < (sizeof($text)) ? $this->image_text_line_spacing : 0)), |
4638
|
|
|
$text_height - (2 * $this->image_text_padding_y) - ($this->image_text_alignment == 'l' ? 0 : (($t_height - strlen($v) * $char_width) / ($this->image_text_alignment == 'r' ? 1 : 2))) , |
4639
|
|
|
$v, |
4640
|
|
|
$text_color); |
4641
|
|
|
} else { |
4642
|
|
|
imagestring($filter, |
4643
|
|
|
$this->image_text_font, |
4644
|
|
|
($this->image_text_alignment == 'l' ? 0 : (($t_width - strlen($v) * $char_width) / ($this->image_text_alignment == 'r' ? 1 : 2))), |
4645
|
|
|
$k * ($line_height + ($k > 0 && $k < (sizeof($text)) ? $this->image_text_line_spacing : 0)), |
4646
|
|
|
$v, |
4647
|
|
|
$text_color); |
4648
|
|
|
} |
4649
|
|
|
} |
4650
|
|
|
$this->imagecopymergealpha($image_dst, $filter, $text_x, $text_y, 0, 0, $t_width, $t_height, $this->image_text_opacity); |
4651
|
|
|
imagedestroy($filter); |
4652
|
|
|
|
4653
|
|
|
} else { |
4654
|
|
|
$text_color = imageColorAllocate($image_dst ,$red, $green, $blue); |
4655
|
|
|
foreach ($text as $k => $v) { |
4656
|
|
|
if ($this->image_text_direction == 'v') { |
4657
|
|
|
imagestringup($image_dst, |
4658
|
|
|
$this->image_text_font, |
4659
|
|
|
$text_x + $k * ($line_width + ($k > 0 && $k < (sizeof($text)) ? $this->image_text_line_spacing : 0)), |
4660
|
|
|
$text_y + $text_height - (2 * $this->image_text_padding_y) - ($this->image_text_alignment == 'l' ? 0 : (($t_height - strlen($v) * $char_width) / ($this->image_text_alignment == 'r' ? 1 : 2))), |
4661
|
|
|
$v, |
4662
|
|
|
$text_color); |
4663
|
|
|
} else { |
4664
|
|
|
imagestring($image_dst, |
4665
|
|
|
$this->image_text_font, |
4666
|
|
|
$text_x + ($this->image_text_alignment == 'l' ? 0 : (($t_width - strlen($v) * $char_width) / ($this->image_text_alignment == 'r' ? 1 : 2))), |
4667
|
|
|
$text_y + $k * ($line_height + ($k > 0 && $k < (sizeof($text)) ? $this->image_text_line_spacing : 0)), |
4668
|
|
|
$v, |
4669
|
|
|
$text_color); |
4670
|
|
|
} |
4671
|
|
|
} |
4672
|
|
|
} |
4673
|
|
|
} |
4674
|
|
|
|
4675
|
|
|
// add a reflection |
4676
|
|
|
if ($this->image_reflection_height) { |
4677
|
|
|
$this->log .= '- add reflection : ' . $this->image_reflection_height . '<br />'; |
4678
|
|
|
// we decode image_reflection_height, which can be a integer, a string in pixels or percentage |
4679
|
|
|
$image_reflection_height = $this->image_reflection_height; |
4680
|
|
|
if (strpos($image_reflection_height, '%')>0) $image_reflection_height = $this->image_dst_y * (str_replace('%','',$image_reflection_height / 100)); |
4681
|
|
|
if (strpos($image_reflection_height, 'px')>0) $image_reflection_height = str_replace('px','',$image_reflection_height); |
4682
|
|
|
$image_reflection_height = (int) $image_reflection_height; |
4683
|
|
|
if ($image_reflection_height > $this->image_dst_y) $image_reflection_height = $this->image_dst_y; |
4684
|
|
|
if (empty($this->image_reflection_opacity)) $this->image_reflection_opacity = 60; |
4685
|
|
|
// create the new destination image |
4686
|
|
|
$tmp = $this->imagecreatenew($this->image_dst_x, $this->image_dst_y + $image_reflection_height + $this->image_reflection_space, true); |
4687
|
|
|
$transparency = $this->image_reflection_opacity; |
4688
|
|
|
|
4689
|
|
|
// copy the original image |
4690
|
|
|
imagecopy($tmp, $image_dst, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y + ($this->image_reflection_space < 0 ? $this->image_reflection_space : 0)); |
4691
|
|
|
|
4692
|
|
|
// we have to make sure the extra bit is the right color, or transparent |
4693
|
|
|
if ($image_reflection_height + $this->image_reflection_space > 0) { |
4694
|
|
|
// use the background color if present |
4695
|
|
|
if (!empty($this->image_background_color)) { |
4696
|
|
|
list($red, $green, $blue) = $this->getcolors($this->image_background_color); |
|
|
|
|
4697
|
|
|
$fill = imagecolorallocate($tmp, $red, $green, $blue); |
4698
|
|
|
} else { |
4699
|
|
|
$fill = imagecolorallocatealpha($tmp, 0, 0, 0, 127); |
4700
|
|
|
} |
4701
|
|
|
// fill in from the edge of the extra bit |
4702
|
|
|
imagefill($tmp, round($this->image_dst_x / 2), $this->image_dst_y + $image_reflection_height + $this->image_reflection_space - 1, $fill); |
4703
|
|
|
} |
4704
|
|
|
|
4705
|
|
|
// copy the reflection |
4706
|
|
|
for ($y = 0; $y < $image_reflection_height; $y++) { |
4707
|
|
|
for ($x = 0; $x < $this->image_dst_x; $x++) { |
4708
|
|
|
$pixel_b = imagecolorsforindex($tmp, imagecolorat($tmp, $x, $y + $this->image_dst_y + $this->image_reflection_space)); |
4709
|
|
|
$pixel_o = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $this->image_dst_y - $y - 1 + ($this->image_reflection_space < 0 ? $this->image_reflection_space : 0))); |
4710
|
|
|
$alpha_o = 1 - ($pixel_o['alpha'] / 127); |
4711
|
|
|
$alpha_b = 1 - ($pixel_b['alpha'] / 127); |
4712
|
|
|
$opacity = $alpha_o * $transparency / 100; |
4713
|
|
|
if ($opacity > 0) { |
4714
|
|
|
$red = round((($pixel_o['red'] * $opacity) + ($pixel_b['red'] ) * $alpha_b) / ($alpha_b + $opacity)); |
4715
|
|
|
$green = round((($pixel_o['green'] * $opacity) + ($pixel_b['green']) * $alpha_b) / ($alpha_b + $opacity)); |
4716
|
|
|
$blue = round((($pixel_o['blue'] * $opacity) + ($pixel_b['blue'] ) * $alpha_b) / ($alpha_b + $opacity)); |
4717
|
|
|
$alpha = ($opacity + $alpha_b); |
4718
|
|
|
if ($alpha > 1) $alpha = 1; |
4719
|
|
|
$alpha = round((1 - $alpha) * 127); |
4720
|
|
|
$color = imagecolorallocatealpha($tmp, $red, $green, $blue, $alpha); |
4721
|
|
|
imagesetpixel($tmp, $x, $y + $this->image_dst_y + $this->image_reflection_space, $color); |
4722
|
|
|
} |
4723
|
|
|
} |
4724
|
|
|
if ($transparency > 0) $transparency = $transparency - ($this->image_reflection_opacity / $image_reflection_height); |
4725
|
|
|
} |
4726
|
|
|
|
4727
|
|
|
// copy the resulting image into the destination image |
4728
|
|
|
$this->image_dst_y = $this->image_dst_y + $image_reflection_height + $this->image_reflection_space; |
|
|
|
|
4729
|
|
|
$image_dst = $this->imagetransfer($tmp, $image_dst); |
4730
|
|
|
} |
4731
|
|
|
|
4732
|
|
|
// change opacity |
4733
|
|
|
if ($gd_version >= 2 && is_numeric($this->image_opacity) && $this->image_opacity < 100) { |
4734
|
|
|
$this->log .= '- change opacity<br />'; |
4735
|
|
|
// create the new destination image |
4736
|
|
|
$tmp = $this->imagecreatenew($this->image_dst_x, $this->image_dst_y, true); |
4737
|
|
|
for($y=0; $y < $this->image_dst_y; $y++) { |
4738
|
|
|
for($x=0; $x < $this->image_dst_x; $x++) { |
4739
|
|
|
$pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); |
4740
|
|
|
$alpha = $pixel['alpha'] + round((127 - $pixel['alpha']) * (100 - $this->image_opacity) / 100); |
4741
|
|
|
if ($alpha > 127) $alpha = 127; |
4742
|
|
|
if ($alpha > 0) { |
4743
|
|
|
$color = imagecolorallocatealpha($tmp, $pixel['red'] , $pixel['green'], $pixel['blue'], $alpha); |
4744
|
|
|
imagesetpixel($tmp, $x, $y, $color); |
4745
|
|
|
} |
4746
|
|
|
} |
4747
|
|
|
} |
4748
|
|
|
// copy the resulting image into the destination image |
4749
|
|
|
$image_dst = $this->imagetransfer($tmp, $image_dst); |
4750
|
|
|
} |
4751
|
|
|
|
4752
|
|
|
// reduce the JPEG image to a set desired size |
4753
|
|
|
if (is_numeric($this->jpeg_size) && $this->jpeg_size > 0 && ($this->image_convert == 'jpeg' || $this->image_convert == 'jpg')) { |
4754
|
|
|
// inspired by: JPEGReducer class version 1, 25 November 2004, Author: Huda M ElMatsani, justhuda at netscape dot net |
4755
|
|
|
$this->log .= '- JPEG desired file size : ' . $this->jpeg_size . '<br />'; |
4756
|
|
|
// calculate size of each image. 75%, 50%, and 25% quality |
4757
|
|
|
ob_start(); imagejpeg($image_dst,'',75); $buffer = ob_get_contents(); ob_end_clean(); |
4758
|
|
|
$size75 = strlen($buffer); |
4759
|
|
|
ob_start(); imagejpeg($image_dst,'',50); $buffer = ob_get_contents(); ob_end_clean(); |
4760
|
|
|
$size50 = strlen($buffer); |
4761
|
|
|
ob_start(); imagejpeg($image_dst,'',25); $buffer = ob_get_contents(); ob_end_clean(); |
4762
|
|
|
$size25 = strlen($buffer); |
4763
|
|
|
|
4764
|
|
|
// make sure we won't divide by 0 |
4765
|
|
|
if ($size50 == $size25) $size50++; |
4766
|
|
|
if ($size75 == $size50 || $size75 == $size25) $size75++; |
4767
|
|
|
|
4768
|
|
|
// calculate gradient of size reduction by quality |
4769
|
|
|
$mgrad1 = 25 / ($size50-$size25); |
4770
|
|
|
$mgrad2 = 25 / ($size75-$size50); |
4771
|
|
|
$mgrad3 = 50 / ($size75-$size25); |
4772
|
|
|
$mgrad = ($mgrad1 + $mgrad2 + $mgrad3) / 3; |
4773
|
|
|
// result of approx. quality factor for expected size |
4774
|
|
|
$q_factor = round($mgrad * ($this->jpeg_size - $size50) + 50); |
4775
|
|
|
|
4776
|
|
|
if ($q_factor<1) { |
4777
|
|
|
$this->jpeg_quality=1; |
4778
|
|
|
} elseif ($q_factor>100) { |
4779
|
|
|
$this->jpeg_quality=100; |
4780
|
|
|
} else { |
4781
|
|
|
$this->jpeg_quality=$q_factor; |
|
|
|
|
4782
|
|
|
} |
4783
|
|
|
$this->log .= ' JPEG quality factor set to ' . $this->jpeg_quality . '<br />'; |
4784
|
|
|
} |
4785
|
|
|
|
4786
|
|
|
// converts image from true color, and fix transparency if needed |
4787
|
|
|
$this->log .= '- converting...<br />'; |
4788
|
|
|
switch($this->image_convert) { |
4789
|
|
|
case 'gif': |
4790
|
|
|
// if the image is true color, we convert it to a palette |
4791
|
|
|
if (imageistruecolor($image_dst)) { |
4792
|
|
|
$this->log .= ' true color to palette<br />'; |
4793
|
|
|
// creates a black and white mask |
4794
|
|
|
$mask = array(array()); |
4795
|
|
|
for ($x = 0; $x < $this->image_dst_x; $x++) { |
4796
|
|
|
for ($y = 0; $y < $this->image_dst_y; $y++) { |
4797
|
|
|
$pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); |
4798
|
|
|
$mask[$x][$y] = $pixel['alpha']; |
4799
|
|
|
} |
4800
|
|
|
} |
4801
|
|
|
list($red, $green, $blue) = $this->getcolors($this->image_default_color); |
|
|
|
|
4802
|
|
|
// first, we merge the image with the background color, so we know which colors we will have |
4803
|
|
|
for ($x = 0; $x < $this->image_dst_x; $x++) { |
4804
|
|
|
for ($y = 0; $y < $this->image_dst_y; $y++) { |
4805
|
|
|
if ($mask[$x][$y] > 0){ |
4806
|
|
|
// we have some transparency. we combine the color with the default color |
4807
|
|
|
$pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); |
4808
|
|
|
$alpha = ($mask[$x][$y] / 127); |
4809
|
|
|
$pixel['red'] = round(($pixel['red'] * (1 -$alpha) + $red * ($alpha))); |
4810
|
|
|
$pixel['green'] = round(($pixel['green'] * (1 -$alpha) + $green * ($alpha))); |
4811
|
|
|
$pixel['blue'] = round(($pixel['blue'] * (1 -$alpha) + $blue * ($alpha))); |
4812
|
|
|
$color = imagecolorallocate($image_dst, $pixel['red'], $pixel['green'], $pixel['blue']); |
4813
|
|
|
imagesetpixel($image_dst, $x, $y, $color); |
4814
|
|
|
} |
4815
|
|
|
} |
4816
|
|
|
} |
4817
|
|
|
// transforms the true color image into palette, with its merged default color |
4818
|
|
|
if (empty($this->image_background_color)) { |
4819
|
|
|
imagetruecolortopalette($image_dst, true, 255); |
4820
|
|
|
$transparency = imagecolorallocate($image_dst, 254, 1, 253); |
4821
|
|
|
imagecolortransparent($image_dst, $transparency); |
4822
|
|
|
// make the transparent areas transparent |
4823
|
|
|
for ($x = 0; $x < $this->image_dst_x; $x++) { |
4824
|
|
|
for ($y = 0; $y < $this->image_dst_y; $y++) { |
4825
|
|
|
// we test wether we have enough opacity to justify keeping the color |
4826
|
|
|
if ($mask[$x][$y] > 120) imagesetpixel($image_dst, $x, $y, $transparency); |
4827
|
|
|
} |
4828
|
|
|
} |
4829
|
|
|
} |
4830
|
|
|
unset($mask); |
4831
|
|
|
} |
4832
|
|
|
break; |
4833
|
|
|
case 'jpg': |
4834
|
|
|
case 'bmp': |
4835
|
|
|
// if the image doesn't support any transparency, then we merge it with the default color |
4836
|
|
|
$this->log .= ' fills in transparency with default color<br />'; |
4837
|
|
|
list($red, $green, $blue) = $this->getcolors($this->image_default_color); |
|
|
|
|
4838
|
|
|
$transparency = imagecolorallocate($image_dst, $red, $green, $blue); |
4839
|
|
|
// make the transaparent areas transparent |
4840
|
|
|
for ($x = 0; $x < $this->image_dst_x; $x++) { |
4841
|
|
|
for ($y = 0; $y < $this->image_dst_y; $y++) { |
4842
|
|
|
// we test wether we have some transparency, in which case we will merge the colors |
4843
|
|
|
if (imageistruecolor($image_dst)) { |
4844
|
|
|
$rgba = imagecolorat($image_dst, $x, $y); |
4845
|
|
|
$pixel = array('red' => ($rgba >> 16) & 0xFF, |
4846
|
|
|
'green' => ($rgba >> 8) & 0xFF, |
4847
|
|
|
'blue' => $rgba & 0xFF, |
4848
|
|
|
'alpha' => ($rgba & 0x7F000000) >> 24); |
4849
|
|
|
} else { |
4850
|
|
|
$pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y)); |
4851
|
|
|
} |
4852
|
|
|
if ($pixel['alpha'] == 127) { |
4853
|
|
|
// we have full transparency. we make the pixel transparent |
4854
|
|
|
imagesetpixel($image_dst, $x, $y, $transparency); |
4855
|
|
|
} else if ($pixel['alpha'] > 0) { |
4856
|
|
|
// we have some transparency. we combine the color with the default color |
4857
|
|
|
$alpha = ($pixel['alpha'] / 127); |
4858
|
|
|
$pixel['red'] = round(($pixel['red'] * (1 -$alpha) + $red * ($alpha))); |
4859
|
|
|
$pixel['green'] = round(($pixel['green'] * (1 -$alpha) + $green * ($alpha))); |
4860
|
|
|
$pixel['blue'] = round(($pixel['blue'] * (1 -$alpha) + $blue * ($alpha))); |
4861
|
|
|
$color = imagecolorclosest($image_dst, $pixel['red'], $pixel['green'], $pixel['blue']); |
4862
|
|
|
imagesetpixel($image_dst, $x, $y, $color); |
4863
|
|
|
} |
4864
|
|
|
} |
4865
|
|
|
} |
4866
|
|
|
|
4867
|
|
|
break; |
4868
|
|
|
default: |
4869
|
|
|
break; |
4870
|
|
|
} |
4871
|
|
|
|
4872
|
|
|
// outputs image |
4873
|
|
|
$this->log .= '- saving image...<br />'; |
4874
|
|
|
switch($this->image_convert) { |
4875
|
|
|
case 'jpeg': |
4876
|
|
|
case 'jpg': |
4877
|
|
|
if (!$return_mode) { |
4878
|
|
|
$result = @imagejpeg($image_dst, $this->file_dst_pathname, $this->jpeg_quality); |
4879
|
|
|
} else { |
4880
|
|
|
ob_start(); |
4881
|
|
|
$result = @imagejpeg($image_dst, '', $this->jpeg_quality); |
4882
|
|
|
$return_content = ob_get_contents(); |
4883
|
|
|
ob_end_clean(); |
4884
|
|
|
} |
4885
|
|
|
if (!$result) { |
4886
|
|
|
$this->processed = false; |
4887
|
|
|
$this->error = $this->translate('file_create', array('JPEG')); |
4888
|
|
|
} else { |
4889
|
|
|
$this->log .= ' JPEG image created<br />'; |
4890
|
|
|
} |
4891
|
|
|
break; |
4892
|
|
|
case 'png': |
4893
|
|
|
imagealphablending( $image_dst, false ); |
4894
|
|
|
imagesavealpha( $image_dst, true ); |
4895
|
|
|
if (!$return_mode) { |
4896
|
|
|
$result = @imagepng($image_dst, $this->file_dst_pathname); |
4897
|
|
|
} else { |
4898
|
|
|
ob_start(); |
4899
|
|
|
$result = @imagepng($image_dst); |
4900
|
|
|
$return_content = ob_get_contents(); |
4901
|
|
|
ob_end_clean(); |
4902
|
|
|
} |
4903
|
|
|
if (!$result) { |
4904
|
|
|
$this->processed = false; |
4905
|
|
|
$this->error = $this->translate('file_create', array('PNG')); |
4906
|
|
|
} else { |
4907
|
|
|
$this->log .= ' PNG image created<br />'; |
4908
|
|
|
} |
4909
|
|
|
break; |
4910
|
|
|
case 'gif': |
4911
|
|
|
if (!$return_mode) { |
4912
|
|
|
$result = @imagegif($image_dst, $this->file_dst_pathname); |
4913
|
|
|
} else { |
4914
|
|
|
ob_start(); |
4915
|
|
|
$result = @imagegif($image_dst); |
4916
|
|
|
$return_content = ob_get_contents(); |
4917
|
|
|
ob_end_clean(); |
4918
|
|
|
} |
4919
|
|
|
if (!$result) { |
4920
|
|
|
$this->processed = false; |
4921
|
|
|
$this->error = $this->translate('file_create', array('GIF')); |
4922
|
|
|
} else { |
4923
|
|
|
$this->log .= ' GIF image created<br />'; |
4924
|
|
|
} |
4925
|
|
|
break; |
4926
|
|
|
case 'bmp': |
4927
|
|
|
if (!$return_mode) { |
4928
|
|
|
$result = $this->imagebmp($image_dst, $this->file_dst_pathname); |
4929
|
|
|
} else { |
4930
|
|
|
ob_start(); |
4931
|
|
|
$result = $this->imagebmp($image_dst); |
4932
|
|
|
$return_content = ob_get_contents(); |
4933
|
|
|
ob_end_clean(); |
4934
|
|
|
} |
4935
|
|
|
if (!$result) { |
4936
|
|
|
$this->processed = false; |
4937
|
|
|
$this->error = $this->translate('file_create', array('BMP')); |
4938
|
|
|
} else { |
4939
|
|
|
$this->log .= ' BMP image created<br />'; |
4940
|
|
|
} |
4941
|
|
|
break; |
4942
|
|
|
|
4943
|
|
|
default: |
4944
|
|
|
$this->processed = false; |
4945
|
|
|
$this->error = $this->translate('no_conversion_type'); |
4946
|
|
|
} |
4947
|
|
|
if ($this->processed) { |
4948
|
|
|
if (is_resource($image_src)) imagedestroy($image_src); |
4949
|
|
|
if (is_resource($image_dst)) imagedestroy($image_dst); |
4950
|
|
|
$this->log .= ' image objects destroyed<br />'; |
4951
|
|
|
} |
4952
|
|
|
} |
4953
|
|
|
|
4954
|
|
|
} else { |
4955
|
|
|
$this->log .= '- no image processing wanted<br />'; |
4956
|
|
|
|
4957
|
|
|
if (!$return_mode) { |
4958
|
|
|
// copy the file to its final destination. we don't use move_uploaded_file here |
4959
|
|
|
// if we happen to have open_basedir restrictions, it is a temp file that we copy, not the original uploaded file |
4960
|
|
|
if (!copy($this->file_src_pathname, $this->file_dst_pathname)) { |
4961
|
|
|
$this->processed = false; |
4962
|
|
|
$this->error = $this->translate('copy_failed'); |
4963
|
|
|
} |
4964
|
|
|
} else { |
4965
|
|
|
// returns the file, so that its content can be received by the caller |
4966
|
|
|
$return_content = @file_get_contents($this->file_src_pathname); |
4967
|
|
|
if ($return_content === FALSE) { |
4968
|
|
|
$this->processed = false; |
4969
|
|
|
$this->error = $this->translate('reading_failed'); |
4970
|
|
|
} |
4971
|
|
|
} |
4972
|
|
|
} |
4973
|
|
|
} |
4974
|
|
|
|
4975
|
|
|
if ($this->processed) { |
4976
|
|
|
$this->log .= '- <b>process OK</b><br />'; |
4977
|
|
|
} else { |
4978
|
|
|
$this->log .= '- <b>error</b>: ' . $this->error . '<br />'; |
4979
|
|
|
} |
4980
|
|
|
|
4981
|
|
|
// we reinit all the vars |
4982
|
|
|
$this->init(); |
4983
|
|
|
|
4984
|
|
|
// we may return the image content |
4985
|
|
|
if ($return_mode) return $return_content; |
4986
|
|
|
|
4987
|
|
|
} |
4988
|
|
|
|
4989
|
|
|
/** |
4990
|
|
|
* Deletes the uploaded file from its temporary location |
4991
|
|
|
* |
4992
|
|
|
* When PHP uploads a file, it stores it in a temporary location. |
4993
|
|
|
* When you {@link process} the file, you actually copy the resulting file to the given location, it doesn't alter the original file. |
4994
|
|
|
* Once you have processed the file as many times as you wanted, you can delete the uploaded file. |
4995
|
|
|
* If there is open_basedir restrictions, the uploaded file is in fact a temporary file |
4996
|
|
|
* |
4997
|
|
|
* You might want not to use this function if you work on local files, as it will delete the source file |
4998
|
|
|
* |
4999
|
|
|
* @access public |
5000
|
|
|
*/ |
5001
|
|
|
function clean() { |
5002
|
|
|
$this->log .= '<b>cleanup</b><br />'; |
5003
|
|
|
$this->log .= '- delete temp file ' . $this->file_src_pathname . '<br />'; |
5004
|
|
|
@unlink($this->file_src_pathname); |
|
|
|
|
5005
|
|
|
} |
5006
|
|
|
|
5007
|
|
|
|
5008
|
|
|
/** |
5009
|
|
|
* Opens a BMP image |
5010
|
|
|
* |
5011
|
|
|
* This function has been written by DHKold, and is used with permission of the author |
5012
|
|
|
* |
5013
|
|
|
* @access public |
5014
|
|
|
*/ |
5015
|
|
|
function imagecreatefrombmp($filename) { |
5016
|
|
|
if (! $f1 = fopen($filename,"rb")) return false; |
5017
|
|
|
|
5018
|
|
|
$file = unpack("vfile_type/Vfile_size/Vreserved/Vbitmap_offset", fread($f1,14)); |
5019
|
|
|
if ($file['file_type'] != 19778) return false; |
5020
|
|
|
|
5021
|
|
|
$bmp = unpack('Vheader_size/Vwidth/Vheight/vplanes/vbits_per_pixel'. |
5022
|
|
|
'/Vcompression/Vsize_bitmap/Vhoriz_resolution'. |
5023
|
|
|
'/Vvert_resolution/Vcolors_used/Vcolors_important', fread($f1,40)); |
5024
|
|
|
$bmp['colors'] = pow(2,$bmp['bits_per_pixel']); |
5025
|
|
|
if ($bmp['size_bitmap'] == 0) $bmp['size_bitmap'] = $file['file_size'] - $file['bitmap_offset']; |
5026
|
|
|
$bmp['bytes_per_pixel'] = $bmp['bits_per_pixel']/8; |
5027
|
|
|
$bmp['bytes_per_pixel2'] = ceil($bmp['bytes_per_pixel']); |
5028
|
|
|
$bmp['decal'] = ($bmp['width']*$bmp['bytes_per_pixel']/4); |
5029
|
|
|
$bmp['decal'] -= floor($bmp['width']*$bmp['bytes_per_pixel']/4); |
5030
|
|
|
$bmp['decal'] = 4-(4*$bmp['decal']); |
5031
|
|
|
if ($bmp['decal'] == 4) $bmp['decal'] = 0; |
5032
|
|
|
|
5033
|
|
|
$palette = array(); |
5034
|
|
|
if ($bmp['colors'] < 16777216) { |
5035
|
|
|
$palette = unpack('V'.$bmp['colors'], fread($f1,$bmp['colors']*4)); |
5036
|
|
|
} |
5037
|
|
|
|
5038
|
|
|
$im = fread($f1,$bmp['size_bitmap']); |
5039
|
|
|
$vide = chr(0); |
5040
|
|
|
|
5041
|
|
|
$res = imagecreatetruecolor($bmp['width'],$bmp['height']); |
5042
|
|
|
$P = 0; |
5043
|
|
|
$Y = $bmp['height']-1; |
5044
|
|
|
while ($Y >= 0) { |
5045
|
|
|
$X=0; |
5046
|
|
|
while ($X < $bmp['width']) { |
5047
|
|
|
if ($bmp['bits_per_pixel'] == 24) |
5048
|
|
|
$color = unpack("V",substr($im,$P,3).$vide); |
5049
|
|
|
elseif ($bmp['bits_per_pixel'] == 16) { |
5050
|
|
|
$color = unpack("n",substr($im,$P,2)); |
5051
|
|
|
$color[1] = $palette[$color[1]+1]; |
5052
|
|
|
} elseif ($bmp['bits_per_pixel'] == 8) { |
5053
|
|
|
$color = unpack("n",$vide.substr($im,$P,1)); |
5054
|
|
|
$color[1] = $palette[$color[1]+1]; |
5055
|
|
|
} elseif ($bmp['bits_per_pixel'] == 4) { |
5056
|
|
|
$color = unpack("n",$vide.substr($im,floor($P),1)); |
5057
|
|
|
if (($P*2)%2 == 0) $color[1] = ($color[1] >> 4) ; else $color[1] = ($color[1] & 0x0F); |
5058
|
|
|
$color[1] = $palette[$color[1]+1]; |
5059
|
|
|
} elseif ($bmp['bits_per_pixel'] == 1) { |
5060
|
|
|
$color = unpack("n",$vide.substr($im,floor($P),1)); |
5061
|
|
|
if (($P*8)%8 == 0) $color[1] = $color[1] >>7; |
5062
|
|
|
elseif (($P*8)%8 == 1) $color[1] = ($color[1] & 0x40)>>6; |
5063
|
|
|
elseif (($P*8)%8 == 2) $color[1] = ($color[1] & 0x20)>>5; |
5064
|
|
|
elseif (($P*8)%8 == 3) $color[1] = ($color[1] & 0x10)>>4; |
5065
|
|
|
elseif (($P*8)%8 == 4) $color[1] = ($color[1] & 0x8)>>3; |
5066
|
|
|
elseif (($P*8)%8 == 5) $color[1] = ($color[1] & 0x4)>>2; |
5067
|
|
|
elseif (($P*8)%8 == 6) $color[1] = ($color[1] & 0x2)>>1; |
5068
|
|
|
elseif (($P*8)%8 == 7) $color[1] = ($color[1] & 0x1); |
5069
|
|
|
$color[1] = $palette[$color[1]+1]; |
5070
|
|
|
} else |
5071
|
|
|
return FALSE; |
5072
|
|
|
imagesetpixel($res,$X,$Y,$color[1]); |
5073
|
|
|
$X++; |
5074
|
|
|
$P += $bmp['bytes_per_pixel']; |
5075
|
|
|
} |
5076
|
|
|
$Y--; |
5077
|
|
|
$P+=$bmp['decal']; |
5078
|
|
|
} |
5079
|
|
|
fclose($f1); |
5080
|
|
|
return $res; |
5081
|
|
|
} |
5082
|
|
|
|
5083
|
|
|
/** |
5084
|
|
|
* Saves a BMP image |
5085
|
|
|
* |
5086
|
|
|
* This function has been published on the PHP website, and can be used freely |
5087
|
|
|
* |
5088
|
|
|
* @access public |
5089
|
|
|
*/ |
5090
|
|
|
function imagebmp(&$im, $filename = "") { |
5091
|
|
|
|
5092
|
|
|
if (!$im) return false; |
5093
|
|
|
$w = imagesx($im); |
5094
|
|
|
$h = imagesy($im); |
5095
|
|
|
$result = ''; |
5096
|
|
|
|
5097
|
|
|
// if the image is not true color, we convert it first |
5098
|
|
|
if (!imageistruecolor($im)) { |
5099
|
|
|
$tmp = imagecreatetruecolor($w, $h); |
5100
|
|
|
imagecopy($tmp, $im, 0, 0, 0, 0, $w, $h); |
5101
|
|
|
imagedestroy($im); |
5102
|
|
|
$im = & $tmp; |
5103
|
|
|
} |
5104
|
|
|
|
5105
|
|
|
$biBPLine = $w * 3; |
5106
|
|
|
$biStride = ($biBPLine + 3) & ~3; |
5107
|
|
|
$biSizeImage = $biStride * $h; |
5108
|
|
|
$bfOffBits = 54; |
5109
|
|
|
$bfSize = $bfOffBits + $biSizeImage; |
5110
|
|
|
|
5111
|
|
|
$result .= substr('BM', 0, 2); |
5112
|
|
|
$result .= pack ('VvvV', $bfSize, 0, 0, $bfOffBits); |
5113
|
|
|
$result .= pack ('VVVvvVVVVVV', 40, $w, $h, 1, 24, 0, $biSizeImage, 0, 0, 0, 0); |
5114
|
|
|
|
5115
|
|
|
$numpad = $biStride - $biBPLine; |
5116
|
|
|
for ($y = $h - 1; $y >= 0; --$y) { |
5117
|
|
|
for ($x = 0; $x < $w; ++$x) { |
5118
|
|
|
$col = imagecolorat ($im, $x, $y); |
5119
|
|
|
$result .= substr(pack ('V', $col), 0, 3); |
5120
|
|
|
} |
5121
|
|
|
for ($i = 0; $i < $numpad; ++$i) |
5122
|
|
|
$result .= pack ('C', 0); |
5123
|
|
|
} |
5124
|
|
|
|
5125
|
|
|
if($filename==""){ |
5126
|
|
|
echo $result; |
5127
|
|
|
} else { |
5128
|
|
|
$file = fopen($filename, "wb"); |
5129
|
|
|
fwrite($file, $result); |
5130
|
|
|
fclose($file); |
5131
|
|
|
} |
5132
|
|
|
return true; |
5133
|
|
|
} |
5134
|
|
|
} |
5135
|
|
|
|
5136
|
|
|
?> |
5137
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.