Conditions | 14 |
Paths | 728 |
Total Lines | 101 |
Code Lines | 70 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
14 | public function GD2ICOstring(&$gd_image_array) |
||
15 | { |
||
16 | $ImageWidths = []; |
||
17 | $ImageHeights = []; |
||
18 | $bpp = []; |
||
19 | $totalcolors = []; |
||
20 | $icXOR = []; |
||
21 | $icAND = []; |
||
22 | $icANDmask = []; |
||
23 | foreach ($gd_image_array as $key => $gd_image) { |
||
24 | $ImageWidths[$key] = imagesx($gd_image); |
||
25 | $ImageHeights[$key] = imagesy($gd_image); |
||
26 | $bpp[$key] = imageistruecolor($gd_image) ? 32 : 24; |
||
27 | $totalcolors[$key] = imagecolorstotal($gd_image); |
||
28 | |||
29 | $icXOR[$key] = ''; |
||
30 | for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) { |
||
31 | for ($x = 0; $x < $ImageWidths[$key]; $x++) { |
||
32 | $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y); |
||
33 | $a = round(255 * ((127 - $argb['alpha']) / 127)); |
||
34 | $r = $argb['red']; |
||
35 | $g = $argb['green']; |
||
36 | $b = $argb['blue']; |
||
37 | |||
38 | if ($bpp[$key] == 32) { |
||
39 | $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
||
|
|||
40 | } elseif ($bpp[$key] == 24) { |
||
41 | $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
||
42 | } |
||
43 | |||
44 | if ($a < 128) { |
||
45 | @$icANDmask[$key][$y] .= '1'; |
||
46 | } else { |
||
47 | @$icANDmask[$key][$y] .= '0'; |
||
48 | } |
||
49 | } |
||
50 | // mask bits are 32-bit aligned per scanline |
||
51 | while (strlen($icANDmask[$key][$y]) % 32) { |
||
52 | $icANDmask[$key][$y] .= '0'; |
||
53 | } |
||
54 | } |
||
55 | $icAND[$key] = ''; |
||
56 | foreach ($icANDmask[$key] as $y => $scanlinemaskbits) { |
||
57 | for ($i = 0, $iMax = strlen($scanlinemaskbits); $i < $iMax; $i += 8) { |
||
58 | $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT))); |
||
59 | } |
||
60 | } |
||
61 | } |
||
62 | |||
63 | foreach ($gd_image_array as $key => $gd_image) { |
||
64 | $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8); |
||
65 | |||
66 | // BITMAPINFOHEADER - 40 bytes |
||
67 | $BitmapInfoHeader[$key] = ''; |
||
68 | $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
||
69 | $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
||
70 | // The biHeight member specifies the combined |
||
71 | // height of the XOR and AND masks. |
||
72 | $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; |
||
73 | $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
||
74 | $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00"; // wBitCount; |
||
75 | $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
||
76 | $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
||
77 | $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
||
78 | $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
||
79 | $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
||
80 | $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
||
81 | } |
||
82 | |||
83 | $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
||
84 | $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
||
85 | $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
||
86 | |||
87 | $dwImageOffset = 6 + (count($gd_image_array) * 16); |
||
88 | foreach ($gd_image_array as $key => $gd_image) { |
||
89 | // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
||
90 | |||
91 | $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
||
92 | $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
||
93 | $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
||
94 | $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
||
95 | |||
96 | $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
||
97 | $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
||
98 | |||
99 | $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
||
100 | $icondata .= phpthumb_functions::LittleEndian2String($dwBytesInRes, 4); // dwBytesInRes; // How many bytes in this resource? |
||
101 | |||
102 | $icondata .= phpthumb_functions::LittleEndian2String($dwImageOffset, 4); // dwImageOffset; // Where in the file is this image? |
||
103 | $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
||
104 | $dwImageOffset += strlen($icXOR[$key]); |
||
105 | $dwImageOffset += strlen($icAND[$key]); |
||
106 | } |
||
107 | |||
108 | foreach ($gd_image_array as $key => $gd_image) { |
||
109 | $icondata .= $BitmapInfoHeader[$key]; |
||
110 | $icondata .= $icXOR[$key]; |
||
111 | $icondata .= $icAND[$key]; |
||
112 | } |
||
113 | |||
114 | return $icondata; |
||
115 | } |
||
117 |