( ′∀`)σ≡σ☆))Д′)レ(゚∀゚;)ヘ=З=З=Зε≡(ノ´_ゝ`)ノ
<?php
include("includes/limittext.php");
include('Connections/videoondemand.php');
require("DbSql.inc.php");
require("NewsSql.inc.php");
$db = new NewsSQL($DBName);
function filter($arr) {
global $link;
return array_map(array($link, 'real_escape_string'), $arr);
}
$_GET = filter($_GET);
$_POST = filter($_POST);
$mode=$_GET["mode"];
$font=$_GET["font"];
include("protect.php");
if (empty($page)) {
$page = 0;
}
include("includes/processFunctions.php");
class TextToImage {
var $fontSize = 12;
var $fontColor = "#8892BF";
var $fontColorAllocated = null;
var $lineHeight = 0;
var $align = "center";
var $text = "Sachin Puri";
var $angle = 0;
var $underline = true;
var $fontFile = '../assets/fonts/HelveticaNeueLTStd-Ex.otf'; //font used
var $image = "san.png";
var $imageWidth = 0;
var $imageHeight = 0;
var $startYPosition=400;
var $padding=0;
var $lines=array();
var $backgroundColor='transparent';
var $elements = "v/uploads/text/name.png";
var $rectangle = 100;
function setStrokeWidth($strokeWidth=0){
$this->strokeWidth = $strokeWidth;
}
function setStrokeColor($colour=array(0, 0, 0)){
$this->strokeColor = $colour;
}
function setText($text){
$this->text=$text;
}
function setFontSize($fontSize){
$this->fontSize=$fontSize*0.75;
}
function setFontFile2($fontFile){
$this->fontFile2=$fontFile;
}
function setFontFile($fontFile){
$this->fontFile=$fontFile;
}
function setFontColor($fontColorHex){
$this->fontColor = $fontColorHex;
}
function setFontColor2($fontColorHex2){
$this->fontColor2 = $fontColorHex2;
}
function startYPosition($YPosition){
$this->startYPosition = $YPosition;
}
function setLineHeight($lineHeight){
$this->lineHeight=$lineHeight;
}
function setUnderline($isUnderline){
$this->underline=$isUnderline;
}
function setPadding($padding){
$this->padding=$padding;
}
function setRectangle($rectangle){
$this->rectangle=$rectangle;
}
function setHAlignment($alignment){
$this->align=$alignment;
}
function setWidth($width){
$this->imageWidth=$width;
}
function setHeight($height){
$this->imageHeight=$height;
}
function saveImage($int){
$this->saveImage=$int;
}
function setAngle($angle){
$this->angle=$angle;
}
function sety($text_y){
$this->text_y=$text_y;
}
function setBackgroundColor($bgColor){
$this->backgroundColor = $bgColor;
}
function textToLines(){
$lines=array();
$wordSizeArray=array();
$arrWords=explode(" ", $this->text);
foreach($arrWords as $word){
$wordSize=imagettfbbox($this->fontSize, $this->angle, $this->fontFile, $word. " ");
$wordWidth=abs($wordSize[0])+abs($wordSize[2]);
$wordSizeArray[]=array('word'=>$word, 'size'=>$wordWidth);
}
$line='';
$lineWidth=0;
foreach($wordSizeArray as $wordDetail){
$word=$wordDetail['word'];
$wordWidth=$wordDetail['size'];
$lineWidth+=$wordWidth;
if($lineWidth<$this->imageWidth-($this->padding*2)){
$line.= ' ' . $word;
}else{
$line.= "\n" . $word;
$lineWidth=$wordWidth;
}
}
return explode("\n",$line);
}
function rounded_rectangle($left, $top, $padding_x, $padding_y, $color, $opacity, $corner_radius, $name, $text, $text_color){
$width = $left + strlen($text)*9 + 2*$padding_x;
$height = $top + 26 + 2*$padding_y;
if(substr($color, 0, 1) == "#"){
$color = substr($color, 1);
}
$r = substr($color,0,2);
$g = substr($color,2,2);
$b = substr($color,4,2);
$r = hexdec($r);
$g = hexdec($g);
$b = hexdec($b);
if(substr($text_color, 0, 1) == "#"){
$text_color = substr($text_color, 1);
}
$text_r = substr($text_color,0,2);
$text_g = substr($text_color,2,2);
$text_b = substr($text_color,4,2);
$text_r = hexdec($text_r);
$text_g = hexdec($text_g);
$text_b = hexdec($text_b);
$opacity = (100 - $opacity)/100 * 127;
$background = imagecreatetruecolor($left + $width, $top + $height);
imagesavealpha($background, true);
$trans_color = imagecolorallocatealpha($background, 0, 0, 0, 127);
imagefill($background, 0, 0, $trans_color);
$rectangle_color = imagecolorallocatealpha($background, $r, $g, $b, $opacity);
$points_array = array(
$left, $top + $corner_radius, //starting from top left corner before radius
$left + $corner_radius - cos(deg2rad(22.5))*$corner_radius, $top + $corner_radius - sin(deg2rad(22.5))*$corner_radius,
$left + $corner_radius - cos(deg2rad(45))*$corner_radius, $top + $corner_radius - sin(deg2rad(45))*$corner_radius,
$left + $corner_radius - cos(deg2rad(67.5))*$corner_radius, $top + $corner_radius - sin(deg2rad(67.5))*$corner_radius,
$left + $corner_radius, $top,
$left + $width - $corner_radius, $top,
$left + $width - $corner_radius + cos(deg2rad(67.5))*$corner_radius, $top + $corner_radius - sin(deg2rad(67.5))*$corner_radius,
$left + $width - $corner_radius + cos(deg2rad(45))*$corner_radius, $top + $corner_radius - sin(deg2rad(45))*$corner_radius,
$left + $width - $corner_radius + cos(deg2rad(22.5))*$corner_radius, $top + $corner_radius - sin(deg2rad(22.5))*$corner_radius,
$left + $width, $top + $corner_radius,
$left + $width, $top + $height - $corner_radius,
$left + $width - $corner_radius + cos(deg2rad(22.5))*$corner_radius, $top + $height - $corner_radius + sin(deg2rad(22.5))*$corner_radius,
$left + $width - $corner_radius + cos(deg2rad(45))*$corner_radius, $top + $height - $corner_radius + sin(deg2rad(45))*$corner_radius,
$left + $width - $corner_radius + cos(deg2rad(67.5))*$corner_radius, $top + $height - $corner_radius + sin(deg2rad(67.5))*$corner_radius,
$left + $width - $corner_radius, $top + $height,
$left + $corner_radius, $top + $height,
$left + $corner_radius - cos(deg2rad(67.5))*$corner_radius, $top + $height - $corner_radius + sin(deg2rad(67.5))*$corner_radius,
$left + $corner_radius - cos(deg2rad(45))*$corner_radius, $top + $height - $corner_radius + sin(deg2rad(45))*$corner_radius,
$left + $corner_radius - cos(deg2rad(22.5))*$corner_radius, $top + $height - $corner_radius + sin(deg2rad(22.5))*$corner_radius,
$left, $top + $height - $corner_radius
);
$rectangle = imagefilledpolygon($background, $points_array, 20, $rectangle_color);
$text_color = imagecolorallocatealpha($background, $text_r, $text_g, $text_b, 0);
$font = "assets/fonts/TitilliumWeb-SemiBold.ttf";
imagettftext($background, 20, 0, $left + $padding_x, $top + 26 + $padding_y, $text_color, $font, $text);
return $background;
}
function draw() {
$this->lines = $this->textToLines();
if($this->lineHeight == 0){
if($this->underline){
$this->lineHeight = $this->fontSize + ($this->fontSize*80/100);
}else{
$this->lineHeight = $this->fontSize + ($this->fontSize*60/100);
}
}
$this->startYPosition = $this->fontSize+1;
list($fontColorRed, $fontColorBlue, $fontColorGreen) = $this->hex2rgb($this->fontColor);
if($this->imageHeight==0){
$this->imageHeight = $this->lineHeight * count($this->lines) + ($this->padding*2);
}
$this->image = imagecreatetruecolor($this->imageWidth, $this->imageHeight);
imagealphablending($this->image, false); imagesavealpha($this->image, true);
$this->fontColorAllocated = imagecolorallocate($this->image, $fontColorRed, $fontColorBlue, $fontColorGreen);
if($this->backgroundColor == 'transparent'){
$bgcolor = imagecolorallocatealpha($this->image, 0, 0, 0, 127);
}else{
list($bgColorRed, $bgColorBlue, $bgColorGreen) = $this->hex2rgb($this->backgroundColor);
$bgcolor = imagecolorallocate($this->image, $bgColorRed, $bgColorBlue, $bgColorGreen);
}
imagefill($this->image, 0, 0, $bgcolor);
$this->writeText();
/*$this->rectangle();*/
/*$this->rectangle();*/
if($this->saveImage =="1")
{
/* imagepng($this->image,"v/uploads/text/".$_GET["pichaNi"].".png");
imagedestroy($this->image);
exit();*/
}
else
{
header("content-type: image/png");
imagepng($this->image);
imagedestroy($this->image);
}
}
function rectangle(){
$x=0;
$y=0;
$width=100;
$height=50;
$colour=array(35, 233, 234);
$opacity="1.0";
$outline=false;
if($outline === true){
imagerectangle($this->image, $x, $y, $x + $width, $y + $height, imagecolorallocatealpha($this->image, $colour[0], $colour[1], $colour[2], (1 - $opacity) * 127));
}else{
imagefilledrectangle($this->image, $x, $y, $x + $width, $y + $height, imagecolorallocatealpha($this->image, $colour[0], $colour[1], $colour[2], (1 - $opacity) * 127));
}
return $this->image;
}
function getStartXPositionOfLine($xBottomLeft, $lineWidth){
switch ($this->align) {
case 'left':
$startXPosition = abs($xBottomLeft) + $this->padding;
break;
case 'right':
$startXPosition = $this->imageWidth - $lineWidth - 1 - $this->padding;
break;
case 'center':
$startXPosition = ($this->imageWidth - $lineWidth) / 2;
break;
default:
$startXPosition = abs($xBottomLeft);
break;
}
return $startXPosition;
}
function strokeIt() {
$lineNumber=1;
foreach($this->lines as $line){
$line=trim($line);
list($xBLeft, $yBLeft, $xBRight, $yBRight, $xTRight, $yTRight, $xTLeft, $yTLeft) = imagettfbbox($this->fontSize, $this->angle, $this->fontFile, $line);
$lineWidth = abs($xBLeft) + abs($xBRight);
$startXPosition = $this->getStartXPositionOfLine($xBLeft, $lineWidth);
if($lineNumber==1 && $this->padding>0){
$this->startYPosition+=$this->padding;
}
if (!empty($_GET['position']) && empty($_GET['type']))
{
if($strokeWidth > 0){
$opacity = 80;
$strokeColor = imagecolorallocatealpha($this->image, $strokeColor[0], $strokeColor[1], $strokeColor[2], (1 - $opacity) * 127);
for($sx = ($x-abs($strokeWidth)); $sx <= ($x+abs($strokeWidth)); $sx++){
for($sy = ($y-abs($strokeWidth)); $sy <= ($y+abs($strokeWidth)); $sy++){
imagettftext($this->image, $this->fontSize, $this->angle, $_GET['x'] + $offsetx, $_GET['y']+22 + $offsety, $strokeColor, $this->fontFile, $line);
}
}
}
imagettftext($this->image, $this->fontSize, $this->angle, $_GET['x'], $_GET['y']+22, $this->fontColorAllocated, $this->fontFile, $line);
}
else if (!empty($_GET['position']) && !empty($_GET['type']))
{
if($strokeWidth > 0){
$opacity = 80;
$strokeColor = imagecolorallocatealpha($this->image, $strokeColor[0], $strokeColor[1], $strokeColor[2], (1 - $opacity) * 127);
for($sx = ($x-abs($strokeWidth)); $sx <= ($x+abs($strokeWidth)); $sx++){
for($sy = ($y-abs($strokeWidth)); $sy <= ($y+abs($strokeWidth)); $sy++){
imagettftext($this->image, $this->fontSize, $this->angle, $_GET['x'] + $offsetx, $_GET['y']+22 + $offsety, $strokeColor, $this->fontFile, $line);
}
}
}
imagettftext($this->image, $this->fontSize, $this->angle, $startXPosition+$_GET['x'], $this->startYPosition+$_GET['y']-20, $this->fontColorAllocated, $this->fontFile, $line);
}
else
{
if($strokeWidth > 0){
$opacity = 10;
$strokeColor = imagecolorallocatealpha($this->image, $strokeColor[0], $strokeColor[1], $strokeColor[2], (1 - $opacity) * 127);
for($sx = ($startXPosition-abs($strokeWidth)); $sx <= ($startXPosition+abs($strokeWidth)); $sx++){
for($sy = ($this->startYPosition-abs($strokeWidth)); $sy <= ($this->startYPosition+abs($strokeWidth)); $sy++){
}
}
}
imagettftext($this->image, $this->fontSize, $this->angle, $startXPosition, $this->startYPosition, $this->fontColorAllocated, $this->fontFile, $line);
}
if(strlen($line)>0){
$this->underline($startXPosition, $lineWidth);
}
$this->startYPosition+=$this->lineHeight;
$lineNumber++;
}
}
function writeText() {
$lineNumber=1;
foreach($this->lines as $line){
$line=trim($line);
list($xBLeft, $yBLeft, $xBRight, $yBRight, $xTRight, $yTRight, $xTLeft, $yTLeft) = imagettfbbox($this->fontSize, $this->angle, $this->fontFile, $line);
$lineWidth = abs($xBLeft) + abs($xBRight);
$startXPosition = $this->getStartXPositionOfLine($xBLeft, $lineWidth);
if($lineNumber==1 && $this->padding>0){
$this->startYPosition+=$this->padding;
}
if($lineNumber==1){
imagettftext($this->image, $this->fontSize, $this->angle, $startXPosition, $this->startYPosition, $this->fontColorAllocated, $this->fontFile, $line);
}
else
{
$logocolor2="#".$_GET["logocolor2"];
list($fontColorRed, $fontColorBlue, $fontColorGreen) = hex2rgb($logocolor2);
$logocolor2 = imagecolorallocate($this->image, $fontColorRed, $fontColorBlue, $fontColorGreen);
imagettftext($this->image, $this->fontSize , $this->angle, $startXPosition, $this->startYPosition, $logocolor2, $this->fontFile, $line);
}
if(strlen($line)>0){
$this->underline($startXPosition, $lineWidth);
}
$this->startYPosition+=$this->lineHeight;
$lineNumber++;
//slogan
}
if($_GET["logotagline"]=="yes") {
$slogan= $_GET["slogan"];
$slogan=trim($slogan);
list($xBLeft, $yBLeft, $xBRight, $yBRight, $xTRight, $yTRight, $xTLeft, $yTLeft) = imagettfbbox(14, $this->angle, $this->fontFile2, $slogan);
$lineWidth = abs($xBLeft) + abs($xBRight);
$startXPosition = $this->getStartXPositionOfLine($xBLeft, $lineWidth);
$logocolor2="#666666";
$sloganheight= $_GET["sloganheight"];
list($fontColorRed, $fontColorBlue, $fontColorGreen) = hex2rgb($logocolor2);
$logocolor2 = imagecolorallocate($this->image, $fontColorRed, $fontColorBlue, $fontColorGreen);
imagettftext($this->image, 14 , $this->angle, $startXPosition, ($this->startYPosition + $sloganheight)-30, $logocolor2, $this->fontFile2, $slogan);
}
}
function underline($startXPosition, $lineWidth){
if ($this->underline) {
$underlineY=$this->startYPosition+5;
imagesetthickness($this->image, 2);
imageline($this->image, $startXPosition, $underlineY, $startXPosition+$lineWidth, $underlineY, $this->fontColorAllocated);
}
}
function imagettfstroketext(&$image, $size, $angle, $x, $y, &$textcolor, &$strokecolor, $fontfile, $text, $px) {
for($c1 = ($x-abs($px)); $c1 <= ($x+abs($px)); $c1++)
for($c2 = ($y-abs($px)); $c2 <= ($y+abs($px)); $c2++)
$bg = imagettftext($image, $size, $angle, $c1, $c2, $strokecolor, $fontfile, $text);
return imagettftext($image, $size, $angle, $x, $y, $textcolor, $fontfile, $text);
}
function hex2rgb($hex) {
$hex = str_replace("#", "", $hex);
if (strlen($hex) == 3) {
$r = hexdec(substr($hex, 0, 1) . substr($hex, 0, 1));
$g = hexdec(substr($hex, 1, 1) . substr($hex, 1, 1));
$b = hexdec(substr($hex, 2, 1) . substr($hex, 2, 1));
} else {
$r = hexdec(substr($hex, 0, 2));
$g = hexdec(substr($hex, 2, 2));
$b = hexdec(substr($hex, 4, 2));
}
$rgb = array($r, $g, $b);
return $rgb;
}
function pr($str){
echo "<pre>";
print_r($str);
echo "</pre>";
}
}
$obj = new TextToImage();
global $link;
if($_GET["logoalign"] == "left")
{
$text_align= "left";
}
elseif($_GET["logoalign"] == "right")
{
$text_align= "right";
}
elseif($_GET["logoalign"] == "center")
{
$text_align= "center";
}
else
{
$text_align= "left";
}
$text_size= "100";
$text_color= "#".$_GET["logocolor"];
$text_pad= 10;
global $link;
$logofont= $_GET["logofont"];
$sql ="select * from fontcombination where name='$logofont' limit 0,1";
$rs_settings = mysqli_query($link,$sql);
while ($row_settings = mysqli_fetch_array($rs_settings)) {
$font = $row_settings['title'].".ttf" ;
$font2 = $row_settings['body'].".ttf" ;
$text_size= 70+ $row_settings['titleincrease'] ;
$text_line_height= $text_size -10;
if($_GET["logocapitalize"] == "uppercase")
{
$theText= strtoupper($_GET["brandname"]) ;
}
elseif($_GET["logocapitalize"] == "lowercase")
{
$theText= strtolower($_GET["brandname"]) ;
}
elseif($_GET["logocapitalize"] == "titlecase")
{
$theText= ucwords($_GET["brandname"]) ;
}
elseif($_GET["logocapitalize"] == "default")
{
if($row_settings['titlecapitalize'] == "1")
{
$theText= strtoupper($_GET["brandname"]) ;
}
else
{
$theText= $_GET["brandname"] ;
}
}
else
{
$theText= ucwords($_GET["brandname"]) ;
}
if($_GET["logolinebreak"] == "no")
{
$theText= $theText ;
}
else
{
$theText = str_replace(" ","\n",$theText);
}
$font_Text= "$font";
$font_Text2= "$font2";
}
$text_line_height= $_GET["logoheight"] ;
$obj->setLineHeight($text_line_height);
$obj->setText($theText);
$obj->setFontSize($text_size);
$obj->setFontFile("assets/fonts/".$font_Text);
$obj->setFontFile2("assets/fonts/".$font_Text2);
$obj->setUnderline(0);
$obj->setPadding(20);
$obj->setHAlignment(strtolower($text_align));
$obj->setWidth(600);
$obj->setHeight(600);
$obj->sety(150);
$obj->setAngle(0);
$obj->setFontColor('#'.$text_color);
$obj->setFontColor2('#666666');
$obj->setBackgroundColor("transparent");
$obj->draw();
?>