( ′∀`)σ≡σ☆))Д′)レ(゚∀゚;)ヘ=З=З=Зε≡(ノ´_ゝ`)ノ
<?php
include("../includes/limittext.php");
include('../Connections/videoondemand.php');
require("../DbSql2.inc.php");
require("../NewsSql2.inc.php");
require("../includes/processFunctionsX.php");
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
$db = new NewsSQL;
include("../protect.php");
include 'json.php';
if (empty($_GET['themeid'])) {
$json = $fileImport;
} else {
$themeid = $_GET['themeid'];
$resultX = getEachJSONLayer($themeid,1);
$json = $resultX["layers2"];
}
require 'vendor/autoload.php';
use PHPImageWorkshop\ImageWorkshop;
$url = $json;
$url = str_replace("http://localhost/thebrand/","https://www.thebrand.ai/",$url) ;
$urlArray = str_replace("'","",$url);
$Description = json_decode($urlArray , true);
$brandLayers = $Description['canvas']['objects'];
$brandWidth = $Description['canvasWidth'];
$brandHeight = $Description['canvasHeight'];
function searchForId($id, $array) {
foreach ($array as $key => $val) {
if ($val['family'] === $id) {
return $key;
}
}
return null;
}
$backgroundColor = 'ffffff'; // optionnal, can be null to transparent
$norwayLayer = ImageWorkshop::initVirginLayer($brandWidth, $brandHeight, $backgroundColor);
$decodedText = html_entity_decode($fonts);
$myArray = json_decode($decodedText, true);
$imageCount =0;
foreach ($brandLayers as $value) {
$imageCount++;
$type = $value['type'];
if($type=="image") {
$type = $value['type'];
$version = $value['version'];
$originX = $value['originX'];
$originY = $value['originY'];
$left = $value['left'];
$top = $value['top'];
$scaleX = $value['scaleX'];
$scaleY = $value['scaleY'];
$width = $value['width'] ;
$height = $value['height'] ;
$src = $value['src'];
// Calling getimagesize() function
list($widthX, $heightX, $type, $attr) = getimagesize($value['src']);
if($heightX != $height) {
/* echo "$scaleX <br> not same!! " . $heightX . " -$height <br>";
echo "not same!! " . $widthX . "- $width <br>";
exit();*/
$halfWidth = $width/2;
$halfHeight = $height/2;
$diffWidth = $value['width'] - $widthX;
$diffHeight =$value['height'] -$heightX ;
$width = $widthX * $scaleX;
$height = $heightX * $scaleY;
$newleft = $value['left']-$halfWidth- $diffWidth;
$newtop = $value['top']-$halfHeight- $diffHeight ;
}
else{
$width = ($width+3) * $scaleX;
$height = ($height+3) * $scaleY;
$halfWidth = $width/2;
$halfHeight = $height/2;
$newleft = $value['left']-$halfWidth ;
$newleft = $newleft-3 ;
$newtop = $value['top']-$halfHeight;
$newtop = $newtop-2;
}
// exit("$newleft,$newtop");
$fill = $value['fill'];
$stroke = $value['stroke'];
$strokeWidth = $value['strokeWidth'];
$strokeDashArray = $value['strokeDashArray'];
$strokeLineCap = $value['strokeLineCap'];
$strokeDashOffset = $value['strokeDashOffset'];
$strokeLineJoin = $value['strokeLineJoin'];
$strokeUniform = $value['strokeUniform'];
$strokeMiterLimit = $value['strokeMiterLimit'];
$angle = $value['angle'];
$flipX = $value['flipX'];
$flipY = $value['flipY'];
$opacity= $value['opacity'];
$shadow = $value['shadow'];
$visible = $value['visible'];
$backgroundColor = $value['backgroundColor'];
$fillRule = $value['fillRule'];
$paintFirst = $value['paintFirst'];
$globalCompositeOperation = $value['globalCompositeOperation'];
$skewX = $value['skewX'];
$skewY = $value['skewY'];
$cropX = $value['cropX'];
$cropY = $value['cropY'];
$selectable = $value['selectable'];
$evented = $value['evented'];
$lockMovementX = $value['lockMovementX'];
$lockMovementY = $value['lockMovementY'];
$lockRotation = $value['lockRotation'];
$lockScalingX = $value['lockScalingX'];
$lockScalingY= $value['lockScalingY'];
$lockUniScaling = $value['lockUniScaling'];
$hasControls = $value['hasControls'];
$hasBorders = $value['hasBorders'];
$hasRotatingPoint = $value['hasRotatingPoint'];
$crossOrigin = $value['crossOrigin'];
$name = $value['name'];
$src = $value['src'];
$src = str_replace("https://www.thebrand.ai/","",$src);
$src = urldecode($src) ;
// $pinguLayer = ImageWorkshop::initFromPath($imageX);
// $norwayLayer->addLayer(rand(1,4), $pinguLayer, 0, 0, "MM");
if (strpos($src, 'taswira') !== false)
{
$ImageValues = explode("&",$src);
$imageSrc = $ImageValues[4];
$src = str_replace("image=/","",$imageSrc);
$src = basename($src);
$src = "../v/uploads/gthumbs/$src";
if (file_exists($src)) {
${'pinguLayer$imageCount'}= ImageWorkshop::initFromPath($value['src']);
${'pinguLayer$imageCount'}->rotate($angle);
${'pinguLayer$imageCount'}->resizeInPixel($width, $height, true);
$norwayLayer->addLayer( $imageCount, ${'pinguLayer$imageCount'},$newleft,$newtop);
}
}
else
{
$src = "../$src";
if (file_exists($src)) {
${'pinguLayer$imageCount'}= ImageWorkshop::initFromPath($value['src']);
${'pinguLayer$imageCount'}->rotate($angle);
${'pinguLayer$imageCount'}->resizeInPixel($width, $height, true);
$norwayLayer->addLayer( $imageCount, ${'pinguLayer$imageCount'},$newleft,$newtop);
}
}
}
if($type=="i-text") {
$type = $value['type'];
$version = $value['version'];
$originX = $value['originX'];
$originY = $value['originY'];
$left = $value['left'];
$top = $value['top'];
$width = $value['width'];
$height = $value['height'];
$halfWidth = $width/2;
$halfHeight = $height/2;
$newleft = $value['left']-$halfWidth -5;
$newtop = $value['top']-$halfHeight-5;
$fill = $value['fill'];
$fill2 = $value['fill'];
$fill = str_replace("rgb(","",$fill) ;
$fill = str_replace(")","",$fill) ;
$fillValues = explode(",",$fill);
$red = $fillValues[0];
$blue = $fillValues[1];
$green = $fillValues[2];
$fill = sprintf("#%02x%02x%02x",$red,$blue,$green); // #0d00ff
//exit($fill);
$fill = str_replace("#","",$fill) ;
$stroke = $value['stroke'];
$strokeWidth = $value['strokeWidth'];
$strokeDashArray = $value['strokeDashArray'];
$strokeLineCap = $value['strokeLineCap'];
$strokeDashOffset = $value['strokeDashOffset'];
$strokeLineJoin = $value['strokeLineJoin'];
$strokeUniform = $value['strokeUniform'];
$strokeMiterLimit = $value['strokeMiterLimit'];
$scaleX = $value['scaleX'];
$scaleY = $value['scaleY'];
$angle = $value['angle'];
$flipX = $value['flipX'];
$flipY = $value['flipY'];
$opacity= $value['opacity'];
$shadow = $value['shadow'];
$visible = $value['visible'];
$backgroundColor = $value['backgroundColor'];
$fillRule = $value['fillRule'];
$paintFirst = $value['paintFirst'];
$globalCompositeOperation = $value['globalCompositeOperation'];
$skewX = $value['skewX'];
$skewY = $value['skewY'];
$cropX = $value['cropX'];
$cropY = $value['cropY'];
$selectable = $value['selectable'];
$evented = $value['evented'];
$lockMovementX = $value['lockMovementX'];
$lockMovementY = $value['lockMovementY'];
$lockRotation = $value['lockRotation'];
$lockScalingX = $value['lockScalingX'];
$lockScalingY= $value['lockScalingY'];
$lockUniScaling = $value['lockUniScaling'];
$hasControls = $value['hasControls'];
$hasBorders = $value['hasBorders'];
$hasRotatingPoint = $value['hasRotatingPoint'];
$crossOrigin = $value['crossOrigin'];
$name = $value['name'];
$src = $value['src'];
$fontFamily = $value['fontFamily'];
$fontWeight = $value['fontWeight'];
$fontStyle = $value['fontStyle'];
// $fonta =processCanvasFont($fontFamily);
$fonta = checkFontNew($fontFamily);
if(empty($fonta)) {
$fonta = "../assets/fonts/BebasNeue.ttf";
}
else
{
$fonta = "../assets/fonts/$fonta";
if (file_exists($fonta)) {
}
else
{
$fonta = "../assets/fonts/BebasNeue.ttf";
}
}
$fontWeight = $value['fontWeight'];
$fontSize = $value['fontSize'];
$text = $value['text'];
$underline = $value['underline'];
$overline = $value['overline'];
$linethrough = $value['linethrough'];
$textAlign = $value['textAlign'];
$fontStyle = $value['fontStyle'];
$id = searchForId($fontFamily, $myArray);
$array = array_values($myArray);
$foundRecord = $array[$id];
$realFont = $foundRecord['src'];
if(!empty($realFont))
{
}
$realFont = str_replace(".woff2",".ttf",$realFont);
$lineHeight = $value['lineHeight'];
$textBackgroundColor = $value['textBackgroundColor'];
$charSpacing = $value['charSpacing'];
$direction = $value['direction'];
$path = $value['path'];
$crossOrigin = $value['pathStartOffset'];
$pathSide = $value['pathSide'];
$pathAlign = $value['pathAlign'];
// This is the text layer
// $textLayer = ImageWorkshop::initTextLayer($text, $fonta, $fontSize-5, $fill, 0);
//
//$norwayLayer->addLayerOnTop($textLayer, $newleft-5,$newtop+5);
//exit($text);
$text = urlencode($text) ;
// exit("https://www.thebrand.ai/superLayer/pullFont.php?fontSize=$fontSize&lineHeight=$lineHeight&charSpacing=$charSpacing&fontStyle=$fonta&textAlign=$textAlign&width=$width&height=$height&textColor=$fill&text=$text");
$newLayer= ImageWorkshop::initFromPath("https://www.thebrand.ai/superLayer/pullFont.php?fontSize=$fontSize&lineHeight=$lineHeight&charSpacing=$charSpacing&fontStyle=$fonta&textAlign=$textAlign&width=$width&height=$height&textColor=$fill&text=$text");
//$newLayer->rotate($angle);
//$newLayer->resizeInPixel(700, "", true);
$norwayLayer->addLayer( $imageCount, $newLayer,$newleft,$newtop+15);
}
}
//$newLayer= ImageWorkshop::initFromPath("https://www.thebrand.ai/superLayer/pullFont.php");
//$newLayer->rotate($angle);
//$newLayer->resizeInPixel(700, "", true);
//$norwayLayer->addLayer( $imageCount, $newLayer,10,10);
$image = $norwayLayer->getResult();
/*// Saving the result
$dirPath = __DIR__."/done";
$filename = "pingu_edited.png";
$createFolders = true;
$backgroundColor = null; // transparent, only for PNG (otherwise it will be white if set null)
$imageQuality = 95; // useless for GIF, usefull for PNG and JPEG (0 to 100%)
$norwayLayer->save($dirPath, $filename, $createFolders, $backgroundColor, $imageQuality);*/
if(!empty($_GET['snap']))
{
$filename = $_GET['poster'];
// Saving the result
$dirPath = "../v/uploads/gallery/";
$createFolders = true;
$backgroundColor = null; // transparent, only for PNG (otherwise it will be white if set null)
$imageQuality = 95; // useless for GIF, usefull for PNG and JPEG (0 to 100%)
$norwayLayer->save($dirPath, $filename, $createFolders, $backgroundColor, $imageQuality);
}
header('Content-type: image/png');
imagejpeg($image, null, 95); // We chose to show a JPG with a quality of 95%
exit;
?>