<?php
session_start();
header("Content-type: image/png");

$img_handle = imageCreateFromPNG("bg2.PNG");

$q = rand(1,255);
$w = rand(1,255);
$e = rand(1,255);
$r = rand(1,255);
$t = rand(1,255);
$y = rand(1,255);
$u = rand(1,255);
$i = rand(1,255);
$color[0] = ImageColorAllocate ($img_handle, $q, 0, 100); 
$color[1] = ImageColorAllocate ($img_handle, 200, 0, 0);
$color[2] = ImageColorAllocate ($img_handle, 0, $w, 100);
$color[3] = ImageColorAllocate ($img_handle, 200, 0, 0);
$color[4] = ImageColorAllocate ($img_handle, 0, $e, 100);
$color[5] = ImageColorAllocate ($img_handle, 200, 0, 0);
$color[6] = ImageColorAllocate ($img_handle, 0, $r, $y);
$color[7] = ImageColorAllocate ($img_handle, 0, $t, 100);
$color[8] = ImageColorAllocate ($img_handle, 200, 0, 0);
$color[9] = ImageColorAllocate ($img_handle, $u, $y, 100);
$color[10] = ImageColorAllocate ($img_handle, 200, 0, 0);
$color[11] = ImageColorAllocate ($img_handle, 0, $u, 100);
$color[12] = ImageColorAllocate ($img_handle, 0, $i, 100);
$rkey=trim($_SESSION['rkey']); 
$characters=str_split($rkey); 
$x=30; 
$j=0; 
for($i=0;$i<count($characters);$i++)
{
    ImageString($img_handle, 5, $x, 13, $characters[$i], $color[$j]);
    $x=$x+7;
    $j=$j+1;
    if($j==13) 
        $j=0;
}
Imagepng($img_handle, '/bg2.png');
ImageDestroy($img_handle);
?>

above is my code. Currently when i run my program it overrides the original file and inserts numbers into it. However when i run it again, it inserts another set of new numbers into the image making it messy. Is there any way to delete the existing numbers and create a new image?

Thanks
Danny

Hi there,
You could try the following function:
imagefill ( resource $image , int $x , int $y , int $color );
Where $x and $y are the top left coordinates where the filling starts, and just fill the image with white.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.