<?php
error_reporting(0);
$w = (int)$_POST['width'];
$h = (int)$_POST['height'];
$img = imagecreatetruecolor($w, $h);
imagefill($img, 0, 0, 0x669966);
$rows = 0;
$cols = 0;
for($rows = 0; $rows < $h; $rows++){
	$c_row = explode(",", $_POST['px' . $rows]);
	for($cols = 0; $cols < $w; $cols++){
		$value = $c_row[$cols];
		if($value != ""){
			$hex = $value;
			while(strlen($hex) < 6){
				$hex = "0" . $hex;
			}
			$r = hexdec(substr($hex, 0, 2));
			$g = hexdec(substr($hex, 2, 2));
			$b = hexdec(substr($hex, 4, 2));
			$test = imagecolorallocate($img, $r, $g, $b);
			imagesetpixel($img, $cols, $rows, $test);
		}
	}
}
$textcolor = imagecolorallocate($img, 0, 0, 0);
imagestring($img, 2, $w-90, $h-15, "chat.qxnzx.com", $textcolor);
$randname=time().rand(10,99);
$filename="upfiles/".$randname.".jpg";

imagejpeg($img, $filename, 100);
//Ιϊ³ΙΛυΒΤΝΌ
$image_p = imagecreatetruecolor(76, 58);
$filename_p="upfiles/x/".md5($_GET['UserName'])."_".$randname.".jpg";
imagecopyresampled($image_p, $img, 0, 0, 0, 0, 76, 58, $w, $h);
imagejpeg($image_p, $filename_p, 100);
//end
imagedestroy($img);
imagedestroy($image_p);
header("Location: view.php?UserName=".$_GET['UserName']);

?>