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