[ Index ] |
|
Code source de phpMyVisites 2.3 |
1 <?php 2 /** 3 * ClickHeat : crée sur disque et renvoie le logo PNG 80x15 / creates on disk and returns the PNG 80x15 logo 4 * 5 * @author Yvan Taviaud - LabsMedia - www.labsmedia.com 6 * @since 31/10/2006 7 **/ 8 9 define('CLICKHEAT_GREY_COLOR', 255); 10 define('CLICKHEAT_LOW_COLOR', 0); 11 define('CLICKHEAT_HIGH_COLOR', 255); 12 13 /** Image creation */ 14 $img = imagecreatetruecolor(180, 45); 15 $white = imagecolorallocate($img, 255, 255, 255); 16 $blue = imagecolorallocate($img, 70, 70, 255); 17 $red = imagecolorallocate($img, 255, 70, 70); 18 $black = imagecolorallocate($img, 0, 0, 0); 19 $shadow = imagecolorallocate($img, 200, 200, 255); 20 imagefill($img, 0, 0, $white); 21 22 /** 23 * Colors creation : 24 * grey => deep blue (rgB) => light blue (rGB) => green (rGb) => yellow (RGb) => red (Rgb) 25 * 0 $colorLevels[0] $colorLevels[1] $colorLevels[2] $colorLevels[3] 128 26 **/ 27 $colorLevels = array(0, 40, 45, 70, 100); 28 $colors = array(); 29 for ($i = 0; $i < 128; $i++) 30 { 31 /** Red */ 32 if ($i < $colorLevels[0]) 33 { 34 $colors[$i][0] = CLICKHEAT_GREY_COLOR + (CLICKHEAT_LOW_COLOR - CLICKHEAT_GREY_COLOR) * $i / $colorLevels[0]; 35 } 36 elseif ($i < $colorLevels[2]) 37 { 38 $colors[$i][0] = CLICKHEAT_LOW_COLOR; 39 } 40 elseif ($i < $colorLevels[3]) 41 { 42 $colors[$i][0] = CLICKHEAT_LOW_COLOR + (CLICKHEAT_HIGH_COLOR - CLICKHEAT_LOW_COLOR) * ($i - $colorLevels[2]) / ($colorLevels[3] - $colorLevels[2]); 43 } 44 else 45 { 46 $colors[$i][0] = CLICKHEAT_HIGH_COLOR; 47 } 48 /** Green */ 49 if ($i < $colorLevels[0]) 50 { 51 $colors[$i][1] = CLICKHEAT_GREY_COLOR + (CLICKHEAT_LOW_COLOR - CLICKHEAT_GREY_COLOR) * $i / $colorLevels[0]; 52 } 53 elseif ($i < $colorLevels[1]) 54 { 55 $colors[$i][1] = CLICKHEAT_LOW_COLOR + (CLICKHEAT_HIGH_COLOR - CLICKHEAT_LOW_COLOR) * ($i - $colorLevels[0]) / ($colorLevels[1] - $colorLevels[0]); 56 } 57 elseif ($i < $colorLevels[3]) 58 { 59 $colors[$i][1] = CLICKHEAT_HIGH_COLOR; 60 } 61 else 62 { 63 $colors[$i][1] = CLICKHEAT_HIGH_COLOR - (CLICKHEAT_HIGH_COLOR - CLICKHEAT_LOW_COLOR) * ($i - $colorLevels[3]) / (127 - $colorLevels[3]); 64 } 65 /** Blue */ 66 if ($i < $colorLevels[0]) 67 { 68 $colors[$i][2] = CLICKHEAT_GREY_COLOR + (CLICKHEAT_HIGH_COLOR - CLICKHEAT_GREY_COLOR) * $i / $colorLevels[0]; 69 } 70 elseif ($i < $colorLevels[1]) 71 { 72 $colors[$i][2] = CLICKHEAT_HIGH_COLOR; 73 } 74 elseif ($i < $colorLevels[2]) 75 { 76 $colors[$i][2] = CLICKHEAT_HIGH_COLOR - (CLICKHEAT_HIGH_COLOR - CLICKHEAT_LOW_COLOR) * ($i - $colorLevels[1]) / ($colorLevels[2] - $colorLevels[1]); 77 } 78 else 79 { 80 $colors[$i][2] = CLICKHEAT_LOW_COLOR; 81 } 82 } 83 84 $max = 12; 85 $pixels = array( 86 ' *** ', 87 ' ***** ', 88 ' ***** ', 89 ' ****** ', 90 ' ****** ', 91 ' ******* ', 92 ' ******* ', 93 ' ******* ', 94 ' ******** ', 95 ' ********* ', 96 ' ********** ', 97 ' *********** ', 98 ' ************* ', 99 ' ************** ', 100 ' **************** ', 101 ' ****************** ', 102 ' ******************** ', 103 '*********************** ', 104 '************************ ', 105 '************************* ', 106 '************************* ', 107 '**************************', 108 '**************************', 109 ' *************************', 110 ' *************************', 111 ' ************************', 112 ' ************************', 113 ' ***********************', 114 ' **********************', 115 ' ******************** ', 116 ' ******************* ', 117 ' ****************** ', 118 ' *************** ', 119 ' ************** ', 120 ' *********** ', 121 ' ********* ', 122 ' ****** ', 123 ' ***** ', 124 ' **** ', 125 ' *** ', 126 ' ** ', 127 ' * '); 128 $mx = strlen($pixels[0]); 129 $my = count($pixels); 130 $blur = imagecreatetruecolor($mx + 2, $my + 2); 131 $white = imagecolorallocate($blur, 255, 255, 255); 132 imagefill($blur, 0, 0, $white); 133 for ($x = 0; $x < $mx; $x++) 134 { 135 for ($y = 0; $y < $my; $y++) 136 { 137 if ($pixels[$y][$x] === '*') 138 { 139 imagesetpixel($blur, $x + 1, $y + 1, $black); 140 } 141 } 142 } 143 144 $previous = $white; 145 for ($i = 0; $i <= $max; $i++) 146 { 147 $color = imagecolorallocate($blur, $colors[ceil($i * 127 / $max)][0], $colors[ceil($i * 127 / $max)][1], $colors[ceil($i * 127 / $max)][2]); 148 for ($x = 1; $x < $mx + 1; $x++) 149 { 150 for ($y = 1; $y < $my + 1; $y++) 151 { 152 if (imagecolorat($blur, $x, $y) === $black) 153 { 154 if ($i === $max || imagecolorat($blur, $x + 1, $y) === $previous || imagecolorat($blur, $x - 1, $y) === $previous 155 || imagecolorat($blur, $x, $y + 1) === $previous || imagecolorat($blur, $x, $y - 1) === $previous) 156 { 157 imagesetpixel($blur, $x, $y, $color); 158 } 159 } 160 } 161 } 162 $previous = $color; 163 } 164 $color = array(); 165 $level = 1; 166 for ($x = 1; $x < $mx + 1; $x++) 167 { 168 for ($y = 1; $y < $my + 1; $y++) 169 { 170 $color[0] = imagecolorsforindex($blur, imagecolorat($blur, $x, $y)); 171 if ($color[0]['red'] + $color[0]['green'] + $color[0]['blue'] === 765) 172 { 173 $color[1] = imagecolorsforindex($blur, imagecolorat($blur, $x + 1, $y)); 174 $color[2] = imagecolorsforindex($blur, imagecolorat($blur, $x - 1, $y)); 175 $color[3] = imagecolorsforindex($blur, imagecolorat($blur, $x, $y + 1)); 176 $color[4] = imagecolorsforindex($blur, imagecolorat($blur, $x, $y - 1)); 177 $col = imagecolorallocate($img, ceil(($level * $color[0]['red'] + $color[1]['red'] + $color[2]['red'] + $color[3]['red'] + $color[4]['red']) / ($level + 4)), 178 ceil(($level * $color[0]['green'] + $color[1]['green'] + $color[2]['green'] + $color[3]['green'] + $color[4]['green']) / ($level + 4)), 179 ceil(($level * $color[0]['blue'] + $color[1]['blue'] + $color[2]['blue'] + $color[3]['blue'] + $color[4]['blue']) / ($level + 4))); 180 } 181 else 182 { 183 $col = imagecolorallocate($img, $color[0]['red'], $color[0]['green'], $color[0]['blue']); 184 } 185 imagesetpixel($img, $x, $y, $col); 186 } 187 } 188 imagedestroy($blur); 189 190 $string = 'ClickHeat'; 191 $x = 28; 192 $font = '/home/yvan/.ies4linux/ie5/drive_c/windows/fonts/verdana.ttf'; 193 $size = 25; 194 for ($i = 0, $max = strlen($string); $i < $max; $i++) 195 { 196 $info = imagettfbbox($size, 0, $font, $string[$i]); 197 if (strtolower($string[$i]) === 'h') 198 { 199 $font = '/home/yvan/.ies4linux/ie5/drive_c/windows/fonts/verdanab.ttf'; 200 } 201 imagettftext($img, $size, 0, $x + 1, 36, $shadow, $font, $string[$i]); 202 imagettftext($img, $size, 0, $x, 35, $blue, $font, $string[$i]); 203 $x += $info[2] - $info[0] + 3; 204 if (strtolower($string[$i]) === 'c' || strtolower($string[$i]) === 'k') 205 { 206 $x -= 2; 207 } 208 if (strtolower($string[$i]) === 'h') 209 { 210 $x += 4; 211 } 212 } 213 214 header('Content-Type: image/png'); 215 imagepng($img, './images/logo.big.png'); 216 imagepng($img); 217 imagedestroy($img); 218 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 14:10:01 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |