Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 11

Discussione: [gd] problema con bmp

  1. #1

    [gd] problema con bmp

    ecco ho trovato una classe per fare thumbnail al volo e funziona da dio ma ha un problema

    questo è il codice
    Codice PHP:
    <?php
    class thumbnail
        
    {
            var 
    $sourceFile// We use this file to create the thumbnail
            
    var $originalFilename// We use this to get the extension of the filename
            
    var $destinationDirectory// The Directory in question
            
    var $destinationDirectoryFilename// The destination filename
            
            
    var $createImageFunction '';
            var 
    $outputImageFunction '';
            
            function 
    generate($sourceFile ""$originalFilename ""$destinationDirectory ""$destinationDirectoryFilename ""$width = -1$height = -1)
            {
          if (!empty(
    $sourceFile))
            
    $this->sourceFile $sourceFile;
          
          if (!empty(
    $originalFilename))
            
    $this->originalFilename $originalFilename;
           
          if (!empty(
    $destinationDirectory))
            
    $this->destinationDirectory $destinationDirectory;
           
          if (!empty(
    $destinationDirectoryFilename))
            
    $this->destinationDirectoryFilename $destinationDirectoryFilename;
          
          if (!empty(
    $width))
            
    $this->width $width;
          
          if (!empty(
    $height))
            
    $this->height $height;

          list(, 
    $this->extension) = explode('.'$this->originalFilename);
                
                switch (
    $this->extension)
                {
                    case 
    'gif' :
                        
    $createImageFunction 'imagecreatefromgif';
                        
    $outputImageFunction 'imagegif';
                      break;
                    
                    case 
    'png' :
                        
    $createImageFunction 'imagecreatefrompng';
                        
    $outputImageFunction 'imagepng';
                      break;
                    
                    case 
    'bmp' :
                        
    $createImageFunction 'imagecreatefromwbmp';
                        
    $outputImageFunction 'image2wbmp';
                      break;
                    
                    case 
    'jpg': case 'jpeg':
                        
    $createImageFunction 'imagecreatefromjpeg';
                        
    $outputImageFunction 'imagejpeg';
                      break;
                    
                    default : 
                        exit(
    "Sorry: The format '{$this->extension}' is unsuported");
                      break;
                }
                
                
    $this->img  $createImageFunction($this->sourceFile);
                
                list(
    $this->org_width$this->org_height) = getimagesize($this->sourceFile);
                
                if (
    $this->height == -1)
                {
                    
    $this->height round($this->org_height $this->width $this->org_width);
                }
                
                if (
    $this->width == -1)
                {
                    
    $this->width round($this->org_width $this->height $this->org_height);
                }     
                
                
    $this->xoffset 0;
                
    $this->yoffset 0;
                
                
    $this->img_new imagecreatetruecolor($this->width$this->height);    
                
                if (
    $this->img_new)
                {
                    
    imagecopyresampled($this->img_new$this->img00$this->xoffset$this->yoffset$this->width$this->height$this->org_width$this->org_height);
                    
                    list(
    $this->newFilename) = explode('.'$this->destinationDirectoryFilename);
                    
                    
    $this->fullDestination = ($this->destinationDirectory.'/'.$this->newFilename.'.'.$this->extension);
                    
                    
    $outputImageFunction($this->img_new$this->fullDestination);
                }
                else
                {
                    
    $this->failed true;
                }
                
                if (
    $this->failed == false)
                {
                    return 
    $this->fullDestination;
                }
            }
        }
    ?>
    l'ho presa da html.it e non capisco perchè al momento di fare la thumb di una bitmap sputi fuori questi errori:

    codice:
    Warning: imagecreatefromwbmp() [function.imagecreatefromwbmp]: '/tmp/phpcZp4zI' is not a valid WBMP file in /newhome/puglfabr/public_html/meta/thumb/thumbnail.class.php on line 86
    
    Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /newhome/puglfabr/public_html/meta/thumb/thumbnail.class.php on line 107
    le righe incriminate sono queste: VVoVe:

    codice:
    $this->img  = $createImageFunction($this->sourceFile); <= riga 86
    imagecopyresampled($this->img_new, $this->img, 0, 0, $this->xoffset, $this->yoffset, $this->width, $this->height, $this->org_width, $this->org_height); <= riga 107
    vi chiedo aiuto....
    Perchè essere stupidi non è una menomazione ma un diritto di tutti!!!

  2. #2
    Ho programmato una galleria dinamica e leggendo il tuo post ho provato a caricare una bmp (a me non serve caricare questo tipo di file ma avevo messo un array di estensioni permesse tra cui
    quella ..e ho verificato il tuo stesso errore

    Warning: imagecreatefromwbmp() [function.imagecreatefromwbmp]: '../foto/23.bmp' is not a valid WBMP file ecc.

    secondo me è un bug del php io uso le gd 2 sia in locale che on line

    se risolvi magari fammi sapere perché la cosa mi interessa

    http://bugs.php.net/search.php?cmd=d...related&by=Any
    Un tardo hegeliano di Busalla / allevava un gorilla nella stalla
    citando Adorno nell notti chiare / finché il primate stanco di ascoltare
    lo strangolò con una sciarpa gialla Dillo Con Parole Sue

  3. #3
    Utente di HTML.it L'avatar di gianiaz
    Registrato dal
    May 2001
    Messaggi
    8,027
    http://fr.php.net/manual/en/function...tefromwbmp.php

    Leggendo i commenti delle funzioni si capisce molto:

    for .bmp files, convert them with bmp2png, then you can use this files in gd
    http://hp.vector.co.jp/authors/VA010446/b2p-home/

    WBMP images are Wireless Bitmaps, not Windows Bitmaps. WBMP is used for bandwidth constrained, black and white, limited devices such as PDAs and Cell Phones.
    Comunque non è un bug, semplicemente le bmp non sono supportate... e chi le vorrebbe sul web?

    ciao

  4. #4
    io le vorrei sul web....non da far visualizzare sulle pagine mi serve da caricare su un server web...
    cmq deve essere un bug perchè la funzione è apposta per le bmp ma da errore sulle bmp .... ci deve essere qualcosa che non va VVoVe:


    speriamo che arrivi una manna dal cielo....
    Perchè essere stupidi non è una menomazione ma un diritto di tutti!!!

  5. #5
    Utente di HTML.it L'avatar di gianiaz
    Registrato dal
    May 2001
    Messaggi
    8,027
    te lo traduco perchè forse non hai capito:

    WBMP images are Wireless Bitmaps, not Windows Bitmaps. WBMP is used for bandwidth constrained, black and white, limited devices such as PDAs and Cell Phones.
    Le immagini WBMP sono le Wireless Bitmaps, e non le Windows Bitmaps. Le WBMP sono usate per risparmiare banda, sono in bianco e nero e vengono usate su pochi dispositivi, come i palmari e i telefoni cellulari.
    Tieni presente che questo è un commento del 2001, quindi di acqua ne è passata sotto i ponti, ma non si può dire lo stesso di funzioni per la gestione delle BMP.

    Tieni presente che le bmp in genere sono molto pesanti, e un server web farebbe comunque fatica a gestirle, anche se ci fossero le funzioni adeguate.

    Dubito che tu possa mettere mano sul server, ma se puoi ed è windows, puoi richiamare questo eseguibile con la funzione system.

    http://cetus.sakura.ne.jp/softlab/b2p-home/

    In ogni caso non è un bug, e fossi in te non mi illuderei riguardo alla probabile uscita di una funzione per la gestione delle bmp.


  6. #6
    Le immagini WBMP sono le Wireless Bitmaps, e non le Windows Bitmaps. Le WBMP sono usate per risparmiare banda, sono in bianco e nero e vengono usate su pochi dispositivi, come i palmari e i telefoni cellulari.
    azz hai ragione....se ti devo dire la verità questo commento lo avevo pure letto....
    Dubito che tu possa mettere mano sul server, ma se puoi ed è windows, puoi richiamare questo eseguibile con la funzione system.
    sbagliato il server è del posto dove lavoro(uno dei tanti server)
    e ovviamente è linux (mai e poi mai winzoz come server)
    cmq ti ringrazio per la delucidazione

    In ogni caso non è un bug, e fossi in te non mi illuderei riguardo alla probabile uscita di una funzione per la gestione delle bmp.

    è un peccato.......e cmq mai dire mai.... :ignore:

    grazie cmq
    Perchè essere stupidi non è una menomazione ma un diritto di tutti!!!

  7. #7
    sembra che un pazzo ci sia

    http://www.php.net/manual/en/functio...eate.php#53879

    <?php
    /*********************************************/
    /* Fonction: ImageCreateFromBMP */
    /* Author: DHKold */
    /* Contact: admin@dhkold.com */
    /* Date: The 15th of June 2005 */
    /* Version: 2.0B */
    /*********************************************/

    function ImageCreateFromBMP($filename)
    {
    //Ouverture du fichier en mode binaire
    if (! $f1 = fopen($filename,"rb")) return FALSE;

    //1 : Chargement des ent�tes FICHIER
    $FILE = unpack("vfile_type/Vfile_size/Vreserved/Vbitmap_offset", fread($f1,14));
    if ($FILE['file_type'] != 19778) return FALSE;

    //2 : Chargement des ent�tes BMP
    $BMP = unpack('Vheader_size/Vwidth/Vheight/vplanes/vbits_per_pixel'.
    '/Vcompression/Vsize_bitmap/Vhoriz_resolution'.
    '/Vvert_resolution/Vcolors_used/Vcolors_important', fread($f1,40));
    $BMP['colors'] = pow(2,$BMP['bits_per_pixel']);
    if ($BMP['size_bitmap'] == 0) $BMP['size_bitmap'] = $FILE['file_size'] - $FILE['bitmap_offset'];
    $BMP['bytes_per_pixel'] = $BMP['bits_per_pixel']/8;
    $BMP['bytes_per_pixel2'] = ceil($BMP['bytes_per_pixel']);
    $BMP['decal'] = ($BMP['width']*$BMP['bytes_per_pixel']/4);
    $BMP['decal'] -= floor($BMP['width']*$BMP['bytes_per_pixel']/4);
    $BMP['decal'] = 4-(4*$BMP['decal']);
    if ($BMP['decal'] == 4) $BMP['decal'] = 0;

    //3 : Chargement des couleurs de la palette
    $PALETTE = array();
    if ($BMP['colors'] < 16777216)
    {
    $PALETTE = unpack('V'.$BMP['colors'], fread($f1,$BMP['colors']*4));
    }

    //4 : Cr�ation de l'image
    $IMG = fread($f1,$BMP['size_bitmap']);
    $VIDE = chr(0);

    $res = imagecreatetruecolor($BMP['width'],$BMP['height']);
    $P = 0;
    $Y = $BMP['height']-1;
    while ($Y >= 0)
    {
    $X=0;
    while ($X < $BMP['width'])
    {
    if ($BMP['bits_per_pixel'] == 24)
    $COLOR = unpack("V",substr($IMG,$P,3).$VIDE);
    elseif ($BMP['bits_per_pixel'] == 16)
    {
    $COLOR = unpack("n",substr($IMG,$P,2));
    $COLOR[1] = $PALETTE[$COLOR[1]+1];
    }
    elseif ($BMP['bits_per_pixel'] == 8)
    {
    $COLOR = unpack("n",$VIDE.substr($IMG,$P,1));
    $COLOR[1] = $PALETTE[$COLOR[1]+1];
    }
    elseif ($BMP['bits_per_pixel'] == 4)
    {
    $COLOR = unpack("n",$VIDE.substr($IMG,floor($P),1));
    if (($P*2)%2 == 0) $COLOR[1] = ($COLOR[1] >> 4) ; else $COLOR[1] = ($COLOR[1] & 0x0F);
    $COLOR[1] = $PALETTE[$COLOR[1]+1];
    }
    elseif ($BMP['bits_per_pixel'] == 1)
    {
    $COLOR = unpack("n",$VIDE.substr($IMG,floor($P),1));
    if (($P*8)%8 == 0) $COLOR[1] = $COLOR[1] >>7;
    elseif (($P*8)%8 == 1) $COLOR[1] = ($COLOR[1] & 0x40)>>6;
    elseif (($P*8)%8 == 2) $COLOR[1] = ($COLOR[1] & 0x20)>>5;
    elseif (($P*8)%8 == 3) $COLOR[1] = ($COLOR[1] & 0x10)>>4;
    elseif (($P*8)%8 == 4) $COLOR[1] = ($COLOR[1] & 0x8)>>3;
    elseif (($P*8)%8 == 5) $COLOR[1] = ($COLOR[1] & 0x4)>>2;
    elseif (($P*8)%8 == 6) $COLOR[1] = ($COLOR[1] & 0x2)>>1;
    elseif (($P*8)%8 == 7) $COLOR[1] = ($COLOR[1] & 0x1);
    $COLOR[1] = $PALETTE[$COLOR[1]+1];
    }
    else
    return FALSE;
    imagesetpixel($res,$X,$Y,$COLOR[1]);
    $X++;
    $P += $BMP['bytes_per_pixel'];
    }
    $Y--;
    $P+=$BMP['decal'];
    }

    //Fermeture du fichier
    fclose($f1);

    return $res;
    }
    ?>
    Un tardo hegeliano di Busalla / allevava un gorilla nella stalla
    citando Adorno nell notti chiare / finché il primate stanco di ascoltare
    lo strangolò con una sciarpa gialla Dillo Con Parole Sue

  8. #8
    viva i pazzi!!!

    mo la proviamo! grazie!
    Perchè essere stupidi non è una menomazione ma un diritto di tutti!!!

  9. #9
    funzia....grande!!!!

    /*per chi volesse/dovesse utilizzare quella funzione ricordo di cambiare la parte riguardante la bmp a 16 bit con questa */

    Codice PHP:
    elseif ($BMP['bits_per_pixel'] == 16)

       
    $COLOR unpack("v",substr($IMG,$P,2));
       
    $blue  = ($COLOR[1] & 0x001f) << 3;
       
    $green = ($COLOR[1] & 0x07e0) >> 3;
       
    $red   = ($COLOR[1] & 0xf800) >> 8;
       
    $COLOR[1] = $red 65536 $green 256 $blue;

    else non funziona!!!


    adesso ci vuole un pazzo che costruisca/abbia costruito una imageBmp [che scrive una bmp sul disco]


    lo so che chiedo troppo ma mi serve che ci posso fare?!?
    Perchè essere stupidi non è una menomazione ma un diritto di tutti!!!

  10. #10
    ok mi autorispondo da solo

    da questo sito (anche è disponibile in molti altri) ho trovato le funzioni imagebmp e imagecraetefrombmp come se fossero direttamente disponibili dalle gd

    http://www.hotscripts.com/Detailed/41077.html

    per correttezza allego le funzioni

    Codice PHP:
    <?
    /*
    *------------------------------------------------------------
    *                   BMP Image functions
    *------------------------------------------------------------
    *                      By JPEXS
    */




    /*
    *------------------------------------------------------------
    *                    ImageBMP
    *------------------------------------------------------------
    *            - Creates new BMP file
    *
    *         Parameters:  $img - Target image
    *                      $file - Target file to store
    *                            - if not specified, bmp is returned
    *
    *           Returns: if $file specified - true if OK
                         if $file not specified - image data
    */
    function imagebmp($img,$file="",$RLE=0)
    {


    $ColorCount=imagecolorstotal($img);

    $Transparent=imagecolortransparent($img);
    $IsTransparent=$Transparent!=-1;


    if(
    $IsTransparent$ColorCount--;

    if(
    $ColorCount==0) {$ColorCount=0$BitCount=24;};
    if((
    $ColorCount>0)and($ColorCount<=2)) {$ColorCount=2$BitCount=1;};
    if((
    $ColorCount>2)and($ColorCount<=16)) { $ColorCount=16$BitCount=4;};
    if((
    $ColorCount>16)and($ColorCount<=256)) { $ColorCount=0$BitCount=8;};


                    
    $Width=imagesx($img);
                    
    $Height=imagesy($img);

                    
    $Zbytek=(4-($Width/(8/$BitCount))%4)%4;

                    if(
    $BitCount<24$palsize=pow(2,$BitCount)*4;

                    
    $size=(floor($Width/(8/$BitCount))+$Zbytek)*$Height+54;
                    
    $size+=$palsize;
                    
    $offset=54+$palsize;

                    
    // Bitmap File Header
                    
    $ret 'BM';                        // header (2b)
                    
    $ret .= int_to_dword($size);        // size of file (4b)
                    
    $ret .= int_to_dword(0);        // reserved (4b)
                    
    $ret .= int_to_dword($offset);        // byte location in the file which is first byte of IMAGE (4b)
                    // Bitmap Info Header
                    
    $ret .= int_to_dword(40);        // Size of BITMAPINFOHEADER (4b)
                    
    $ret .= int_to_dword($Width);        // width of bitmap (4b)
                    
    $ret .= int_to_dword($Height);        // height of bitmap (4b)
                    
    $ret .= int_to_word(1);        // biPlanes = 1 (2b)
                    
    $ret .= int_to_word($BitCount);        // biBitCount = {1 (mono) or 4 (16 clr ) or 8 (256 clr) or 24 (16 Mil)} (2b)
                    
    $ret .= int_to_dword($RLE);        // RLE COMPRESSION (4b)
                    
    $ret .= int_to_dword(0);        // width x height (4b)
                    
    $ret .= int_to_dword(0);        // biXPelsPerMeter (4b)
                    
    $ret .= int_to_dword(0);        // biYPelsPerMeter (4b)
                    
    $ret .= int_to_dword(0);        // Number of palettes used (4b)
                    
    $ret .= int_to_dword(0);        // Number of important colour (4b)
                    // image data

                    
    $CC=$ColorCount;
                    
    $sl1=strlen($ret);
                    if(
    $CC==0$CC=256;
                    if(
    $BitCount<24)
                       {
                        
    $ColorTotal=imagecolorstotal($img);
                         if(
    $IsTransparent$ColorTotal--;

                         for(
    $p=0;$p<$ColorTotal;$p++)
                         {
                          
    $color=imagecolorsforindex($img,$p);
                           
    $ret.=inttobyte($color["blue"]);
                           
    $ret.=inttobyte($color["green"]);
                           
    $ret.=inttobyte($color["red"]);
                           
    $ret.=inttobyte(0); //RESERVED
                         
    };

                        
    $CT=$ColorTotal;
                      for(
    $p=$ColorTotal;$p<$CC;$p++)
                           {
                          
    $ret.=inttobyte(0);
                          
    $ret.=inttobyte(0);
                          
    $ret.=inttobyte(0);
                          
    $ret.=inttobyte(0); //RESERVED
                         
    };
                       };


    if(
    $BitCount<=8)
    {

     for(
    $y=$Height-1;$y>=0;$y--)
     {
      
    $bWrite="";
      for(
    $x=0;$x<$Width;$x++)
       {
       
    $color=imagecolorat($img,$x,$y);
       
    $bWrite.=decbinx($color,$BitCount);
       if(
    strlen($bWrite)==8)
        {
         
    $retd.=inttobyte(bindec($bWrite));
         
    $bWrite="";
        };
       };

      if((
    strlen($bWrite)<8)and(strlen($bWrite)!=0))
        {
         
    $sl=strlen($bWrite);
         for(
    $t=0;$t<8-$sl;$t++)
          
    $sl.="0";
         
    $retd.=inttobyte(bindec($bWrite));
        };
     for(
    $z=0;$z<$Zbytek;$z++)
       
    $retd.=inttobyte(0);
     };
    };

    if((
    $RLE==1)and($BitCount==8))
    {
     for(
    $t=0;$t<strlen($retd);$t+=4)
      {
       if(
    $t!=0)
       if((
    $t)%$Width==0)
        
    $ret.=chr(0).chr(0);

       if((
    $t+5)%$Width==0)
       {
         
    $ret.=chr(0).chr(5).substr($retd,$t,5).chr(0);
         
    $t+=1;
       }
       if((
    $t+6)%$Width==0)
        {
         
    $ret.=chr(0).chr(6).substr($retd,$t,6);
         
    $t+=2;
        }
        else
        {
         
    $ret.=chr(0).chr(4).substr($retd,$t,4);
        };
      };
      
    $ret.=chr(0).chr(1);
    }
    else
    {
    $ret.=$retd;
    };


                    if(
    $BitCount==24)
                    {
                    for(
    $z=0;$z<$Zbytek;$z++)
                     
    $Dopl.=chr(0);

                    for(
    $y=$Height-1;$y>=0;$y--)
                     {
                     for(
    $x=0;$x<$Width;$x++)
                            {
                               
    $color=imagecolorsforindex($img,ImageColorAt($img,$x,$y));
                               
    $ret.=chr($color["blue"]).chr($color["green"]).chr($color["red"]);
                            }
                     
    $ret.=$Dopl;
                     };

                     };

      if(
    $file!="")
       {
        
    $r=($f=fopen($file,"w"));
        
    $r=$r and fwrite($f,$ret);
        
    $r=$r and fclose($f);
        return 
    $r;
       }
      else
      {
       echo 
    $ret;
      };
    };


    /*
    *------------------------------------------------------------
    *                    ImageCreateFromBmp
    *------------------------------------------------------------
    *            - Reads image from a BMP file
    *
    *         Parameters:  $file - Target file to load
    *
    *            Returns: Image ID
    */

    function imagecreatefrombmp($file)
    {
    global  
    $CurrentBit$echoMode;

    $f=fopen($file,"r");
    $Header=fread($f,2);

    if(
    $Header=="BM")
    {
     
    $Size=freaddword($f);
     
    $Reserved1=freadword($f);
     
    $Reserved2=freadword($f);
     
    $FirstByteOfImage=freaddword($f);

     
    $SizeBITMAPINFOHEADER=freaddword($f);
     
    $Width=freaddword($f);
     
    $Height=freaddword($f);
     
    $biPlanes=freadword($f);
     
    $biBitCount=freadword($f);
     
    $RLECompression=freaddword($f);
     
    $WidthxHeight=freaddword($f);
     
    $biXPelsPerMeter=freaddword($f);
     
    $biYPelsPerMeter=freaddword($f);
     
    $NumberOfPalettesUsed=freaddword($f);
     
    $NumberOfImportantColors=freaddword($f);

    if(
    $biBitCount<24)
     {
      
    $img=imagecreate($Width,$Height);
      
    $Colors=pow(2,$biBitCount);
      for(
    $p=0;$p<$Colors;$p++)
       {
        
    $B=freadbyte($f);
        
    $G=freadbyte($f);
        
    $R=freadbyte($f);
        
    $Reserved=freadbyte($f);
        
    $Palette[]=imagecolorallocate($img,$R,$G,$B);
       };




    if(
    $RLECompression==0)
    {
       
    $Zbytek=(4-ceil(($Width/(8/$biBitCount)))%4)%4;

    for(
    $y=$Height-1;$y>=0;$y--)
        {
         
    $CurrentBit=0;
         for(
    $x=0;$x<$Width;$x++)
          {
             
    $C=freadbits($f,$biBitCount);
           
    imagesetpixel($img,$x,$y,$Palette[$C]);
          };
        if(
    $CurrentBit!=0) {freadbyte($f);};
        for(
    $g=0;$g<$Zbytek;$g++)
         
    freadbyte($f);
         };

     };
    };


    if(
    $RLECompression==1//$BI_RLE8
    {
    $y=$Height;

    $pocetb=0;

    while(
    true)
    {
    $y--;
    $prefix=freadbyte($f);
    $suffix=freadbyte($f);
    $pocetb+=2;

    $echoit=false;

    if(
    $echoit)echo "Prefix: $prefix Suffix: $suffix
    "
    ;
    if((
    $prefix==0)and($suffix==1)) break;
    if(
    feof($f)) break;

    while(!((
    $prefix==0)and($suffix==0)))
    {
     if(
    $prefix==0)
      {
       
    $pocet=$suffix;
       
    $Data.=fread($f,$pocet);
       
    $pocetb+=$pocet;
       if(
    $pocetb%2==1) {freadbyte($f); $pocetb++;};
      };
     if(
    $prefix>0)
      {
       
    $pocet=$prefix;
       for(
    $r=0;$r<$pocet;$r++)
        
    $Data.=chr($suffix);
      };
     
    $prefix=freadbyte($f);
     
    $suffix=freadbyte($f);
     
    $pocetb+=2;
     if(
    $echoit) echo "Prefix: $prefix Suffix: $suffix
    "
    ;
    };

    for(
    $x=0;$x<strlen($Data);$x++)
     {
      
    imagesetpixel($img,$x,$y,$Palette[ord($Data[$x])]);
     };
    $Data="";

    };

    };


    if(
    $RLECompression==2//$BI_RLE4
    {
    $y=$Height;
    $pocetb=0;

    /*while(!feof($f))
     echo freadbyte($f)."_".freadbyte($f)."
    ";*/
    while(true)
    {
    //break;
    $y--;
    $prefix=freadbyte($f);
    $suffix=freadbyte($f);
    $pocetb+=2;

    $echoit=false;

    if(
    $echoit)echo "Prefix: $prefix Suffix: $suffix
    "
    ;
    if((
    $prefix==0)and($suffix==1)) break;
    if(
    feof($f)) break;

    while(!((
    $prefix==0)and($suffix==0)))
    {
     if(
    $prefix==0)
      {
       
    $pocet=$suffix;

       
    $CurrentBit=0;
       for(
    $h=0;$h<$pocet;$h++)
        
    $Data.=chr(freadbits($f,4));
       if(
    $CurrentBit!=0freadbits($f,4);
       
    $pocetb+=ceil(($pocet/2));
       if(
    $pocetb%2==1) {freadbyte($f); $pocetb++;};
      };
     if(
    $prefix>0)
      {
       
    $pocet=$prefix;
       
    $i=0;
       for(
    $r=0;$r<$pocet;$r++)
        {
        if(
    $i%2==0)
         {
          
    $Data.=chr($suffix%16);
         }
         else
         {
          
    $Data.=chr(floor($suffix/16));
         };
        
    $i++;
        };
      };
     
    $prefix=freadbyte($f);
     
    $suffix=freadbyte($f);
     
    $pocetb+=2;
     if(
    $echoit) echo "Prefix: $prefix Suffix: $suffix
    "
    ;
    };

    for(
    $x=0;$x<strlen($Data);$x++)
     {
      
    imagesetpixel($img,$x,$y,$Palette[ord($Data[$x])]);
     };
    $Data="";

    };

    };


     if(
    $biBitCount==24)
    {
     
    $img=imagecreatetruecolor($Width,$Height);
     
    $Zbytek=$Width%4;

       for(
    $y=$Height-1;$y>=0;$y--)
        {
         for(
    $x=0;$x<$Width;$x++)
          {
           
    $B=freadbyte($f);
           
    $G=freadbyte($f);
           
    $R=freadbyte($f);
           
    $color=imagecolorexact($img,$R,$G,$B);
           if(
    $color==-1$color=imagecolorallocate($img,$R,$G,$B);
           
    imagesetpixel($img,$x,$y,$color);
          }
        for(
    $z=0;$z<$Zbytek;$z++)
         
    freadbyte($f);
       };
    };
    return 
    $img;

    };


    fclose($f);


    };





    /*
    * Helping functions:
    *-------------------------
    *
    * freadbyte($file) - reads 1 byte from $file
    * freadword($file) - reads 2 bytes (1 word) from $file
    * freaddword($file) - reads 4 bytes (1 dword) from $file
    * freadlngint($file) - same as freaddword($file)
    * decbin8($d) - returns binary string of d zero filled to 8
    * RetBits($byte,$start,$len) - returns bits $start->$start+$len from $byte
    * freadbits($file,$count) - reads next $count bits from $file
    * RGBToHex($R,$G,$B) - convert $R, $G, $B to hex
    * int_to_dword($n) - returns 4 byte representation of $n
    * int_to_word($n) - returns 2 byte representation of $n
    */

    function freadbyte($f)
    {
     return 
    ord(fread($f,1));
    };

    function 
    freadword($f)
    {
     
    $b1=freadbyte($f);
     
    $b2=freadbyte($f);
     return 
    $b2*256+$b1;
    };


    function 
    freadlngint($f)
    {
    return 
    freaddword($f);
    };

    function 
    freaddword($f)
    {
     
    $b1=freadword($f);
     
    $b2=freadword($f);
     return 
    $b2*65536+$b1;
    };



    function 
    RetBits($byte,$start,$len)
    {
    $bin=decbin8($byte);
    $r=bindec(substr($bin,$start,$len));
    return 
    $r;

    };



    $CurrentBit=0;
    function 
    freadbits($f,$count)
    {
     global 
    $CurrentBit,$SMode;
     
    $Byte=freadbyte($f);
     
    $LastCBit=$CurrentBit;
     
    $CurrentBit+=$count;
     if(
    $CurrentBit==8)
      {
       
    $CurrentBit=0;
      }
     else
      {
       
    fseek($f,ftell($f)-1);
      };
     return 
    RetBits($Byte,$LastCBit,$count);
    };



    function 
    RGBToHex($Red,$Green,$Blue)
      {
       
    $hRed=dechex($Red);if(strlen($hRed)==1$hRed="0$hRed";
       
    $hGreen=dechex($Green);if(strlen($hGreen)==1$hGreen="0$hGreen";
       
    $hBlue=dechex($Blue);if(strlen($hBlue)==1$hBlue="0$hBlue";
       return(
    $hRed.$hGreen.$hBlue);
      };

            function 
    int_to_dword($n)
            {
                    return 
    chr($n 255).chr(($n >> 8) & 255).chr(($n >> 16) & 255).chr(($n >> 24) & 255);
            }
            function 
    int_to_word($n)
            {
                    return 
    chr($n 255).chr(($n >> 8) & 255);
            }


    function 
    decbin8($d)
    {
    return 
    decbinx($d,8);
    };

    function 
    decbinx($d,$n)
    {
    $bin=decbin($d);
    $sbin=strlen($bin);
    for(
    $j=0;$j<$n-$sbin;$j++)
     
    $bin="0$bin";
    return 
    $bin;
    };

    function 
    inttobyte($n)
    {
    return 
    chr($n);
    };

    ?>
    Perchè essere stupidi non è una menomazione ma un diritto di tutti!!!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.