This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
||
3 | // GIF Util - (C) 2003 Yamasoft (S/C) |
||
4 | // http://www.yamasoft.com |
||
5 | // All Rights Reserved |
||
6 | // This file can be frelly copied, distributed, modified, updated by anyone under the only |
||
7 | // condition to leave the original address (Yamasoft, http://www.yamasoft.com) and this header. |
||
8 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
||
9 | // <gif> = gif_loadFile(filename, [index]) |
||
10 | // <bool> = gif_getSize(<gif> or filename, &width, &height) |
||
11 | // <bool> = gif_outputAsPng(<gif>, filename, [bgColor]) |
||
12 | // <bool> = gif_outputAsBmp(<gif>, filename, [bgcolor]) |
||
13 | // <bool> = gif_outputAsJpeg(<gif>, filename, [bgcolor]) - Requires cjpeg |
||
14 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
||
15 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
||
16 | if (!defined('XOOPS_ROOT_PATH')) { |
||
17 | die('XOOPS root path not defined'); |
||
18 | } |
||
19 | |||
20 | function gif_loadFile($lpszFileName, $iIndex = 0) |
||
21 | { |
||
22 | $gif = new CGIF(); |
||
23 | |||
24 | if(!$gif->loadFile($lpszFileName, $iIndex)) { |
||
25 | return false; |
||
26 | } |
||
27 | |||
28 | return $gif; |
||
29 | } |
||
30 | |||
31 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
||
32 | |||
33 | View Code Duplication | function gif_outputAsBmp($gif, $lpszFileName, $bgColor = -1) |
|
34 | { |
||
35 | if(!isSet($gif) || (@get_class($gif) <> 'cgif') || !$gif->loaded() || ($lpszFileName == '')) { |
||
36 | return false; |
||
37 | } |
||
38 | |||
39 | $fd = $gif->getBmp($bgColor); |
||
40 | if(strlen($fd) <= 0) { |
||
41 | return false; |
||
42 | } |
||
43 | |||
44 | if(!($fh = @fOpen($lpszFileName, 'wb'))) { |
||
45 | return false; |
||
46 | } |
||
47 | @fWrite($fh, $fd, strlen($fd)); |
||
0 ignored issues
–
show
|
|||
48 | @fFlush($fh); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
49 | @fClose($fh); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
50 | |||
51 | return true; |
||
52 | } |
||
53 | |||
54 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
||
55 | |||
56 | View Code Duplication | function gif_outputAsPng($gif, $lpszFileName, $bgColor = -1) |
|
57 | { |
||
58 | if(!isSet($gif) || (@get_class($gif) <> 'cgif') || !$gif->loaded() || ($lpszFileName == '')) { |
||
59 | return false; |
||
60 | } |
||
61 | |||
62 | $fd = $gif->getPng($bgColor); |
||
63 | if(strlen($fd) <= 0) { |
||
64 | return false; |
||
65 | } |
||
66 | |||
67 | if(!($fh = @fOpen($lpszFileName, 'wb'))) { |
||
68 | return false; |
||
69 | } |
||
70 | @fWrite($fh, $fd, strlen($fd)); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
71 | @fFlush($fh); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
72 | @fClose($fh); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
73 | |||
74 | return true; |
||
75 | } |
||
76 | |||
77 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
||
78 | |||
79 | function gif_outputAsJpeg($gif, $lpszFileName, $bgColor = -1) |
||
80 | { |
||
81 | if(gif_outputAsBmp($gif, "$lpszFileName.bmp", $gbColor)) { |
||
0 ignored issues
–
show
|
|||
82 | exec("cjpeg $lpszFileName.bmp >$lpszFileName 2>/dev/null"); |
||
83 | @unLink("$lpszFileName.bmp"); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
84 | |||
85 | if(@file_exists($lpszFileName)) { |
||
86 | if(@fileSize($lpszFileName) > 0) { |
||
87 | return true; |
||
88 | } |
||
89 | |||
90 | @unLink($lpszFileName); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
91 | } |
||
92 | } |
||
93 | |||
94 | return false; |
||
95 | } |
||
96 | |||
97 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
||
98 | |||
99 | function gif_getSize($gif, &$width, &$height) |
||
100 | { |
||
101 | if(isSet($gif) && (@get_class($gif) == 'cgif') && $gif->loaded()) { |
||
102 | $width = $gif->width(); |
||
103 | $height = $gif->height(); |
||
104 | } |
||
105 | else if(@file_exists($gif)) { |
||
106 | $myGIF = new CGIF(); |
||
107 | if(!$myGIF->getSize($gif, $width, $height)) { |
||
108 | return false; |
||
109 | } |
||
110 | } |
||
111 | else { |
||
112 | return false; |
||
113 | } |
||
114 | |||
115 | return true; |
||
116 | } |
||
117 | |||
118 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
||
119 | |||
120 | class CGIFLZW |
||
121 | { |
||
122 | var $MAX_LZW_BITS; |
||
123 | var $Fresh, $CodeSize, $SetCodeSize, $MaxCode, $MaxCodeSize, $FirstCode, $OldCode; |
||
124 | var $ClearCode, $EndCode, $Next, $Vals, $Stack, $sp, $Buf, $CurBit, $LastBit, $Done, $LastByte; |
||
125 | |||
126 | /////////////////////////////////////////////////////////////////////////// |
||
127 | |||
128 | // CONSTRUCTOR |
||
129 | function CGIFLZW() |
||
130 | { |
||
131 | $this->MAX_LZW_BITS = 12; |
||
132 | unSet($this->Next); |
||
133 | unSet($this->Vals); |
||
134 | unSet($this->Stack); |
||
135 | unSet($this->Buf); |
||
136 | |||
137 | $this->Next = range(0, (1 << $this->MAX_LZW_BITS) - 1); |
||
138 | $this->Vals = range(0, (1 << $this->MAX_LZW_BITS) - 1); |
||
139 | $this->Stack = range(0, (1 << ($this->MAX_LZW_BITS + 1)) - 1); |
||
140 | $this->Buf = range(0, 279); |
||
141 | } |
||
142 | |||
143 | /////////////////////////////////////////////////////////////////////////// |
||
144 | |||
145 | function deCompress($data, &$datLen) |
||
146 | { |
||
147 | $stLen = strlen($data); |
||
148 | $datLen = 0; |
||
149 | $ret = ''; |
||
150 | |||
151 | // INITIALIZATION |
||
152 | $this->LZWCommand($data, true); |
||
153 | |||
154 | while(($iIndex = $this->LZWCommand($data, false)) >= 0) { |
||
155 | $ret .= chr($iIndex); |
||
156 | } |
||
157 | |||
158 | $datLen = $stLen - strlen($data); |
||
159 | |||
160 | if($iIndex != -2) { |
||
161 | return false; |
||
162 | } |
||
163 | |||
164 | return $ret; |
||
165 | } |
||
166 | |||
167 | /////////////////////////////////////////////////////////////////////////// |
||
168 | |||
169 | function LZWCommand(&$data, $bInit) |
||
170 | { |
||
171 | if($bInit) { |
||
172 | $this->SetCodeSize = ord($data{0}); |
||
173 | $data = substr($data, 1); |
||
174 | |||
175 | $this->CodeSize = $this->SetCodeSize + 1; |
||
176 | $this->ClearCode = 1 << $this->SetCodeSize; |
||
177 | $this->EndCode = $this->ClearCode + 1; |
||
178 | $this->MaxCode = $this->ClearCode + 2; |
||
179 | $this->MaxCodeSize = $this->ClearCode << 1; |
||
180 | |||
181 | $this->GetCode($data, $bInit); |
||
182 | |||
183 | $this->Fresh = 1; |
||
184 | View Code Duplication | for($i = 0; $i < $this->ClearCode; $i++) { |
|
185 | $this->Next[$i] = 0; |
||
186 | $this->Vals[$i] = $i; |
||
187 | } |
||
188 | |||
189 | View Code Duplication | for(; $i < (1 << $this->MAX_LZW_BITS); $i++) { |
|
190 | $this->Next[$i] = 0; |
||
191 | $this->Vals[$i] = 0; |
||
192 | } |
||
193 | |||
194 | $this->sp = 0; |
||
195 | |||
196 | return 1; |
||
197 | } |
||
198 | |||
199 | if($this->Fresh) { |
||
200 | $this->Fresh = 0; |
||
201 | do { |
||
202 | $this->FirstCode = $this->GetCode($data, $bInit); |
||
203 | $this->OldCode = $this->FirstCode; |
||
204 | } |
||
205 | while($this->FirstCode == $this->ClearCode); |
||
206 | |||
207 | return $this->FirstCode; |
||
208 | } |
||
209 | |||
210 | if($this->sp > 0) { |
||
211 | $this->sp--; |
||
212 | |||
213 | return $this->Stack[$this->sp]; |
||
214 | } |
||
215 | |||
216 | while(($Code = $this->GetCode($data, $bInit)) >= 0) { |
||
217 | if($Code == $this->ClearCode) { |
||
218 | View Code Duplication | for($i = 0; $i < $this->ClearCode; $i++) { |
|
219 | $this->Next[$i] = 0; |
||
220 | $this->Vals[$i] = $i; |
||
221 | } |
||
222 | |||
223 | View Code Duplication | for(; $i < (1 << $this->MAX_LZW_BITS); $i++) { |
|
224 | $this->Next[$i] = 0; |
||
225 | $this->Vals[$i] = 0; |
||
226 | } |
||
227 | |||
228 | $this->CodeSize = $this->SetCodeSize + 1; |
||
229 | $this->MaxCodeSize = $this->ClearCode << 1; |
||
230 | $this->MaxCode = $this->ClearCode + 2; |
||
231 | $this->sp = 0; |
||
232 | $this->FirstCode = $this->GetCode($data, $bInit); |
||
233 | $this->OldCode = $this->FirstCode; |
||
234 | |||
235 | return $this->FirstCode; |
||
236 | } |
||
237 | |||
238 | if($Code == $this->EndCode) { |
||
239 | return -2; |
||
240 | } |
||
241 | |||
242 | $InCode = $Code; |
||
243 | if($Code >= $this->MaxCode) { |
||
244 | $this->Stack[$this->sp] = $this->FirstCode; |
||
245 | $this->sp++; |
||
246 | $Code = $this->OldCode; |
||
247 | } |
||
248 | |||
249 | while($Code >= $this->ClearCode) { |
||
250 | $this->Stack[$this->sp] = $this->Vals[$Code]; |
||
251 | $this->sp++; |
||
252 | |||
253 | if($Code == $this->Next[$Code]) // Circular table entry, big GIF Error! |
||
254 | return -1; |
||
255 | |||
256 | $Code = $this->Next[$Code]; |
||
257 | } |
||
258 | |||
259 | $this->FirstCode = $this->Vals[$Code]; |
||
260 | $this->Stack[$this->sp] = $this->FirstCode; |
||
261 | $this->sp++; |
||
262 | |||
263 | if(($Code = $this->MaxCode) < (1 << $this->MAX_LZW_BITS)) { |
||
264 | $this->Next[$Code] = $this->OldCode; |
||
265 | $this->Vals[$Code] = $this->FirstCode; |
||
266 | $this->MaxCode++; |
||
267 | |||
268 | if(($this->MaxCode >= $this->MaxCodeSize) && ($this->MaxCodeSize < (1 << $this->MAX_LZW_BITS))) { |
||
269 | $this->MaxCodeSize *= 2; |
||
270 | $this->CodeSize++; |
||
271 | } |
||
272 | } |
||
273 | |||
274 | $this->OldCode = $InCode; |
||
275 | if($this->sp > 0) { |
||
276 | $this->sp--; |
||
277 | |||
278 | return $this->Stack[$this->sp]; |
||
279 | } |
||
280 | } |
||
281 | |||
282 | return $Code; |
||
283 | } |
||
284 | |||
285 | /////////////////////////////////////////////////////////////////////////// |
||
286 | |||
287 | function GetCode(&$data, $bInit) |
||
288 | { |
||
289 | if($bInit) { |
||
290 | $this->CurBit = 0; |
||
291 | $this->LastBit = 0; |
||
292 | $this->Done = 0; |
||
293 | $this->LastByte = 2; |
||
294 | |||
295 | return 1; |
||
296 | } |
||
297 | |||
298 | if(($this->CurBit + $this->CodeSize) >= $this->LastBit) { |
||
299 | if($this->Done) { |
||
300 | if($this->CurBit >= $this->LastBit) { |
||
301 | // Ran off the end of my bits |
||
302 | return 0; |
||
303 | } |
||
304 | |||
305 | return -1; |
||
306 | } |
||
307 | |||
308 | $this->Buf[0] = $this->Buf[$this->LastByte - 2]; |
||
309 | $this->Buf[1] = $this->Buf[$this->LastByte - 1]; |
||
310 | |||
311 | $Count = ord($data{0}); |
||
312 | $data = substr($data, 1); |
||
313 | |||
314 | if($Count) { |
||
315 | for($i = 0; $i < $Count; $i++) { |
||
316 | $this->Buf[2 + $i] = ord($data{$i}); |
||
317 | } |
||
318 | $data = substr($data, $Count); |
||
319 | } |
||
320 | else { |
||
321 | $this->Done = 1; |
||
322 | } |
||
323 | |||
324 | $this->LastByte = 2 + $Count; |
||
325 | $this->CurBit = ($this->CurBit - $this->LastBit) + 16; |
||
326 | $this->LastBit = (2 + $Count) << 3; |
||
327 | } |
||
328 | |||
329 | $iRet = 0; |
||
330 | for($i = $this->CurBit, $j = 0; $j < $this->CodeSize; $i++, $j++) { |
||
331 | $iRet |= (($this->Buf[intval($i / 8)] & (1 << ($i % 8))) != 0) << $j; |
||
332 | } |
||
333 | |||
334 | $this->CurBit += $this->CodeSize; |
||
335 | |||
336 | return $iRet; |
||
337 | } |
||
338 | } |
||
339 | |||
340 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
||
341 | |||
342 | class CGIFCOLORTABLE |
||
343 | { |
||
344 | var $m_nColors; |
||
345 | var $m_arColors; |
||
346 | |||
347 | /////////////////////////////////////////////////////////////////////////// |
||
348 | |||
349 | // CONSTRUCTOR |
||
350 | function CGIFCOLORTABLE() |
||
351 | { |
||
352 | unSet($this->m_nColors); |
||
353 | unSet($this->m_arColors); |
||
354 | } |
||
355 | |||
356 | /////////////////////////////////////////////////////////////////////////// |
||
357 | |||
358 | function load($lpData, $num) |
||
359 | { |
||
360 | $this->m_nColors = 0; |
||
361 | $this->m_arColors = array(); |
||
362 | |||
363 | for($i = 0; $i < $num; $i++) { |
||
364 | $rgb = substr($lpData, $i * 3, 3); |
||
365 | if(strlen($rgb) < 3) { |
||
366 | return false; |
||
367 | } |
||
368 | |||
369 | $this->m_arColors[] = (ord($rgb{2}) << 16) + (ord($rgb{1}) << 8) + ord($rgb{0}); |
||
370 | $this->m_nColors++; |
||
371 | } |
||
372 | |||
373 | return true; |
||
374 | } |
||
375 | |||
376 | /////////////////////////////////////////////////////////////////////////// |
||
377 | |||
378 | View Code Duplication | function toString() |
|
379 | { |
||
380 | $ret = ''; |
||
381 | |||
382 | for($i = 0; $i < $this->m_nColors; $i++) { |
||
383 | $ret .= |
||
384 | chr($this->m_arColors[$i] & 0x000000FF) . // R |
||
385 | chr(($this->m_arColors[$i] & 0x0000FF00) >> 8) . // G |
||
386 | chr(($this->m_arColors[$i] & 0x00FF0000) >> 16); // B |
||
387 | } |
||
388 | |||
389 | return $ret; |
||
390 | } |
||
391 | |||
392 | /////////////////////////////////////////////////////////////////////////// |
||
393 | |||
394 | View Code Duplication | function toRGBQuad() |
|
395 | { |
||
396 | $ret = ''; |
||
397 | |||
398 | for($i = 0; $i < $this->m_nColors; $i++) { |
||
399 | $ret .= |
||
400 | chr(($this->m_arColors[$i] & 0x00FF0000) >> 16) . // B |
||
401 | chr(($this->m_arColors[$i] & 0x0000FF00) >> 8) . // G |
||
402 | chr($this->m_arColors[$i] & 0x000000FF) . // R |
||
403 | "\x00"; |
||
404 | } |
||
405 | |||
406 | return $ret; |
||
407 | } |
||
408 | |||
409 | /////////////////////////////////////////////////////////////////////////// |
||
410 | |||
411 | function colorIndex($rgb) |
||
412 | { |
||
413 | $rgb = intval($rgb) & 0xFFFFFF; |
||
414 | $r1 = ($rgb & 0x0000FF); |
||
415 | $g1 = ($rgb & 0x00FF00) >> 8; |
||
416 | $b1 = ($rgb & 0xFF0000) >> 16; |
||
417 | $idx = -1; |
||
418 | |||
419 | for($i = 0; $i < $this->m_nColors; $i++) { |
||
420 | $r2 = ($this->m_arColors[$i] & 0x000000FF); |
||
421 | $g2 = ($this->m_arColors[$i] & 0x0000FF00) >> 8; |
||
422 | $b2 = ($this->m_arColors[$i] & 0x00FF0000) >> 16; |
||
423 | $d = abs($r2 - $r1) + abs($g2 - $g1) + abs($b2 - $b1); |
||
424 | |||
425 | if(($idx == -1) || ($d < $dif)) { |
||
0 ignored issues
–
show
The variable
$dif does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
|||
426 | $idx = $i; |
||
427 | $dif = $d; |
||
428 | } |
||
429 | } |
||
430 | |||
431 | return $idx; |
||
432 | } |
||
433 | } |
||
434 | |||
435 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
||
436 | |||
437 | class CGIFFILEHEADER |
||
438 | { |
||
439 | var $m_lpVer; |
||
440 | var $m_nWidth; |
||
441 | var $m_nHeight; |
||
442 | var $m_bGlobalClr; |
||
443 | var $m_nColorRes; |
||
444 | var $m_bSorted; |
||
445 | var $m_nTableSize; |
||
446 | var $m_nBgColor; |
||
447 | var $m_nPixelRatio; |
||
448 | var $m_colorTable; |
||
449 | |||
450 | /////////////////////////////////////////////////////////////////////////// |
||
451 | |||
452 | // CONSTRUCTOR |
||
453 | function CGIFFILEHEADER() |
||
454 | { |
||
455 | unSet($this->m_lpVer); |
||
456 | unSet($this->m_nWidth); |
||
457 | unSet($this->m_nHeight); |
||
458 | unSet($this->m_bGlobalClr); |
||
459 | unSet($this->m_nColorRes); |
||
460 | unSet($this->m_bSorted); |
||
461 | unSet($this->m_nTableSize); |
||
462 | unSet($this->m_nBgColor); |
||
463 | unSet($this->m_nPixelRatio); |
||
464 | unSet($this->m_colorTable); |
||
465 | } |
||
466 | |||
467 | /////////////////////////////////////////////////////////////////////////// |
||
468 | |||
469 | function load($lpData, &$hdrLen) |
||
470 | { |
||
471 | $hdrLen = 0; |
||
472 | |||
473 | $this->m_lpVer = substr($lpData, 0, 6); |
||
474 | if(($this->m_lpVer <> 'GIF87a') && ($this->m_lpVer <> 'GIF89a')) { |
||
475 | return false; |
||
476 | } |
||
477 | |||
478 | $this->m_nWidth = $this->w2i(substr($lpData, 6, 2)); |
||
479 | $this->m_nHeight = $this->w2i(substr($lpData, 8, 2)); |
||
480 | if(!$this->m_nWidth || !$this->m_nHeight) { |
||
481 | return false; |
||
482 | } |
||
483 | |||
484 | $b = ord(substr($lpData, 10, 1)); |
||
485 | $this->m_bGlobalClr = ($b & 0x80) ? true : false; |
||
486 | $this->m_nColorRes = ($b & 0x70) >> 4; |
||
487 | $this->m_bSorted = ($b & 0x08) ? true : false; |
||
488 | $this->m_nTableSize = 2 << ($b & 0x07); |
||
489 | $this->m_nBgColor = ord(substr($lpData, 11, 1)); |
||
490 | $this->m_nPixelRatio = ord(substr($lpData, 12, 1)); |
||
491 | $hdrLen = 13; |
||
492 | |||
493 | View Code Duplication | if($this->m_bGlobalClr) { |
|
494 | $this->m_colorTable = new CGIFCOLORTABLE(); |
||
495 | if(!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize)) { |
||
496 | return false; |
||
497 | } |
||
498 | $hdrLen += 3 * $this->m_nTableSize; |
||
499 | } |
||
500 | |||
501 | return true; |
||
502 | } |
||
503 | |||
504 | /////////////////////////////////////////////////////////////////////////// |
||
505 | |||
506 | function w2i($str) |
||
507 | { |
||
508 | return ord(substr($str, 0, 1)) + (ord(substr($str, 1, 1)) << 8); |
||
509 | } |
||
510 | } |
||
511 | |||
512 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
||
513 | |||
514 | class CGIFIMAGEHEADER |
||
515 | { |
||
516 | var $m_nLeft; |
||
517 | var $m_nTop; |
||
518 | var $m_nWidth; |
||
519 | var $m_nHeight; |
||
520 | var $m_bLocalClr; |
||
521 | var $m_bInterlace; |
||
522 | var $m_bSorted; |
||
523 | var $m_nTableSize; |
||
524 | var $m_colorTable; |
||
525 | |||
526 | /////////////////////////////////////////////////////////////////////////// |
||
527 | |||
528 | // CONSTRUCTOR |
||
529 | function CGIFIMAGEHEADER() |
||
530 | { |
||
531 | unSet($this->m_nLeft); |
||
532 | unSet($this->m_nTop); |
||
533 | unSet($this->m_nWidth); |
||
534 | unSet($this->m_nHeight); |
||
535 | unSet($this->m_bLocalClr); |
||
536 | unSet($this->m_bInterlace); |
||
537 | unSet($this->m_bSorted); |
||
538 | unSet($this->m_nTableSize); |
||
539 | unSet($this->m_colorTable); |
||
540 | } |
||
541 | |||
542 | /////////////////////////////////////////////////////////////////////////// |
||
543 | |||
544 | function load($lpData, &$hdrLen) |
||
545 | { |
||
546 | $hdrLen = 0; |
||
547 | |||
548 | $this->m_nLeft = $this->w2i(substr($lpData, 0, 2)); |
||
549 | $this->m_nTop = $this->w2i(substr($lpData, 2, 2)); |
||
550 | $this->m_nWidth = $this->w2i(substr($lpData, 4, 2)); |
||
551 | $this->m_nHeight = $this->w2i(substr($lpData, 6, 2)); |
||
552 | |||
553 | if(!$this->m_nWidth || !$this->m_nHeight) { |
||
554 | return false; |
||
555 | } |
||
556 | |||
557 | $b = ord($lpData{8}); |
||
558 | $this->m_bLocalClr = ($b & 0x80) ? true : false; |
||
559 | $this->m_bInterlace = ($b & 0x40) ? true : false; |
||
560 | $this->m_bSorted = ($b & 0x20) ? true : false; |
||
561 | $this->m_nTableSize = 2 << ($b & 0x07); |
||
562 | $hdrLen = 9; |
||
563 | |||
564 | View Code Duplication | if($this->m_bLocalClr) { |
|
565 | $this->m_colorTable = new CGIFCOLORTABLE(); |
||
566 | if(!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize)) { |
||
567 | return false; |
||
568 | } |
||
569 | $hdrLen += 3 * $this->m_nTableSize; |
||
570 | } |
||
571 | |||
572 | return true; |
||
573 | } |
||
574 | |||
575 | /////////////////////////////////////////////////////////////////////////// |
||
576 | |||
577 | function w2i($str) |
||
578 | { |
||
579 | return ord(substr($str, 0, 1)) + (ord(substr($str, 1, 1)) << 8); |
||
580 | } |
||
581 | } |
||
582 | |||
583 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
||
584 | |||
585 | class CGIFIMAGE |
||
586 | { |
||
587 | var $m_disp; |
||
588 | var $m_bUser; |
||
589 | var $m_bTrans; |
||
590 | var $m_nDelay; |
||
591 | var $m_nTrans; |
||
592 | var $m_lpComm; |
||
593 | var $m_gih; |
||
594 | var $m_data; |
||
595 | var $m_lzw; |
||
596 | |||
597 | /////////////////////////////////////////////////////////////////////////// |
||
598 | |||
599 | function CGIFIMAGE() |
||
600 | { |
||
601 | unSet($this->m_disp); |
||
602 | unSet($this->m_bUser); |
||
603 | unSet($this->m_bTrans); |
||
604 | unSet($this->m_nDelay); |
||
605 | unSet($this->m_nTrans); |
||
606 | unSet($this->m_lpComm); |
||
607 | unSet($this->m_data); |
||
608 | $this->m_gih = new CGIFIMAGEHEADER(); |
||
609 | $this->m_lzw = new CGIFLZW(); |
||
610 | } |
||
611 | |||
612 | /////////////////////////////////////////////////////////////////////////// |
||
613 | |||
614 | function load($data, &$datLen) |
||
615 | { |
||
616 | $datLen = 0; |
||
617 | |||
618 | while(true) { |
||
619 | $b = ord($data{0}); |
||
620 | $data = substr($data, 1); |
||
621 | $datLen++; |
||
622 | |||
623 | switch($b) { |
||
624 | case 0x21: // Extension |
||
625 | if(!$this->skipExt($data, $len = 0)) { |
||
626 | return false; |
||
627 | } |
||
628 | $datLen += $len; |
||
629 | break; |
||
630 | |||
631 | case 0x2C: // Image |
||
632 | // LOAD HEADER & COLOR TABLE |
||
633 | if(!$this->m_gih->load($data, $len = 0)) { |
||
634 | return false; |
||
635 | } |
||
636 | $data = substr($data, $len); |
||
637 | $datLen += $len; |
||
638 | |||
639 | // ALLOC BUFFER |
||
640 | if(!($this->m_data = $this->m_lzw->deCompress($data, $len = 0))) { |
||
641 | return false; |
||
642 | } |
||
643 | $data = substr($data, $len); |
||
0 ignored issues
–
show
$data is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
644 | $datLen += $len; |
||
645 | |||
646 | if($this->m_gih->m_bInterlace) { |
||
647 | $this->deInterlace(); |
||
648 | } |
||
649 | |||
650 | return true; |
||
651 | |||
652 | case 0x3B: // EOF |
||
653 | default: |
||
654 | return false; |
||
655 | } |
||
656 | } |
||
657 | |||
658 | return false; |
||
659 | } |
||
660 | |||
661 | /////////////////////////////////////////////////////////////////////////// |
||
662 | |||
663 | function skipExt(&$data, &$extLen) |
||
664 | { |
||
665 | $extLen = 0; |
||
666 | |||
667 | $b = ord($data{0}); |
||
668 | $data = substr($data, 1); |
||
669 | $extLen++; |
||
670 | |||
671 | switch($b) { |
||
672 | case 0xF9: // Graphic Control |
||
673 | $b = ord($data{1}); |
||
674 | $this->m_disp = ($b & 0x1C) >> 2; |
||
675 | $this->m_bUser = ($b & 0x02) ? true : false; |
||
676 | $this->m_bTrans = ($b & 0x01) ? true : false; |
||
677 | $this->m_nDelay = $this->w2i(substr($data, 2, 2)); |
||
678 | $this->m_nTrans = ord($data{4}); |
||
679 | break; |
||
680 | |||
681 | case 0xFE: // Comment |
||
682 | $this->m_lpComm = substr($data, 1, ord($data{0})); |
||
683 | break; |
||
684 | |||
685 | case 0x01: // Plain text |
||
686 | break; |
||
687 | |||
688 | case 0xFF: // Application |
||
689 | break; |
||
690 | } |
||
691 | |||
692 | // SKIP DEFAULT AS DEFS MAY CHANGE |
||
693 | $b = ord($data{0}); |
||
694 | $data = substr($data, 1); |
||
695 | $extLen++; |
||
696 | while($b > 0) { |
||
697 | $data = substr($data, $b); |
||
698 | $extLen += $b; |
||
699 | $b = ord($data{0}); |
||
700 | $data = substr($data, 1); |
||
701 | $extLen++; |
||
702 | } |
||
703 | |||
704 | return true; |
||
705 | } |
||
706 | |||
707 | /////////////////////////////////////////////////////////////////////////// |
||
708 | |||
709 | function w2i($str) |
||
710 | { |
||
711 | return ord(substr($str, 0, 1)) + (ord(substr($str, 1, 1)) << 8); |
||
712 | } |
||
713 | |||
714 | /////////////////////////////////////////////////////////////////////////// |
||
715 | |||
716 | function deInterlace() |
||
717 | { |
||
718 | $data = $this->m_data; |
||
719 | |||
720 | for($i = 0; $i < 4; $i++) { |
||
721 | switch($i) { |
||
722 | case 0: |
||
723 | $s = 8; |
||
724 | $y = 0; |
||
725 | break; |
||
726 | |||
727 | case 1: |
||
728 | $s = 8; |
||
729 | $y = 4; |
||
730 | break; |
||
731 | |||
732 | case 2: |
||
733 | $s = 4; |
||
734 | $y = 2; |
||
735 | break; |
||
736 | |||
737 | case 3: |
||
738 | $s = 2; |
||
739 | $y = 1; |
||
740 | break; |
||
741 | } |
||
742 | |||
743 | for(; $y < $this->m_gih->m_nHeight; $y += $s) { |
||
0 ignored issues
–
show
The variable
$y does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() The variable
$s does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
|||
744 | $lne = substr($this->m_data, 0, $this->m_gih->m_nWidth); |
||
745 | $this->m_data = substr($this->m_data, $this->m_gih->m_nWidth); |
||
746 | |||
747 | $data = |
||
748 | substr($data, 0, $y * $this->m_gih->m_nWidth) . |
||
749 | $lne . |
||
750 | substr($data, ($y + 1) * $this->m_gih->m_nWidth); |
||
751 | } |
||
752 | } |
||
753 | |||
754 | $this->m_data = $data; |
||
755 | } |
||
756 | } |
||
757 | |||
758 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
||
759 | |||
760 | class CGIF |
||
761 | { |
||
762 | var $m_gfh; |
||
763 | var $m_lpData; |
||
764 | var $m_img; |
||
765 | var $m_bLoaded; |
||
766 | |||
767 | /////////////////////////////////////////////////////////////////////////// |
||
768 | |||
769 | // CONSTRUCTOR |
||
770 | function CGIF() |
||
771 | { |
||
772 | $this->m_gfh = new CGIFFILEHEADER(); |
||
773 | $this->m_img = new CGIFIMAGE(); |
||
774 | $this->m_lpData = ''; |
||
775 | $this->m_bLoaded = false; |
||
776 | } |
||
777 | |||
778 | /////////////////////////////////////////////////////////////////////////// |
||
779 | |||
780 | function loadFile($lpszFileName, $iIndex) |
||
781 | { |
||
782 | if($iIndex < 0) { |
||
783 | return false; |
||
784 | } |
||
785 | |||
786 | // READ FILE |
||
787 | if(!($fh = @fOpen($lpszFileName, 'rb'))) { |
||
788 | // return false; |
||
789 | } |
||
790 | //for local Gif's |
||
791 | // $this->m_lpData = @fRead($fh, @fileSize($lpszFileName)); |
||
792 | //for remote Gif's |
||
793 | while(!feof($fh)) { |
||
794 | $this->m_lpData = $this->m_lpData . fread($fh, 1024); |
||
795 | //$this->m_lpData = @fRead($fh, @fileSize($lpszFileName)); |
||
796 | } |
||
797 | fClose($fh); |
||
798 | // GET FILE HEADER |
||
799 | if(!$this->m_gfh->load($this->m_lpData, $len = 0)) { |
||
800 | return false; |
||
801 | } |
||
802 | $this->m_lpData = substr($this->m_lpData, $len); |
||
803 | |||
804 | do { |
||
805 | if(!$this->m_img->load($this->m_lpData, $imgLen = 0)) { |
||
806 | return false; |
||
807 | } |
||
808 | $this->m_lpData = substr($this->m_lpData, $imgLen); |
||
809 | } |
||
810 | while($iIndex-- > 0); |
||
811 | |||
812 | $this->m_bLoaded = true; |
||
813 | |||
814 | return true; |
||
815 | } |
||
816 | |||
817 | /////////////////////////////////////////////////////////////////////////// |
||
818 | |||
819 | function getSize($lpszFileName, &$width, &$height) |
||
820 | { |
||
821 | if(!($fh = @fOpen($lpszFileName, 'rb'))) { |
||
822 | return false; |
||
823 | } |
||
824 | $data = @fRead($fh, @fileSize($lpszFileName)); |
||
825 | @fClose($fh); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
826 | |||
827 | $gfh = new CGIFFILEHEADER(); |
||
828 | if(!$gfh->load($data, $len = 0)) { |
||
829 | return false; |
||
830 | } |
||
831 | |||
832 | $width = $gfh->m_nWidth; |
||
833 | $height = $gfh->m_nHeight; |
||
834 | |||
835 | return true; |
||
836 | } |
||
837 | |||
838 | /////////////////////////////////////////////////////////////////////////// |
||
839 | |||
840 | function getBmp($bgColor) |
||
841 | { |
||
842 | $out = ''; |
||
843 | |||
844 | if(!$this->m_bLoaded) { |
||
845 | return false; |
||
846 | } |
||
847 | |||
848 | // PREPARE COLOR TABLE (RGBQUADs) |
||
849 | View Code Duplication | if($this->m_img->m_gih->m_bLocalClr) { |
|
850 | $nColors = $this->m_img->m_gih->m_nTableSize; |
||
851 | $rgbq = $this->m_img->m_gih->m_colorTable->toRGBQuad(); |
||
852 | if($bgColor != -1) { |
||
853 | $bgColor = $this->m_img->m_gih->m_colorTable->colorIndex($bgColor); |
||
854 | } |
||
855 | } |
||
856 | else if($this->m_gfh->m_bGlobalClr) { |
||
857 | $nColors = $this->m_gfh->m_nTableSize; |
||
858 | $rgbq = $this->m_gfh->m_colorTable->toRGBQuad(); |
||
859 | if($bgColor != -1) { |
||
860 | $bgColor = $this->m_gfh->m_colorTable->colorIndex($bgColor); |
||
861 | } |
||
862 | } |
||
863 | else { |
||
864 | $nColors = 0; |
||
865 | $bgColor = -1; |
||
866 | } |
||
867 | |||
868 | // PREPARE BITMAP BITS |
||
869 | $data = $this->m_img->m_data; |
||
870 | $nPxl = ($this->m_gfh->m_nHeight - 1) * $this->m_gfh->m_nWidth; |
||
871 | $bmp = ''; |
||
872 | $nPad = ($this->m_gfh->m_nWidth % 4) ? 4 - ($this->m_gfh->m_nWidth % 4) : 0; |
||
873 | for($y = 0; $y < $this->m_gfh->m_nHeight; $y++) { |
||
874 | for($x = 0; $x < $this->m_gfh->m_nWidth; $x++, $nPxl++) { |
||
875 | if( |
||
876 | ($x >= $this->m_img->m_gih->m_nLeft) && |
||
877 | ($y >= $this->m_img->m_gih->m_nTop) && |
||
878 | ($x < ($this->m_img->m_gih->m_nLeft + $this->m_img->m_gih->m_nWidth)) && |
||
879 | ($y < ($this->m_img->m_gih->m_nTop + $this->m_img->m_gih->m_nHeight))) { |
||
880 | // PART OF IMAGE |
||
881 | if($this->m_img->m_bTrans && (ord($data{$nPxl}) == $this->m_img->m_nTrans)) { |
||
882 | // TRANSPARENT -> BACKGROUND |
||
883 | View Code Duplication | if($bgColor == -1) { |
|
884 | $bmp .= chr($this->m_gfh->m_nBgColor); |
||
885 | } |
||
886 | else { |
||
887 | $bmp .= chr($bgColor); |
||
888 | } |
||
889 | } |
||
890 | else { |
||
891 | $bmp .= $data{$nPxl}; |
||
892 | } |
||
893 | } |
||
894 | View Code Duplication | else { |
|
895 | // BACKGROUND |
||
896 | if($bgColor == -1) { |
||
897 | $bmp .= chr($this->m_gfh->m_nBgColor); |
||
898 | } |
||
899 | else { |
||
900 | $bmp .= chr($bgColor); |
||
901 | } |
||
902 | } |
||
903 | } |
||
904 | $nPxl -= $this->m_gfh->m_nWidth << 1; |
||
905 | |||
906 | // ADD PADDING |
||
907 | for($x = 0; $x < $nPad; $x++) { |
||
908 | $bmp .= "\x00"; |
||
909 | } |
||
910 | } |
||
911 | |||
912 | // BITMAPFILEHEADER |
||
913 | $out .= 'BM'; |
||
914 | $out .= $this->dword(14 + 40 + ($nColors << 2) + strlen($bmp)); |
||
915 | $out .= "\x00\x00"; |
||
916 | $out .= "\x00\x00"; |
||
917 | $out .= $this->dword(14 + 40 + ($nColors << 2)); |
||
918 | |||
919 | // BITMAPINFOHEADER |
||
920 | $out .= $this->dword(40); |
||
921 | $out .= $this->dword($this->m_gfh->m_nWidth); |
||
922 | $out .= $this->dword($this->m_gfh->m_nHeight); |
||
923 | $out .= "\x01\x00"; |
||
924 | $out .= "\x08\x00"; |
||
925 | $out .= "\x00\x00\x00\x00"; |
||
926 | $out .= "\x00\x00\x00\x00"; |
||
927 | $out .= "\x12\x0B\x00\x00"; |
||
928 | $out .= "\x12\x0B\x00\x00"; |
||
929 | $out .= $this->dword($nColors % 256); |
||
930 | $out .= "\x00\x00\x00\x00"; |
||
931 | |||
932 | // COLOR TABLE |
||
933 | if($nColors > 0) { |
||
934 | $out .= $rgbq; |
||
0 ignored issues
–
show
The variable
$rgbq does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
|||
935 | } |
||
936 | |||
937 | // DATA |
||
938 | $out .= $bmp; |
||
939 | |||
940 | return $out; |
||
941 | } |
||
942 | |||
943 | /////////////////////////////////////////////////////////////////////////// |
||
944 | |||
945 | function getPng($bgColor) |
||
946 | { |
||
947 | $out = ''; |
||
948 | |||
949 | if(!$this->m_bLoaded) { |
||
950 | return false; |
||
951 | } |
||
952 | |||
953 | // PREPARE COLOR TABLE (RGBQUADs) |
||
954 | View Code Duplication | if($this->m_img->m_gih->m_bLocalClr) { |
|
955 | $nColors = $this->m_img->m_gih->m_nTableSize; |
||
956 | $pal = $this->m_img->m_gih->m_colorTable->toString(); |
||
957 | if($bgColor != -1) { |
||
958 | $bgColor = $this->m_img->m_gih->m_colorTable->colorIndex($bgColor); |
||
959 | } |
||
960 | } |
||
961 | else if($this->m_gfh->m_bGlobalClr) { |
||
962 | $nColors = $this->m_gfh->m_nTableSize; |
||
963 | $pal = $this->m_gfh->m_colorTable->toString(); |
||
964 | if($bgColor != -1) { |
||
965 | $bgColor = $this->m_gfh->m_colorTable->colorIndex($bgColor); |
||
966 | } |
||
967 | } |
||
968 | else { |
||
969 | $nColors = 0; |
||
970 | $bgColor = -1; |
||
971 | } |
||
972 | |||
973 | // PREPARE BITMAP BITS |
||
974 | $data = $this->m_img->m_data; |
||
975 | $nPxl = 0; |
||
976 | $bmp = ''; |
||
977 | for($y = 0; $y < $this->m_gfh->m_nHeight; $y++) { |
||
978 | $bmp .= "\x00"; |
||
979 | for($x = 0; $x < $this->m_gfh->m_nWidth; $x++, $nPxl++) { |
||
980 | if( |
||
981 | ($x >= $this->m_img->m_gih->m_nLeft) && |
||
982 | ($y >= $this->m_img->m_gih->m_nTop) && |
||
983 | ($x < ($this->m_img->m_gih->m_nLeft + $this->m_img->m_gih->m_nWidth)) && |
||
984 | ($y < ($this->m_img->m_gih->m_nTop + $this->m_img->m_gih->m_nHeight))) { |
||
985 | // PART OF IMAGE |
||
986 | $bmp .= $data{$nPxl}; |
||
987 | } |
||
988 | View Code Duplication | else { |
|
989 | // BACKGROUND |
||
990 | if($bgColor == -1) { |
||
991 | $bmp .= chr($this->m_gfh->m_nBgColor); |
||
992 | } |
||
993 | else { |
||
994 | $bmp .= chr($bgColor); |
||
995 | } |
||
996 | } |
||
997 | } |
||
998 | } |
||
999 | $bmp = gzcompress($bmp, 9); |
||
1000 | |||
1001 | /////////////////////////////////////////////////////////////////////// |
||
1002 | // SIGNATURE |
||
1003 | $out .= "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A"; |
||
1004 | /////////////////////////////////////////////////////////////////////// |
||
1005 | // HEADER |
||
1006 | $out .= "\x00\x00\x00\x0D"; |
||
1007 | $tmp = 'IHDR'; |
||
1008 | $tmp .= $this->ndword($this->m_gfh->m_nWidth); |
||
1009 | $tmp .= $this->ndword($this->m_gfh->m_nHeight); |
||
1010 | $tmp .= "\x08\x03\x00\x00\x00"; |
||
1011 | $out .= $tmp; |
||
1012 | $out .= $this->ndword(crc32($tmp)); |
||
1013 | /////////////////////////////////////////////////////////////////////// |
||
1014 | // PALETTE |
||
1015 | if($nColors > 0) { |
||
1016 | $out .= $this->ndword($nColors * 3); |
||
1017 | $tmp = 'PLTE'; |
||
1018 | $tmp .= $pal; |
||
0 ignored issues
–
show
The variable
$pal does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
|||
1019 | $out .= $tmp; |
||
1020 | $out .= $this->ndword(crc32($tmp)); |
||
1021 | } |
||
1022 | /////////////////////////////////////////////////////////////////////// |
||
1023 | // TRANSPARENCY |
||
1024 | if($this->m_img->m_bTrans && ($nColors > 0)) { |
||
1025 | $out .= $this->ndword($nColors); |
||
1026 | $tmp = 'tRNS'; |
||
1027 | for($i = 0; $i < $nColors; $i++) { |
||
1028 | $tmp .= ($i == $this->m_img->m_nTrans) ? "\x00" : "\xFF"; |
||
1029 | } |
||
1030 | $out .= $tmp; |
||
1031 | $out .= $this->ndword(crc32($tmp)); |
||
1032 | } |
||
1033 | /////////////////////////////////////////////////////////////////////// |
||
1034 | // DATA BITS |
||
1035 | $out .= $this->ndword(strlen($bmp)); |
||
1036 | $tmp = 'IDAT'; |
||
1037 | $tmp .= $bmp; |
||
1038 | $out .= $tmp; |
||
1039 | $out .= $this->ndword(crc32($tmp)); |
||
1040 | /////////////////////////////////////////////////////////////////////// |
||
1041 | // END OF FILE |
||
1042 | $out .= "\x00\x00\x00\x00IEND\xAE\x42\x60\x82"; |
||
1043 | |||
1044 | return $out; |
||
1045 | } |
||
1046 | |||
1047 | /////////////////////////////////////////////////////////////////////////// |
||
1048 | |||
1049 | function dword($val) |
||
1050 | { |
||
1051 | $val = intval($val); |
||
1052 | |||
1053 | return chr($val & 0xFF).chr(($val & 0xFF00) >> 8).chr(($val & 0xFF0000) >> 16).chr(($val & 0xFF000000) >> 24); |
||
1054 | } |
||
1055 | |||
1056 | /////////////////////////////////////////////////////////////////////////// |
||
1057 | |||
1058 | function ndword($val) |
||
1059 | { |
||
1060 | $val = intval($val); |
||
1061 | |||
1062 | return chr(($val & 0xFF000000) >> 24).chr(($val & 0xFF0000) >> 16).chr(($val & 0xFF00) >> 8).chr($val & 0xFF); |
||
1063 | } |
||
1064 | |||
1065 | /////////////////////////////////////////////////////////////////////////// |
||
1066 | |||
1067 | function width() |
||
1068 | { |
||
1069 | return $this->m_gfh->m_nWidth; |
||
1070 | } |
||
1071 | |||
1072 | /////////////////////////////////////////////////////////////////////////// |
||
1073 | |||
1074 | function height() |
||
1075 | { |
||
1076 | return $this->m_gfh->m_nHeight; |
||
1077 | } |
||
1078 | |||
1079 | /////////////////////////////////////////////////////////////////////////// |
||
1080 | |||
1081 | function comment() |
||
1082 | { |
||
1083 | return $this->m_img->m_lpComm; |
||
1084 | } |
||
1085 | |||
1086 | /////////////////////////////////////////////////////////////////////////// |
||
1087 | |||
1088 | function loaded() |
||
1089 | { |
||
1090 | return $this->m_bLoaded; |
||
1091 | } |
||
1092 | } |
||
1093 | |||
1094 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
||
1095 | |||
1096 |
If you suppress an error, we recommend checking for the error condition explicitly: