<?php
	//在线拍照设置
	//相框所在文件夹名

$width = $_POST["width"];
$height = $_POST["height"];
$colors =$_POST["image"]; 

function hex2rgb($color)
{
	return array(hexdec(substr($color, 0, 2)), hexdec(substr($color, 2, 2)), hexdec(substr($color, 4, 2)));	
}
	
$im = imagecreatetruecolor($width, $height);
imagecolorallocate($im, 255, 255, 255);

$pixs = explode(",", $colors);
array_pop($pixs);

$x = 0;
$y = 0;

$im1 = imagecreate(1, 1);

foreach ($pixs as $p)
{
	list($r, $g, $b) = hex2rgb($p);

	$_color = imagecolorallocate($im, $r, $g, $b);
	imagesetpixel($im, $x, $y, $_color);
	
	$x ++;
	if ($x == $width)
	{
		$x = 0;
		$y += 1;
	}
}
$filename=time().".jpg";

if(!imagejpeg($im,"image/".$filename)){
	echo "图片生成错误";
}
Header("location: userpicsave.asp?filename={$filename}"); 



?>
