+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: My latest PHP creation

  1. #1
    KentonBomb's Avatar
    KentonBomb is offline x10Hosting Member KentonBomb is an unknown quantity at this point
    Join Date
    Feb 2008
    Posts
    42

    My latest PHP creation

    I'm going into hardcore PHP mode now. Since linux has taken my life over, I find web based scripting much more appealing that writing windows programs to use over Wine.

    This is my latest PHP Creation. It's a random image generator.



    Refresh to see a new image.

    This is the source:
    PHP Code:
    <?php
    /*
    Random Textalizer
    */
    $img imagecreate(22020);
    $black imagecolorallocate($img000);
    $white imagecolorallocate($img255255255);
    imagefill($img00$black);
    $file "random.txt";
    $hnd fopen($file"r");
    $strings fread($hndfilesize($file));
    $array explode(","$strings);
    $ret count($array);
    $num rand(1$ret);

    $string $array[$num];    
    imagestring($img222$string$white);    
    header("Content-type: image/png");
    imagepng($img);
    imagedestroy($img);

    ?>
    As you can see, it reads the number of entries in a txt file named "random.txt". It dynamically generates the image based on the number of entries in the text file (Each entry is separated by a comma)

    An example random.txt would be:

    Code:
    Hello!, Bon Jour, Hola!, Konnichiwa!, Ni Hao!
    This would randomly say hello in a few different languages (Note:: I don't care if I spelled any of those incorrectly :P)

    Feedback?

  2. #2
    Brandon's Avatar
    Brandon is offline Former Senior Account Rep Brandon is on a distinguished road
    Join Date
    Jun 2006
    Location
    Tewksbury, MA
    Posts
    9,589

    Re: My latest PHP creation

    That's cool, I am working on an image creation class currently too, if you want to check it out it's here: http://brandonsgames.com/source/sigclass.
    Thanks,
    Brandon Long

  3. #3
    VPmase's Avatar
    VPmase is offline x10 Elder VPmase is an unknown quantity at this point
    Join Date
    Nov 2007
    Location
    Dixon, IL, USA
    Posts
    914

    Re: My latest PHP creation

    Not bad for a first. You can end up making Captcha images with GD too.
    (Demo) The site isn't done yet but the captcha works perfectly.

    Page containing captcha
    PHP Code:
    <?
        session_cache_limiter
    ("private_no_expire, must-revalidate");
        
    session_start();
        
    $ip $_SERVER['REMOTE_ADDR'];
        
    $alphabet = 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''0');
        
    srand(time());
        
    $randstr "";
        for (
    $i=0$i<10$i++){
            
    $random = (rand() % sizeof($alphabet));
            
    $randstr .= $alphabet[$random];
        }
        
    $_SESSION["capval" $ip] = $randstr;
    ?>
    <html>
    <head>
    <title>Captcha</title>
    </head>
    <body>
    <img src="capimg.php" />
    </body>
    </html>
    capimg.php
    PHP Code:
    <?
        session_cache_limiter
    ("private_no_expire, must-revalidate");
        
    session_start();
        
    $ip $_SERVER['REMOTE_ADDR'];
        
    $randstr $_SESSION["capval" $ip];
        
    header ("Content type: image/jpeg");
        
    $im = @imagecreatetruecolor(10025) or die("Cannot Initialize new GD image stream");
        
    $text_color imagecolorallocate($im255255255);
        
    imagestring($im2105,  $randstr$text_color);
        
    imagejpeg($im''100);
        
    imagedestroy($im);
    ?>
    Last edited by VPmase; 02-24-2008 at 04:51 PM.

  4. #4
    medphoenix's Avatar
    medphoenix is offline x10 Lieutenant medphoenix is an unknown quantity at this point
    Join Date
    Sep 2007
    Posts
    354

    Re: My latest PHP creation

    Try this....

    can you make the background as noisy-one like in captcha images. (instead of pure black - you can use noisy or grain background)...
    Last edited by medphoenix; 02-24-2008 at 05:41 PM.

  5. #5
    VPmase's Avatar
    VPmase is offline x10 Elder VPmase is an unknown quantity at this point
    Join Date
    Nov 2007
    Location
    Dixon, IL, USA
    Posts
    914

    Re: My latest PHP creation

    You just have to use
    PHP Code:
    $im = @imagecreatefromjpeg('jpg.jpeg'
    http://us3.php.net/manual/en/functio...tefromjpeg.php

    Instead of $im = @imagecreatetruecolor
    Last edited by VPmase; 02-24-2008 at 06:27 PM.

  6. #6
    Jesse's Avatar
    Jesse is offline Lord Of The Keys Jesse is an unknown quantity at this point
    Join Date
    Oct 2007
    Location
    Manila, PH
    Posts
    1,357

    Re: My latest PHP creation

    Thanks for the tut.
    x10HOSTING
    Member Since October 2007.

    JESSEMAN.ME
    | iMusicz.net

  7. #7
    sunils's Avatar
    sunils is offline x10 Spammer sunils is an unknown quantity at this point
    Join Date
    Jan 2008
    Location
    Chennai ,India
    Posts
    2,264

    Re: My latest PHP creation

    Good one. These days members are trying to create dynamic signature........
    [LEFT][B]Sunil Sankar
    -------------------------------------------------------------------------

  8. #8
    Brandon's Avatar
    Brandon is offline Former Senior Account Rep Brandon is on a distinguished road
    Join Date
    Jun 2006
    Location
    Tewksbury, MA
    Posts
    9,589

    Re: My latest PHP creation

    Mines going to be pretty cool when it's done I hope.
    Thanks,
    Brandon Long

  9. #9
    diabolo's Avatar
    diabolo is offline Community Advocate diabolo is on a distinguished road
    Join Date
    Nov 2007
    Location
    Jersey Shore
    Posts
    1,683

    Re: My latest PHP creation

    Quote Originally Posted by VPmase View Post
    You just have to use
    PHP Code:
    $im = @imagecreatefromjpeg('jpg.jpeg'
    http://us3.php.net/manual/en/functio...tefromjpeg.php

    Instead of $im = @imagecreatetruecolor

    you can also use imagecreatefrompng, or gif, and a couple others

  10. #10
    Join Date
    Aug 2007
    Location
    Gangstas Paradise
    Posts
    4,143

    Re: My latest PHP creation

    uhm... am I the only one that sees a red cross where that image is supposed to be ?

    P.S. Check out my dynamic sig ;p

    http://dev.x10hosting.com (this has nothing to do with x10hosting)

    ->All us helpful people here at x10hosting would like to reach our next user groups, "Community Paragon". Please click the +rep icon on the left hand side of a post if that post was helpfull.



+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. tons of PHP Resources
    By Chris S in forum Scripts & 3rd Party Apps
    Replies: 10
    Last Post: 01-16-2009, 10:07 AM
  2. Unstand PHP?
    By o0slowpaul0o in forum Tutorials
    Replies: 8
    Last Post: 01-07-2008, 09:16 PM
  3. Sigo con problemas con phpbb2
    By reciecho in forum Soporte
    Replies: 7
    Last Post: 10-20-2007, 06:28 PM
  4. "PHP Startup: Invalid Library" - Interesting error
    By javaguy78 in forum Free Hosting
    Replies: 5
    Last Post: 03-27-2007, 02:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers