I am not sure what is the problem but I suggest that you define a function to generate the clan info image:
function clanInfoImage($clan_page_info) {
$pattern = '/Record: ([0-9-]+).*?World Rank: ([0-9]+).*?Regional Rank: ([0-9]+)/s';
preg_match($pattern, $clan_page_info, $matches);
list(, $record, $world_rank, $regional_rank) = $matches;
$top100 = "100";
// load the image from the file specified:
if ($world_rank <= $top100) {
$im = imagecreatefrompng("box1_top100.png");
} else {
$im = imagecreatefrompng("box1.png");
}
// if there's an error, stop processing the page:
if(!$im)
{
die("");
}
// define some colours to use with the image
$yellow = imagecolorallocate($im, 255, 255, 0);
$black = imagecolorallocate($im, 0, 0, 0);
// get the width and the height of the image
$width = imagesx($im);
$height = imagesy($im);
// draw a black rectangle across the bottom, say, 20 pixels of the image:
// now we want to write in the centre of the rectangle:
$font = 2; // store the int ID of the system font we're using in $font
$text1 = $record; // store the text we're going to write in $text
// calculate the left position of the text:
$leftTextPos = ( $width - imagefontwidth($font)*strlen($text) )/3.3;
// finally, write the string:
imagestring($im, $font, $leftTextPos, $height-77, $text1, $yellow);
$font = 2; // store the int ID of the system font we're using in $font
$text2 = $world_rank; // store the text we're going to write in $text
// calculate the left position of the text:
$leftTextPos = ( $width - imagefontwidth($font)*strlen($text) )/2.3;
// finally, write the string:
imagestring($im, $font, $leftTextPos, $height-62, $text2, $yellow);
$font = 2; // store the int ID of the system font we're using in $font
$text3 = $regional_rank; // store the text we're going to write in $text
// calculate the left position of the text:
$leftTextPos = ( $width - imagefontwidth($font)*strlen($text3) )/1.9;
// finally, write the string:
imagestring($im, $font, $leftTextPos, $height-49, $text3, $yellow);
// output the image
// tell the browser what we're sending it
Header('Content-type: image/png');
// output the image as a png
imagepng($im);
// tidy up
imagedestroy($im);
}
Then, use that function:
if (!empty($_POST['clan_page']))
{
$clanpage = $_POST["clan_page"];
$source = file_get_contents("http://ops.warrock.net/showclan.aspx?c=$clanpage");
clanInfoImage($source);
}
else
{
echo 'No clan page provided.';
}