source: trunk/expressoMail1_2/inc/gd_functions.php @ 1037

Revision 1037, 5.9 KB checked in by amuller, 15 years ago (diff)

Ticket #559 - Correção de problema, usando caminho relativo

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