Find your favorite captcha script, and change the line that outputs to save, put it in a loop and save the answers and filenames, here is an example (missing the code that actually makes a captcha):
<?php
set_time_limit(0); // Disable time limit
$dir = 'D:\\pre-rendered_captchas\\'; // Directory to store the images
$num = 10000; // Number of images to make
$file = fopen($dir.'captcha_key.txt','w');
for( $i=0; $i<$num; $i++ ) {
$filename = substr( hash( 'sha256', $i.rand(100,1000).$i ),0,16 ) .'.png'; // Create a unique filename
$img = imagecreate(300,60); // Create the image for the captcha
// Generate random letters store in $answer and create captcha image in $img
imagepng($img,$dir.$filename); // save captcha to disk instead of outputting
fputcsv($file,array($filename,$answer)); // save filename and answer
unset($img);
unset($filename);
}
fclose($file);
A database is probably better suited for saving the filename/answer pairs. Here is how you would output the image using the prerendered with listing in a file:
$captchas = file('D:\\pre-rendered_captchas\\captcha_key.txt');
$captchas = $captchas[ array_rand($captchas) ];
list($captchas,$_SESSION['captcha_answer']) = explode(',',$captchas);
header('Content-Type: image/png');
$img = imagecreatefrompng($captchas);
imagepng($img);