( ′∀`)σ≡σ☆))Д′)レ(゚∀゚;)ヘ=З=З=Зε≡(ノ´_ゝ`)ノ
<?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 'jsonV2.php';
if (empty($_GET['themeid'])) {
$json = $fileImport;
} else {
$themeid = $_GET['themeid'];
$resultX = getEachJSONLayerV2($themeid,0);
$json = $resultX["layers3"];
}
require 'vendor/autoload.php';
use PHPImageWorkshop\ImageWorkshop;
$url = $json;
$url = str_replace("http://localhost/thebrand/","https://www.thebrand.ai/",$url) ;
$urlArray = htmlspecialchars_decode($url);
$Description = json_decode($urlArray , true);
$brandLayers = $Description['objects'];
$brandWidth = $Description['backgroundImage']['width'];
$brandHeight = $Description['backgroundImage']['height'];
$backgroundColor = $Description['background'];
$backgroundColor = str_replace("#","",$backgroundColor);
// optionnal, can be null to transparent
$norwayLayer = ImageWorkshop::initVirginLayer($brandWidth, $brandHeight, $backgroundColor);
$imageCount =0;
$textCount =0;
$rectCount =0;
foreach ($brandLayers as $child) {
$imageCount++;
$textCount++;
$rectCount++;
$type = $child['type'];
if($child['type']=="textbox") {
$type = $child['type'];
$version = $child['version'];
$originX = $child['originX'];
$originY = $child['originY'];
$left = $child['left']-25;
$top = $child['top']+15;
$width = $child['width'];
$height = $child['height'];
$fill = $child['fill'];
$stroke = $child['stroke'];
$strokeWidth = $child['strokeWidth'];
$strokeDashArray = $child['strokeDashArray'];
$strokeLineCap = $child['strokeLineCap'];
$strokeDashOffset = $child['strokeDashOffset'];
$strokeLineJoin = $child['strokeLineJoin'];
$strokeMiterLimit = $child['strokeMiterLimit'];
$scaleX = $child['scaleX'];
$scaleY = $child['scaleY'];
$angle = $child['angle'];
$flipX = $child['flipX'];
$flipY = $child['flipY'];
$opacity = $child['opacity'];
$shadow = $child['shadow'];
$visible = $child['visible'];
$clipTo = $child['clipTo'];
$backgroundColor = $child['backgroundColor'];
$fillRule = $child['fillRule'];
$paintFirst = $child['paintFirst'];
$globalCompositeOperation = $child['globalCompositeOperation'];
$transformMatrix = $child['transformMatrix'];
$skewX = $child['skewX'];
$skewY = $child['skewY'];
$text = $child['text'];
$fontSize = $child['fontSize'];
$fontWeight = $child['fontWeight'];
$fontFamily = $child['fontFamily'];
$fontStyle = $child['fontStyle'];
$lineHeight = $child['lineHeight'];
$underline = $child['underline'];
$overline = $child['overline'];
$linethrough = $child['linethrough'];
$textAlign = $child['textAlign'];
$textBackgroundColor = $child['textBackgroundColor'];
$charSpacing = $child['charSpacing'];
$minWidth = $child['minWidth'];
$splitByGrapheme = $child['splitByGrapheme'];
$id = $child['id'];
$lockUniScaling = $child['lockUniScaling'];
$perPixelTargetFind = $child['perPixelTargetFind'];
$objectCaching = $child['objectCaching'];
$noScaleCache = $child['noScaleCache'];
$strokeUniform = $child['strokeUniform'];
$originalLeft = $child['originalLeft'];
$originalTop = $child['originalTop'];
$fontFamilyCommandName = $child['fontFamilyCommandName'];
if(empty($fontWeight)) { $fontWeight =" Regular";}
else
{
$fontWeight =" $fontWeight";
}
$fontFamily = str_replace(" ","",$fontFamily) ;
$fontFamily =trim($fontFamily.$fontWeight);
$fonta = checkFontNewV2($fontFamily).".ttf";
if(empty($fonta)) {
$fonta = "../assets/fonts/BebasNeue.ttf";
}
else
{
$fonta = "../assets/fonts/$fonta";
if (file_exists($fonta)) {
}
else
{
$fonta = "../assets/fonts/BebasNeue.ttf";
}
}
$text = urlencode($text) ;
$width = ($child['width'] * $scaleX)-100;
$height = ($child['height']* $scaleY)-20;
if($fill == "white") {$fill == "ffffff"; }
elseif($fill == "black") {$fill == "ffffff"; }
else {
$fill = str_replace("#","",$fill) ;
}
${'pinguLayer$textCount'}= ImageWorkshop::initFromPath("https://www.thebrand.ai/superLayer/pullFont.php?fontSize=$fontSize&lineHeight=$lineHeight&charSpacing=$charSpacing&fontStyle=$fonta&textAlign=left&width=$width&height=$height&textColor=$fill&text=$text");
${'pinguLayer$textCount'}->rotate($angle);
$newOpacity = 100*$opacity;
${'pinguLayer$textCount'}->opacity($newOpacity);
$norwayLayer->addLayer( $textCount, ${'pinguLayer$textCount'},$left,$top);
}
if ($child['type'] == 'image') {
$type = $child['type'];
$version = $child['version'];
$originX = $child['originX'];
$originY = $child['originY'];
$left = $child['left'];
$top = $child['top'];
$width = $child['width'];
$height = $child['height'];
$fill = $child['fill'];
$opacity = $child['opacity'];
$src = $child['src'];
$angle= $child['angle'];
$scaleX = $child['scaleX'];
$scaleY = $child['scaleY'];
$crop = $width /$height.":1";
$width = ($child['width'] * $scaleX)-2;
$height = ($child['height']* $scaleY)-2;
/* $src ="../v/uploads/gthumbs/".basename($src);
list($newWidth, $newHeight) = getimagesize($src);
$newWidth2 = $newWidth -1;
$newHeight2 = $newHeight -1;*/
${'pinguLayer$imageCount'}= ImageWorkshop::initFromPath($src);
${'pinguLayer$imageCount'}->rotate($angle);
${'pinguLayer$imageCount'}->resizeInPixel($width, $height, true);
$newOpacity = 100*$opacity;
${'pinguLayer$imageCount'}->opacity($newOpacity);
$norwayLayer->addLayer( $imageCount, ${'pinguLayer$imageCount'},$left,$top);
}
if ($child['type'] == 'rect') {
$type = $child['type'];
$version = $child['version'];
$originX = $child['originX'];
$originY = $child['originY'];
$left = $child['left'];
$top = $child['top'];
$width = $child['width'];
$height = $child['height'];
$fill = $child['fill'];
$opacity = $child['opacity'];
$src = $child['src'];
$angle= $child['angle'];
$scaleX = $child['scaleX'];
$scaleY = $child['scaleY'];
$width = ($child['width'] * $scaleX)-2;
$height = ($child['height']* $scaleY)-2;
$fill = str_replace("#","",$fill) ;
${'pinguLayer$rectCount'}= ImageWorkshop::initVirginLayer($width, $height, $fill);
${'pinguLayer$rectCount'}->rotate($angle);
$newOpacity = 100*$opacity;
${'pinguLayer$rectCount'}->opacity($newOpacity);
$norwayLayer->addLayer( $rectCount, ${'pinguLayer$rectCount'},$left,$top);
}
if ($child['type'] == 'cirecle') {
$type = $child['type'];
$version = $child['version'];
$originX = $child['originX'];
$originY = $child['originY'];
$left = $child['left'];
$top = $child['top'];
$width = $child['width'];
$height = $child['height'];
$fill = $child['fill'];
$opacity = $child['opacity'];
$src = $child['src'];
$angle = $child['angle'];
$scaleX = $child['scaleX'];
$scaleY = $child['scaleY'];
$fill = str_replace("#", "", $fill);
// Create image
$width2 = 200;
$height2 = 200;
$img_width = $width;
$img_height = $height;
$img = imagecreatetruecolor($img_width, $img_height);
imagesavealpha($img, true);
$white = imagecolorallocatealpha($img, 255, 255, 255, 127);
list($r, $g, $b) = sscanf($fill, "#%02x%02x%02x");
$orange = imagecolorallocate($img, $r, $g, $b);
imagefill($img, 0, 0, $white);
//imageellipse($img, 100, 100, 100, 100, $orange);
imagefilledellipse($img, 0, 0, $img_width, $img_height, $orange);
// Draw the circle
/*imagepolygon($img, [$img_width*3/10, $img_height*2/10, $img_width*2/10, $img_height*5/10, $img_width*4/10, $img_height*5/10], 3, $red);
imageopenpolygon($img, [$img_width*3/10, $img_height*2/10, $img_width*7/10, $img_height*2/10, $img_width*8/10, $img_height*5/10], 3, $red);*/
/*imagearc($img, $img_width*3/10, $img_height*8/10, 100, 200, 180, 360, $red);
imageline($img, 0, $img_height*8/10, $img_width, $img_height*8/10, $green);*/
$circle = ImageWorkshop::initFromResourceVar($img);
$norwayLayer->addLayer($rectCount, $circle, $left, $top);
}
if ($child['type'] == 'pasth') {
$er++;
$pathColor++;
$type = $child['type'];
$version = $child['version'];
$originX = $child['originX'];
$originY = $child['originY'];
$left = $child['left'];
$top = $child['top'];
$width = $child['width'];
$height = $child['height'];
$fill = $child['fill'];
$stroke = $child['stroke'];
$strokeWidth = $child['strokeWidth'];
$strokeDashArray = $child['strokeDashArray'];
$strokeLineCap = $child['strokeLineCap'];
$strokeDashOffset = $child['strokeDashOffset'];
$strokeLineJoin = $child['strokeLineJoin'];
$strokeMiterLimit = $child['strokeMiterLimit'];
$scaleX = $child['scaleX'];
$scaleY = $child['scaleY'];
$angle = $child['angle'];
$flipX = $child['flipX'];
$flipY = $child['flipY'];
$opacity = $child['opacity'];
$shadow = $child['shadow'];
$visible = $child['visible'];
$clipTo = $child['clipTo'];
$backgroundColor = $child['backgroundColor'];
$fillRule = $child['fillRule'];
$paintFirst = $child['paintFirst'];
$globalCompositeOperation = $child['globalCompositeOperation'];
$transformMatrix = $child['transformMatrix'];
$skewX = $child['skewX'];
$skewY = $child['skewY'];
$id = $child['id'];
$lockUniScaling = $child['lockUniScaling'];
$perPixelTargetFind = $child['perPixelTargetFind'];
$objectCaching = $child['objectCaching'];
$noScaleCache = $child['noScaleCache'];
$strokeUniform = $child['strokeUniform'];
$originalLeft = $child['originalLeft'];
$originalTop = $child['originalTop'];
$path = $child['path'];
$svgPath = json_encode($path);
$json ='{
"type": "path",
"version": "5.3.0",
"originX": "'.$originX.'",
"originY": "'.$originY.'",
"left": '.$left.',
"top": '.$top.',
"width": '.$width.',
"height": '.$height.',
"fill": "'.$fill.'",
"stroke": "'.$stroke.'",
"strokeWidth": '.$strokeWidth.',
"strokeDashArray": null,
"strokeLineCap": "butt",
"strokeDashOffset": 0,
"strokeLineJoin": "miter",
"strokeUniform": true,
"strokeMiterLimit": 4,
"scaleX": '.$scaleX.',
"scaleY":'.$scaleY.',
"angle": '.$angle.',
"flipX": false,
"flipY": false,
"opacity": '.$opacity.',
"shadow": null,
"visible": true,
"backgroundColor": "",
"fillRule": "nonzero",
"paintFirst": "fill",
"globalCompositeOperation": "source-over",
"skewX": 0,
"skewY": 0,
"erasable": false,
"objectType": "element",
"gradientFill": "none",
"selectable": true,
"lockMovementX": false,
"lockMovementY": false,
"lockRotation": false,
"crossOrigin": "anonymous",
"path": '.$svgPath.'
},';
exit($json);
}
}
//$newLayer= ImageWorkshop::initFromPath("https://www.thebrand.ai/superLayer/pullFont.php");
//$newLayer->rotate($angle);
//$newLayer->resizeInPixel(700, "", true);
//$norwayLayer->addLayer( $imageCount, $newLayer,10,10);
/*// The card creator name layer (this is a text layer)
$textLayer = ImageWorkshop::initTextLayer('Sybio', '/path/to/fonts/garfield.ttf', 14, 'ffffff', 0);
// Adding the name of the card creator
$brushstroke2Layer->addLayer(1, $textLayer, 25, 13);*/
$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 = 100; // 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, 100); // We chose to show a JPG with a quality of 95%
exit;
?>