SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: GD Questions

  1. #1
    SitePoint Addict Kokos's Avatar
    Join Date
    Nov 2005
    Location
    The Netherlands
    Posts
    205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    GD Questions

    First, I have some problems when creating security images. For some reason I always have this, when I create too many characters or things with colors the latest characters just turn grey. Heres an example (yes the captcha is weak but its just for showing)


    and another, in some captchas I see that text gets distorted, twisted and such. how do I do that?
    Greets and thanks in advance

    Taking over the web one pixel at a time.
    Currently working @ CodeCreators

  2. #2
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,935
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to post some code.

  3. #3
    SitePoint Addict Kokos's Avatar
    Join Date
    Nov 2005
    Location
    The Netherlands
    Posts
    205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    K, but the wierd thing is that it happens with every color thing I make....

    PHP Code:
        function writeCode(){
            for(
    $i 0;$i $this->iLength;$i++){
                
    $sFont "font.ttf";
                
    $this->iSize rand(14,20);
                
    $sChar_y rand($this->iHeight-15,$this->iHeight-5);
                
    $iAngle rand(-10,10);
                
    $a rand(150,255);
                
    $b rand(150,255);
                
    $c rand(150,255);
                
    $d rand(0,150);
                
    $e rand(0,150);
                
    $f rand(0,150);
                
    $oColor imagecolorallocate($this->oImage,$a,$b,$c);
                
    $oColor2 imagecolorallocate($this->oImage,$d,$e,$f);
                
    imagettftext($this->oImage,$this->iSize,$iAngle,15+($i*$this->iSpacing),$sChar_y+1,$oColor2,$sFont,$this->aCode[$i]);
                
    imagettftext($this->oImage,$this->iSize,$iAngle,15+($i*$this->iSpacing)+1,$sChar_y,$oColor2,$sFont,$this->aCode[$i]);
                
    imagettftext($this->oImage,$this->iSize,$iAngle,14+($i*$this->iSpacing),$sChar_y,$oColor,$sFont,$this->aCode[$i]);
            }
        } 
    this is the part of my class that writes the code to the image

    Taking over the web one pixel at a time.
    Currently working @ CodeCreators

  4. #4
    SitePoint Addict Kokos's Avatar
    Join Date
    Nov 2005
    Location
    The Netherlands
    Posts
    205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nobody?

    Taking over the web one pixel at a time.
    Currently working @ CodeCreators

  5. #5
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,935
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your code is OOP and you have only posted one method. That makes it impossible for anyone to run the code.

  6. #6
    SitePoint Addict Kokos's Avatar
    Join Date
    Nov 2005
    Location
    The Netherlands
    Posts
    205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    K Ill give the full code, just didnt think it mattered:

    PHP Code:
    class captcha{
        var 
    $oImage;
        var 
    $iWidth;
        var 
    $iHeight;
        var 
    $iLength;
        var 
    $iSize;
        var 
    $iSpacing;
        var 
    $aCode;

        function 
    setVars(){
            
    $this->iWidth 100;
            
    $this->iHeight 35;
            
    $this->iLength 4;
            
    $this->iSpacing = ($this->iWidth/$this->iLength)-6;
        }
        
        function 
    setImage(){
            
    $this->oImage imagecreate($this->iWidth,$this->iHeight);
            
    imagecolorallocate($this->oImage,230,230,230);
        }
        
        function 
    setBorder(){
            
    $oColor imagecolorallocate($this->oImage,160,160,160);
            
    imageline($this->oImage,0,0,0,$this->iHeight,$oColor);
            
    imageline($this->oImage,0,0,$this->iWidth,0,$oColor);
            
    imageline($this->oImage,$this->iWidth-1,0,$this->iWidth-1,$this->iHeight-1,$oColor);
            
    imageline($this->oImage,0,$this->iHeight-1,$this->iWidth-1,$this->iHeight-1,$oColor);
        }
        
        function 
    genCode(){
            
    $aChars = array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","1","2","3","4","5","6","7","8","9");
            
    $iTotal count($aChars);
            for(
    $i 0;$i $this->iLength;$i++){
                
    $x rand(1,$iTotal);
                
    $aChar $aChars[$x];
                
    $this->aCode[$i] = $aChar;
            }
            return 
    $this->aCode;
        }
        
        function 
    genNoise(){
            
    imagefilter($this->oImage,IMG_FILTER_MEAN_REMOVAL);
            
    imagefilter($this->oImage,IMG_FILTER_EDGEDETECT);
        }
        
        function 
    writeCode(){
            for(
    $i 0;$i $this->iLength;$i++){
                
    $sFont "font.ttf";
                
    $this->iSize rand(14,20);
                
    $sChar_y rand($this->iHeight-15,$this->iHeight-5);
                
    $iAngle rand(-10,10);
                
    $a rand(150,255);
                
    $b rand(150,255);
                
    $c rand(150,255);
                
    $d rand(0,150);
                
    $e rand(0,150);
                
    $f rand(0,150);
                
    $oColor imagecolorallocate($this->oImage,$a,$b,$c);
                
    $oColor2 imagecolorallocate($this->oImage,$d,$e,$f);
                
    imagettftext($this->oImage,$this->iSize,$iAngle,15+($i*$this->iSpacing),$sChar_y+1,$oColor2,$sFont,$this->aCode[$i]);
                
    imagettftext($this->oImage,$this->iSize,$iAngle,15+($i*$this->iSpacing)+1,$sChar_y,$oColor2,$sFont,$this->aCode[$i]);
                
    imagettftext($this->oImage,$this->iSize,$iAngle,14+($i*$this->iSpacing),$sChar_y,$oColor,$sFont,$this->aCode[$i]);
            }
        }
        
        function 
    createImage(){
            
    $this->setVars();
            
    $this->setImage();
            
    $this->setBorder();
            
    $this->genCode();
            
    $this->writeCode();
            
    //$this->genNoise();
            
    imagepng($this->oImage,"image.png");
            
    imagedestroy($this->oImage);
            return 
    implode('',$this->aCode);
        }


    Taking over the web one pixel at a time.
    Currently working @ CodeCreators

  7. #7
    SitePoint Addict Kokos's Avatar
    Join Date
    Nov 2005
    Location
    The Netherlands
    Posts
    205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    :O need help

    Taking over the web one pixel at a time.
    Currently working @ CodeCreators


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •