<?php
//$s=file_get_contents('http://www.mingpian.sh/GetText.aspx?'. $_SERVER['QUERY_STRING'], 'r');
//$s=@file_get_contents('http://demo.v5print.com/BusinessCard/AjaxPage/GetText.ashx?'. $_SERVER['QUERY_STRING'], 'r');
$s1=@file_get_contents('http://www.aliyin.com/GetText.aspx?'. $_SERVER['QUERY_STRING'], 'r');
//http://www.aliyin.com/GetText.aspx?
//$s2=@file_get_contents('http://www.mingpian.sh/GetText.aspx?'. $_SERVER['QUERY_STRING'], 'r');
//$s3=$s1?$s1:$s2?$s2:$s;
if ($s1){
  echo $s1;
}else{
 

/******************************
*
*  Written by John Minton
*  http://iluvjohn.com/
*
*  PHP TTF Text<->Image
*  This script returns a PNG image file format.
*
*  You use this script in an HTML document the same as
*  you would add an image using the <img src="image.png" />
*  tag. But we also pass the script some variables to change
*  what it outputs to the screen.
*
*  Example Usages
*
*  <img src="text-image.php?text=Welcome Home" />
*
* License: Attribution-Noncommercial-Share Alike 3.0 Unported
* (http://creativecommons.org/licenses/by-nc-sa/3.0/)
*  If you have a need that doesn't fit the license above,
*  contact me via http://iluvjohn.com/
*AjaxPage/gettext.php?Text="2"&FontName="2"&FontSize="2"&RGBColor="2"&Fontweight="2"&Fontstyle="2";
*****************************/
$settings['text'] =empty($_GET['Text'])?"": htmlspecialchars(trim($_GET['Text']));
//$settings['ttf'] =empty($_GET['FontName'])?"方正楷体": str_replace("..","",htmlspecialchars(trim($_GET['FontName'])));
$settings['font-size'] =empty($_GET['FontSize'])?"": htmlspecialchars(trim($_GET['FontSize']));
$settings['size']['x'] =empty($_GET['sizex'])?"": htmlspecialchars(trim($_GET['sizex']));
$settings['size']['y'] =empty($_GET['sizey'])?"": htmlspecialchars(trim($_GET['sizey']));
$settings['position']['x'] =empty($_GET['Fontstyle'])?"": htmlspecialchars(trim($_GET['Fontstyle']));
$settings['position']['y'] =empty($_GET['posy'])?"": htmlspecialchars(trim($_GET['Fontstyle']));
//$settings['transparent-background'] =empty($_GET['Fontweight'])?"": htmlspecialchars(trim($_GET['Fontweight']));
//$settings['bgcolor'] =empty($_GET['Fontstyle'])?"": htmlspecialchars(trim($_GET['Fontstyle']));
$settings['fontcolor'] =empty($_GET['RGBColor'])?"": htmlspecialchars(trim($_GET['RGBColor']));

//$settings['ttf']=$ttf.$settings['ttf'].".ttf";//"../fonts/方正楷体.ttf";//$ttf.$settings['ttf'].".ttf";
// This file
$script_name = $_SERVER["SCRIPT_NAME"];

// Set some defaults so you don't need to specify it all every time you use the script!
if(empty($settings['text'])){
$settings['text'] = "";
$settings['size']['x'] = "20";
$settings['size']['y'] = "30";
}

if(empty($settings['ttf'])){$settings['ttf'] = "../fonts/fz.TTF";}
if(empty($settings['font-size'])){$settings['font-size'] = "12";}
if(empty($settings['size']['x'])){$settings['size']['x'] = "220";}
if(empty($settings['size']['y'])){$settings['size']['y'] = "30";}
if(empty($settings['position']['x'])){$settings['position']['x'] = "1";}
if(empty($settings['position']['y'])){$settings['position']['y'] = "30";}
if(empty($settings['transparent-background'])){$settings['transparent-background'] = "y";}
if(empty($settings['bgcolor'])){$settings['bgcolor'] = "ffffff";}
if(empty($settings['fontcolor'])){$settings['fontcolor'] = "#000000";}

$margin = GetImageSizeForTextBlock(0, $settings['text'], $settings['ttf'], $settings['font-size']);
$settings['size']['x']=$margin['WIDTH'];
$settings['size']['y']=$margin['HEIGHT'];
$settings['position']['x']=$margin['X_POS'];
$settings['position']['y']=$margin['Y_POS'];
// Now we are going to get on with the script, prepair some data
// hexdec() converts hex number format to decimal
$settings['background'][0] = hexdec($settings['bgcolor'][0].$settings['bgcolor'][1]); // Red
$settings['background'][1] = hexdec($settings['bgcolor'][2].$settings['bgcolor'][3]); // Green
$settings['background'][2] = hexdec($settings['bgcolor'][4].$settings['bgcolor'][5]); // Blue

$settings['foreground'][0] = hexdec($settings['fontcolor'][1].$settings['fontcolor'][2]); // Red
$settings['foreground'][1] = hexdec($settings['fontcolor'][3].$settings['fontcolor'][4]); // Green
$settings['foreground'][2] = hexdec($settings['fontcolor'][5].$settings['fontcolor'][6]); // Blue

$img = imagecreate($settings['size']['x'],$settings['size']['y']);

if($settings['transparent-background'] == "y"){
imagesavealpha($img, true);
imagealphablending($img, false);
$transparent_background = imagecolorallocatealpha($img, 200, 200, 200, 127);
imagefill($img, 0, 0, $transparent_background);
}else{
$background = imagecolorallocate($img,$settings['background'][0],$settings['background'][1],$settings['background'][2]);
}

$font_color = imagecolorallocate($img,$settings['foreground'][0],$settings['foreground'][1],$settings['foreground'][2]);
imagettftext($img,$settings['font-size'],0,$settings['position']['x'],$settings['position']['y'],$font_color,$settings['ttf'],$settings['text']);

//header("Content-type: image/png");
echo imagepng($img);

imagecolordeallocate($background,$img);
imagedestroy($img);


}
//计算文本框大小
function GetImageSizeForTextBlock($rotateDegrees, $TextString, $fontLocation, $fontSize){

//这将添加一个文本块小边缘区域。
//字体大小的控制。
	$margin = intval(0.25 * $fontSize);

	//转换角度这总是一个0到359之间的数字
	if($rotateDegrees > 359 || $rotateDegrees < -359){
		$rotateDegrees = intval($rotateDegrees % 360);
	}
	if($rotateDegrees < 0){
		$rotateDegrees = 360 + $rotateDegrees;
	}

	$TextString = preg_replace("/(\n|\r)/", "", $TextString);


	//总大小的文本块,以便我们知道多大创建图像
	$TextBoxSize = imagettfbbox($fontSize, $rotateDegrees, $fontLocation, preg_replace("/-br-/", "\n\r", $TextString));

	//把变量放在读者友好的变量
	$TxtBx_Lwr_L_x = $TextBoxSize[0];
	$TxtBx_Lwr_L_y = $TextBoxSize[1];
	$TxtBx_Lwr_R_x = $TextBoxSize[2];
	$TxtBx_Lwr_R_y = $TextBoxSize[3];
	$TxtBx_Upr_R_x = $TextBoxSize[4];
	$TxtBx_Upr_R_y = $TextBoxSize[5];
	$TxtBx_Upr_L_x = $TextBoxSize[6];
	$TxtBx_Upr_L_y = $TextBoxSize[7];

	//文本框坐标是相对于字体,无论角度
//我们需要找出文本框的高度和宽度占旋转
	if($rotateDegrees <= 90 || $rotateDegrees >= 270 ){
		$TextBox_width= max($TxtBx_Lwr_R_x, $TxtBx_Upr_R_x) - min($TxtBx_Lwr_L_x, $TxtBx_Upr_L_x);
		$TextBox_height= max($TxtBx_Lwr_L_y, $TxtBx_Lwr_R_y) - min($TxtBx_Upr_R_y, $TxtBx_Upr_L_y);

		//这数据坐标文本块的第一个字母开始
//这是大约左下角的信
		$Start_Text_Coord_x = -(min($TxtBx_Upr_L_x, $TxtBx_Lwr_L_x));
		$Start_Text_Coord_y = -(min($TxtBx_Upr_R_y, $TxtBx_Upr_L_y));
	}
	else{
		$TextBox_width= max($TxtBx_Lwr_L_x, $TxtBx_Upr_L_x) - min($TxtBx_Lwr_R_x, $TxtBx_Upr_R_x);
		$TextBox_height= max($TxtBx_Upr_R_y, $TxtBx_Upr_L_y) - min($TxtBx_Lwr_L_y, $TxtBx_Lwr_R_y);

		$Start_Text_Coord_x = -(min($TxtBx_Lwr_R_x,$TxtBx_Upr_R_x));
		$Start_Text_Coord_y = -(min($TxtBx_Lwr_L_y, $TxtBx_Lwr_R_y));
	}

	// 我们需要添加第一个字母的坐标
	//$Start_Text_Coord_x += $margin;
	$Start_Text_Coord_y += $margin - 2;  //别忘了考虑第0个像素Y-coord 0


	/*/我们要使图像就大得足以容纳我们的文本块……旋转和字体大小。
我们*的利润率2,4面都有一个边缘
$TotalImageWidth= $TextBox_width + $margin*2 ;
	$TotalImageHeight= $TextBox_height + $margin*2 ;*/
//边缘太在，把它取消了.by39wifi
	$TotalImageWidth= $TextBox_width + $margin*2 ;
	$TotalImageHeight= $TextBox_height + $margin*2 ;

	//返回一个数组，包括左上角坐标（X，Y），宽度和高度
	return array("WIDTH"=>$TotalImageWidth, "HEIGHT"=>$TotalImageHeight, "X_POS"=>$Start_Text_Coord_x, "Y_POS"=>$Start_Text_Coord_y);
}
?>
