[1036] | 1 | <?php |
---|
[5509] | 2 | /*************************************************************************** |
---|
| 3 | * Expresso Livre * |
---|
| 4 | * http://www.expressolivre.org * |
---|
| 5 | * -------------------------------------------- * |
---|
| 6 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 7 | * under the terms of the GNU General Public License as published by the * |
---|
| 8 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 9 | * option) any later version. * |
---|
| 10 | \**************************************************************************/ |
---|
| 11 | |
---|
[1037] | 12 | if(!isset($GLOBALS['phpgw_info'])){ |
---|
| 13 | $GLOBALS['phpgw_info']['flags'] = array( |
---|
| 14 | 'currentapp' => 'expressoMail1_2', |
---|
| 15 | 'nonavbar' => true, |
---|
| 16 | 'noheader' => true |
---|
| 17 | ); |
---|
| 18 | } |
---|
[1040] | 19 | require_once '../header.inc.php'; |
---|
| 20 | |
---|
| 21 | /*Author: |
---|
[1005] | 22 | * JPEXS from http://www.hotscripts.com* ImageCreateFromBmp |
---|
| 23 | */ |
---|
| 24 | |
---|
| 25 | function imagecreatefrombmp($file) |
---|
| 26 | { |
---|
| 27 | global $CurrentBit, $echoMode; |
---|
| 28 | |
---|
| 29 | $f=fopen($file,"r"); |
---|
| 30 | $Header=fread($f,2); |
---|
| 31 | |
---|
| 32 | if($Header=="BM") |
---|
| 33 | { |
---|
| 34 | $Size=freaddword($f); |
---|
| 35 | $Reserved1=freadword($f); |
---|
| 36 | $Reserved2=freadword($f); |
---|
| 37 | $FirstByteOfImage=freaddword($f); |
---|
| 38 | |
---|
| 39 | $SizeBITMAPINFOHEADER=freaddword($f); |
---|
| 40 | $Width=freaddword($f); |
---|
| 41 | $Height=freaddword($f); |
---|
| 42 | $biPlanes=freadword($f); |
---|
| 43 | $biBitCount=freadword($f); |
---|
| 44 | $RLECompression=freaddword($f); |
---|
| 45 | $WidthxHeight=freaddword($f); |
---|
| 46 | $biXPelsPerMeter=freaddword($f); |
---|
| 47 | $biYPelsPerMeter=freaddword($f); |
---|
| 48 | $NumberOfPalettesUsed=freaddword($f); |
---|
| 49 | $NumberOfImportantColors=freaddword($f); |
---|
| 50 | |
---|
| 51 | if($biBitCount<24) |
---|
| 52 | { |
---|
| 53 | $img=imagecreate($Width,$Height); |
---|
| 54 | $Colors=pow(2,$biBitCount); |
---|
[7655] | 55 | for($p=0;$p<$Colors;++$p) |
---|
[1005] | 56 | { |
---|
| 57 | $B=freadbyte($f); |
---|
| 58 | $G=freadbyte($f); |
---|
| 59 | $R=freadbyte($f); |
---|
| 60 | $Reserved=freadbyte($f); |
---|
| 61 | $Palette[]=imagecolorallocate($img,$R,$G,$B); |
---|
| 62 | }; |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | if($RLECompression==0) |
---|
| 68 | { |
---|
| 69 | $Zbytek=(4-ceil(($Width/(8/$biBitCount)))%4)%4; |
---|
| 70 | |
---|
| 71 | for($y=$Height-1;$y>=0;$y--) |
---|
| 72 | { |
---|
| 73 | $CurrentBit=0; |
---|
[7655] | 74 | for($x=0;$x<$Width;++$x) |
---|
[1005] | 75 | { |
---|
| 76 | $C=freadbits($f,$biBitCount); |
---|
| 77 | imagesetpixel($img,$x,$y,$Palette[$C]); |
---|
| 78 | }; |
---|
| 79 | if($CurrentBit!=0) {freadbyte($f);}; |
---|
[7655] | 80 | for($g=0;$g<$Zbytek;++$g) |
---|
[1005] | 81 | freadbyte($f); |
---|
| 82 | }; |
---|
| 83 | |
---|
| 84 | }; |
---|
| 85 | }; |
---|
| 86 | |
---|
| 87 | |
---|
| 88 | if($RLECompression==1) //$BI_RLE8 |
---|
| 89 | { |
---|
| 90 | $y=$Height; |
---|
| 91 | |
---|
| 92 | $pocetb=0; |
---|
| 93 | |
---|
| 94 | while(true) |
---|
| 95 | { |
---|
| 96 | $y--; |
---|
| 97 | $prefix=freadbyte($f); |
---|
| 98 | $suffix=freadbyte($f); |
---|
| 99 | $pocetb+=2; |
---|
| 100 | |
---|
| 101 | $echoit=false; |
---|
| 102 | |
---|
| 103 | if($echoit)echo "Prefix: $prefix Suffix: $suffix<BR>"; |
---|
| 104 | if(($prefix==0)and($suffix==1)) break; |
---|
| 105 | if(feof($f)) break; |
---|
| 106 | |
---|
| 107 | while(!(($prefix==0)and($suffix==0))) |
---|
| 108 | { |
---|
| 109 | if($prefix==0) |
---|
| 110 | { |
---|
| 111 | $pocet=$suffix; |
---|
| 112 | $Data.=fread($f,$pocet); |
---|
| 113 | $pocetb+=$pocet; |
---|
[7655] | 114 | if($pocetb%2==1) {freadbyte($f); ++$pocetb;}; |
---|
[1005] | 115 | }; |
---|
| 116 | if($prefix>0) |
---|
| 117 | { |
---|
| 118 | $pocet=$prefix; |
---|
[7655] | 119 | for($r=0;$r<$pocet;++$r) |
---|
[1005] | 120 | $Data.=chr($suffix); |
---|
| 121 | }; |
---|
| 122 | $prefix=freadbyte($f); |
---|
| 123 | $suffix=freadbyte($f); |
---|
| 124 | $pocetb+=2; |
---|
| 125 | if($echoit) echo "Prefix: $prefix Suffix: $suffix<BR>"; |
---|
| 126 | }; |
---|
| 127 | |
---|
[7655] | 128 | for($x=0;$x<strlen($Data);++$x) |
---|
[1005] | 129 | { |
---|
| 130 | imagesetpixel($img,$x,$y,$Palette[ord($Data[$x])]); |
---|
| 131 | }; |
---|
| 132 | $Data=""; |
---|
| 133 | |
---|
| 134 | }; |
---|
| 135 | |
---|
| 136 | }; |
---|
| 137 | |
---|
| 138 | |
---|
| 139 | if($RLECompression==2) //$BI_RLE4 |
---|
| 140 | { |
---|
| 141 | $y=$Height; |
---|
| 142 | $pocetb=0; |
---|
| 143 | |
---|
| 144 | /*while(!feof($f)) |
---|
| 145 | echo freadbyte($f)."_".freadbyte($f)."<BR>";*/ |
---|
| 146 | while(true) |
---|
| 147 | { |
---|
| 148 | //break; |
---|
| 149 | $y--; |
---|
| 150 | $prefix=freadbyte($f); |
---|
| 151 | $suffix=freadbyte($f); |
---|
| 152 | $pocetb+=2; |
---|
| 153 | |
---|
| 154 | $echoit=false; |
---|
| 155 | |
---|
| 156 | if($echoit)echo "Prefix: $prefix Suffix: $suffix<BR>"; |
---|
| 157 | if(($prefix==0)and($suffix==1)) break; |
---|
| 158 | if(feof($f)) break; |
---|
| 159 | |
---|
| 160 | while(!(($prefix==0)and($suffix==0))) |
---|
| 161 | { |
---|
| 162 | if($prefix==0) |
---|
| 163 | { |
---|
| 164 | $pocet=$suffix; |
---|
| 165 | |
---|
| 166 | $CurrentBit=0; |
---|
[7655] | 167 | for($h=0;$h<$pocet;++$h) |
---|
[1005] | 168 | $Data.=chr(freadbits($f,4)); |
---|
| 169 | if($CurrentBit!=0) freadbits($f,4); |
---|
| 170 | $pocetb+=ceil(($pocet/2)); |
---|
[7655] | 171 | if($pocetb%2==1) {freadbyte($f); ++$pocetb;}; |
---|
[1005] | 172 | }; |
---|
| 173 | if($prefix>0) |
---|
| 174 | { |
---|
| 175 | $pocet=$prefix; |
---|
| 176 | $i=0; |
---|
[7655] | 177 | for($r=0;$r<$pocet;++$r) |
---|
[1005] | 178 | { |
---|
| 179 | if($i%2==0) |
---|
| 180 | { |
---|
| 181 | $Data.=chr($suffix%16); |
---|
| 182 | } |
---|
| 183 | else |
---|
| 184 | { |
---|
| 185 | $Data.=chr(floor($suffix/16)); |
---|
| 186 | }; |
---|
[7655] | 187 | ++$i; |
---|
[1005] | 188 | }; |
---|
| 189 | }; |
---|
| 190 | $prefix=freadbyte($f); |
---|
| 191 | $suffix=freadbyte($f); |
---|
| 192 | $pocetb+=2; |
---|
| 193 | if($echoit) echo "Prefix: $prefix Suffix: $suffix<BR>"; |
---|
| 194 | }; |
---|
| 195 | |
---|
[7655] | 196 | for($x=0;$x<strlen($Data);++$x) |
---|
[1005] | 197 | { |
---|
| 198 | imagesetpixel($img,$x,$y,$Palette[ord($Data[$x])]); |
---|
| 199 | }; |
---|
| 200 | $Data=""; |
---|
| 201 | |
---|
| 202 | }; |
---|
| 203 | |
---|
| 204 | }; |
---|
| 205 | |
---|
| 206 | |
---|
| 207 | if($biBitCount==24) |
---|
| 208 | { |
---|
| 209 | $img=imagecreatetruecolor($Width,$Height); |
---|
| 210 | $Zbytek=$Width%4; |
---|
| 211 | |
---|
| 212 | for($y=$Height-1;$y>=0;$y--) |
---|
| 213 | { |
---|
[7655] | 214 | for($x=0;$x<$Width;++$x) |
---|
[1005] | 215 | { |
---|
| 216 | $B=freadbyte($f); |
---|
| 217 | $G=freadbyte($f); |
---|
| 218 | $R=freadbyte($f); |
---|
| 219 | $color=imagecolorexact($img,$R,$G,$B); |
---|
| 220 | if($color==-1) $color=imagecolorallocate($img,$R,$G,$B); |
---|
| 221 | imagesetpixel($img,$x,$y,$color); |
---|
| 222 | } |
---|
[7655] | 223 | for($z=0;$z<$Zbytek;++$z) |
---|
[1005] | 224 | freadbyte($f); |
---|
| 225 | }; |
---|
| 226 | }; |
---|
| 227 | return $img; |
---|
| 228 | |
---|
| 229 | }; |
---|
| 230 | |
---|
| 231 | |
---|
| 232 | fclose($f); |
---|
| 233 | |
---|
| 234 | |
---|
| 235 | }; |
---|
| 236 | |
---|
| 237 | |
---|
| 238 | /* |
---|
| 239 | * Helping functions: |
---|
| 240 | *------------------------- |
---|
| 241 | * |
---|
| 242 | * freadbyte($file) - reads 1 byte from $file |
---|
| 243 | * freadword($file) - reads 2 bytes (1 word) from $file |
---|
| 244 | * freaddword($file) - reads 4 bytes (1 dword) from $file |
---|
| 245 | * freadlngint($file) - same as freaddword($file) |
---|
| 246 | * decbin8($d) - returns binary string of d zero filled to 8 |
---|
| 247 | * RetBits($byte,$start,$len) - returns bits $start->$start+$len from $byte |
---|
| 248 | * freadbits($file,$count) - reads next $count bits from $file |
---|
| 249 | * RGBToHex($R,$G,$B) - convert $R, $G, $B to hex |
---|
| 250 | * int_to_dword($n) - returns 4 byte representation of $n |
---|
| 251 | * int_to_word($n) - returns 2 byte representation of $n |
---|
| 252 | */ |
---|
| 253 | |
---|
| 254 | function freadbyte($f) |
---|
| 255 | { |
---|
| 256 | return ord(fread($f,1)); |
---|
| 257 | }; |
---|
| 258 | |
---|
| 259 | function freadword($f) |
---|
| 260 | { |
---|
| 261 | $b1=freadbyte($f); |
---|
| 262 | $b2=freadbyte($f); |
---|
| 263 | return $b2*256+$b1; |
---|
| 264 | }; |
---|
| 265 | |
---|
| 266 | |
---|
| 267 | function freadlngint($f) |
---|
| 268 | { |
---|
| 269 | return freaddword($f); |
---|
| 270 | }; |
---|
| 271 | |
---|
| 272 | function freaddword($f) |
---|
| 273 | { |
---|
| 274 | $b1=freadword($f); |
---|
| 275 | $b2=freadword($f); |
---|
| 276 | return $b2*65536+$b1; |
---|
| 277 | }; |
---|
| 278 | |
---|
| 279 | |
---|
| 280 | |
---|
| 281 | function RetBits($byte,$start,$len) |
---|
| 282 | { |
---|
| 283 | $bin=decbin8($byte); |
---|
| 284 | $r=bindec(substr($bin,$start,$len)); |
---|
| 285 | return $r; |
---|
| 286 | |
---|
| 287 | }; |
---|
| 288 | |
---|
| 289 | |
---|
| 290 | |
---|
| 291 | $CurrentBit=0; |
---|
| 292 | function freadbits($f,$count) |
---|
| 293 | { |
---|
| 294 | global $CurrentBit,$SMode; |
---|
| 295 | $Byte=freadbyte($f); |
---|
| 296 | $LastCBit=$CurrentBit; |
---|
| 297 | $CurrentBit+=$count; |
---|
| 298 | if($CurrentBit==8) |
---|
| 299 | { |
---|
| 300 | $CurrentBit=0; |
---|
| 301 | } |
---|
| 302 | else |
---|
| 303 | { |
---|
| 304 | fseek($f,ftell($f)-1); |
---|
| 305 | }; |
---|
| 306 | return RetBits($Byte,$LastCBit,$count); |
---|
| 307 | }; |
---|
| 308 | |
---|
| 309 | |
---|
| 310 | |
---|
| 311 | function RGBToHex($Red,$Green,$Blue) |
---|
| 312 | { |
---|
| 313 | $hRed=dechex($Red);if(strlen($hRed)==1) $hRed="0$hRed"; |
---|
| 314 | $hGreen=dechex($Green);if(strlen($hGreen)==1) $hGreen="0$hGreen"; |
---|
| 315 | $hBlue=dechex($Blue);if(strlen($hBlue)==1) $hBlue="0$hBlue"; |
---|
| 316 | return($hRed.$hGreen.$hBlue); |
---|
| 317 | }; |
---|
| 318 | |
---|
| 319 | function int_to_dword($n) |
---|
| 320 | { |
---|
| 321 | return chr($n & 255).chr(($n >> 8) & 255).chr(($n >> 16) & 255).chr(($n >> 24) & 255); |
---|
| 322 | } |
---|
| 323 | function int_to_word($n) |
---|
| 324 | { |
---|
| 325 | return chr($n & 255).chr(($n >> 8) & 255); |
---|
| 326 | } |
---|
| 327 | |
---|
| 328 | |
---|
| 329 | function decbin8($d) |
---|
| 330 | { |
---|
| 331 | return decbinx($d,8); |
---|
| 332 | }; |
---|
| 333 | |
---|
| 334 | function decbinx($d,$n) |
---|
| 335 | { |
---|
| 336 | $bin=decbin($d); |
---|
| 337 | $sbin=strlen($bin); |
---|
[7655] | 338 | for($j=0;$j<$n-$sbin;++$j) |
---|
[1005] | 339 | $bin="0$bin"; |
---|
| 340 | return $bin; |
---|
| 341 | }; |
---|
| 342 | |
---|
| 343 | function inttobyte($n) |
---|
| 344 | { |
---|
| 345 | return chr($n); |
---|
| 346 | }; |
---|
| 347 | |
---|
| 348 | ?> |
---|