Skip to content
MPGHThe Dark Arts
/
RegisterLog in
Forum
Community
What's NewLatest posts across the boardTrendingHottest threads right nowSubscribedThreads you follow
Discussion
GeneralIntroductionsEntertainmentDebate FortFlaming & Rage
Board
News & AnnouncementsMPGH TimesSuggestions & HelpGiveaways
More Sections
Art & Graphic DesignProgrammingHackingCryptocurrency
Hacks & Cheats
Games
ValorantCS2 / CS:GOCall of Duty / WarzoneFortniteApex LegendsEscape From Tarkov
+14 moreLeague of LegendsGTA VMinecraftRustROTMGBattlefieldTroveBattleOnCombat ArmsCrossFireBlackshotRuneScapeDayZDead by Daylight
Resources
Game Hacking TutorialsReverse EngineeringGeneral Game HackingAnti-CheatConsole Game Hacking
Tools
Game Hacking ToolsTrainers & CheatsHack/Release NewsNew
Submit a release →Share your cheat, tool, or config with the community.
AINEW
AI Tools
General & DiscussionPrompt EngineeringLLM JailbreaksHotAI Agents & AutomationLocal / Open Models
AI × Gaming
AI Aimbots & VisionML Anti-CheatGame Bots & Automation
Create
AI Coding / Vibe CodingAI Art & MediaAI Voice & TTS
The AI frontier →Where game hacking meets modern machine learning. Jump in.
Marketplace
Buy & Sell
SellingBuyingTradingUser Services
Trust & Safety
Middleman LoungeMarketplace TalkVouch Copy Profiles
Money
Cryptocurrency TalkCurrency ExchangeWork & Job Offers
Start selling →List accounts, services, and goods. Use the middleman to trade safe.
MPGH The Dark Arts

A community for offensive security research, reverse engineering, and AI.

Community

ForumMarketplaceSearch

Account

RegisterLog in

Legal

Privacy PolicyForum RulesHelp & FAQ
© 2026 MPGH · All rights reserved.Built by the community, for the community. For educational purposes onlyContent is shared for security research and education — we don't condone illegal use. You're responsible for complying with applicable laws. Use at your own risk.
Home › Forum › Programming › Other Programming › PHP Programming › PHP Random Text to Image (Captcha Generator)

PostPHP Random Text to Image (Captcha Generator)

Posts 1–2 of 2 · Page 1 of 1
CW
CwDirectly
PHP Random Text to Image (Captcha Generator)
So this is both a release and tutorial for the people newer to PHP. Below is the source code and it is very well commented. The function only creates a random string of characters from a source and puts it into an image using a font file as well. This also allows you to expand on and change things around such as colors, characters used, the length of the text etc.

Like I stated it does not currently have a direct use but makes for a good base to learn a little on and plenty of room to expand on it. This is just one of my many projects I jump between. I do intend on making an admin page to make changes and a demo contact form that will validate the input so it will be more directly and immediately usable. Pretty basic right now.

(The link to the font file used is included in the comments or you can use any .ttf file. As long as it supports all the characters used.

Code:
<?php

function Generate() {

    // Set the content-type to display the image properly.
    header('Content-type: image/png');

    // Create the image. imagecreatetruecolor(Width, Height);
    $image = imagecreatetruecolor(400, 30);

    // Set the colors to be used. These use RGB color codes.
    // View the following link to easliy find RGB color codes:
    // http://www.color-he*****m/
    $white = imagecolorallocate($image, 255, 255, 255); // Used for the background fill, see below. (Default White = 255, 255, 255)
    $text_shadow = imagecolorallocate($image, 128, 128, 128); // Used for the text shadowing, see below. (Default Gray = 128, 128, 128)
    $text_color = imagecolorallocate($image, 0, 0, 0); // Used for the text color, see below. (Default Black = 0, 0, 0)
    
    imagefilledrectangle($image, 0, 0, 399, 29, $white); // Fills the background in white.

    // Call for the random text to be used and set the value.
    $text = RandomText();

    // You may change this to your own .ttf font file.
    // Thanks and credit to the following website and author for this great default font!
    // http://www.dafon*****m/chaos-times.font
    $font = 'ChaosTimes_lig.ttf';

    // Adds gray shadowing to the text, using the $text_shadow color.
    // This also adds slightly more distortion to the image, making it
    // slightly more difficult.
    imagettftext($image, 20, 0, 11, 21, $text_shadow, $font, $text);

    // Random text and colors have been set, time to put it all together.
    // This is also where we use $text_color to set the font color.
    imagettftext($image, 20, 0, 10, 20, $text_color, $font, $text);

    // Using imagepng() results in clear text compared to imagejpeg().
    // If you wanted to distort the image even more, you could use
    // imagejpeg($im); in place of the following.  Be sure to update
    // header('Content-type: image/png'); TO header('Content-type: image/jpeg');
    imagepng($image);
    imagedestroy($image);
}

// Randomly generates the text to be shown.
// The following line is also where to edit the different values,
// such as the $length which is how long the captcha will be.
// Also $chars which contains all the things to use in the captcha.
function RandomText($length = 8, $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") {
    $charl = strlen($chars); // Here we get the length of $chars, used to create random text from it.
    $string = ''; // Make sure the string is empty. Shouldn't normally be required but a good habit.
    
    for ($i=0; $i<$length; $i++) { // If you require some explaining here please view: https://goo .gl/yYjC2j
        $string .= $chars[rand(0, $charl - 1)]; // Set $string to random text using $chars as the text options.
    }
    return $string; // Return the random text generated.
}
// Output the finished image
echo Generate();
?>
#1 · edited 10y ago · 10y ago
MI
michaelfraz
thanks for sharing
#2 · 10y ago
Posts 1–2 of 2 · Page 1 of 1

Post a Reply

Similar Threads

  • [Release] xD Captcha GeneratorBy Hassan in Visual Basic Programming
    11Last post 16y ago
  • Text title+Image TitleBy Jov in Profile Edit Requests
    1Last post 12y ago
  • text and image titleBy AirCanada in Profile Edit Requests
    3Last post 13y ago
  • Text title + Image TitleBy Janitor in Profile Edit Requests
    2Last post 14y ago
  • [SOLVED] image code generator ?By allie966 in CrossFire Help
    7Last post 16y ago

Tags for this Thread

#captcha#php#tutorial or release