SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict Smolf3d's Avatar
    Join Date
    Aug 2004
    Location
    russia
    Posts
    224
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    image verification - question

    Ok this is a script

    vImage.php
    PHP Code:
    <?
    class vImage{

            var 
    $numChars 3# Tamanho da String: default 3;
            
    var $w# Largura da imagem
            
    var $h 20# Altura da Imagem: default 15;
            
    var $colBG "188 220 231";
            var 
    $colTxt "0 0 0";
            var 
    $colBorder "0 128 192";
            var 
    $charx 20# Espaзo lateral de cada char
            
    var $numCirculos 10#Numeros de circulos randomicos


            
    function vImage(){
                    
    session_start();
            }

            function 
    gerText($num){
                    
    # receber tamanho da string
                    
    if ($num != ''$this->numChars $num;
                    
    # gerar string randmica
                    
    $this->texto $this->gerString();

                    
    $_SESSION['vImageCodS'] = $this->texto;
            }

            function 
    loadCodes(){
                    
    $this->postCode $_POST['vImageCodP'];
                    
    $this->sessionCode $_SESSION['vImageCodS'];
            }

            function 
    checkCode(){
                    if (isset(
    $this->postCode)) $this->loadCodes();
                    if (
    $this->postCode == $this->sessionCode)
                            return 
    true;
                    else
                            return 
    false;
            }

            function 
    showCodBox($mode=0,$extra=''){
                    
    $str "<input type=\"text\" name=\"vImageCodP\" ".$extra." > ";

                    if (
    $mode)
                            echo 
    $str;
                    else
                            return 
    $str;
            }

            function 
    showImage(){


                    
    $this->gerImage();

                    
    header("Content-type: image/png");
                    
    ImagePng($this->im);

            }

            function 
    gerImage(){
                    
    # Calcular tamanho para caber texto
                    
    $this->= ($this->numChars*$this->charx) + 40#5px de cada lado, 4px por char
                    # Criar img
                    
    $this->im imagecreatetruecolor($this->w$this->h);
                    
    #desenhar borda e fundo
                    
    imagefill($this->im00$this->getColor($this->colBorder));
                    
    imagefilledrectangle $this->im11, ($this->w-2), ($this->h-2), $this->getColor($this->colBG) );

                    
    #desenhar circulos
                    
    for ($i=1;$i<=$this->numCirculos;$i++) {
                            
    $randomcolor imagecolorallocate ($this->im rand(100,255), rand(100,255),rand(100,255));
                            
    imageellipse($this->im,rand(0,$this->w-10),rand(0,$this->h-3), rand(20,60),rand(20,60),$randomcolor);
                    }
                    
    #escrever texto
                    
    $ident 20;
                    for (
    $i=0;$i<$this->numChars;$i++){
                            
    $char substr($this->texto$i1);
                            
    $font rand(4,5);
                            
    $y round(($this->h-15)/2);
                            
    $col $this->getColor($this->colTxt);
                            if ((
    $i%2) == 0){
                                    
    imagechar $this->im$font$ident$y$char$col );
                            }else{
                                    
    imagecharup $this->im$font$ident$y+10$char$col );
                            }
                            
    $ident $ident+$this->charx;
                    }

            }

            function 
    getColor($var){
                    
    $rgb explode(" ",$var);
                    
    $col imagecolorallocate ($this->im$rgb[0], $rgb[1], $rgb[2]);
                    return 
    $col;
            }

            function 
    gerString(){
                    
    rand(0,time());
                    
    $possible="1234578";
                    while(
    strlen($str)<$this->numChars)
                    {
                                    
    $str.=substr($possible,(rand()%(strlen($possible))),1);
                    }

                    
    $txt $str;

                    return 
    $txt;
            }
    }

    ?>
    img.php
    PHP Code:
    <? 

    include("vImage.php"); 

    $vImage = new vImage(); 
    $vImage->gerText($_GET['size']); 
    $vImage->showimage(); 

    ?>
    My question is: How to change the alphabet for other language (German, Russian) instead of English ?

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    $possible="1234578";
    It's using numbers, not letters, anyway. Just replace that string with whatever letters you want it to pull from.

  3. #3
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Plano
    Posts
    643
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    like dan said...this script isn't generating letters from the english alphabet, its using numbers. did you test this script out yourself before asking this question?


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
  •