( ′∀`)σ≡σ☆))Д′)レ(゚∀゚;)ヘ=З=З=Зε≡(ノ´_ゝ`)ノ
<?php
$characters = json_decode($characters,true);
$designWidth= $characters['canvasWidth'];
$designHeight= $characters['canvasHeight'];
$characters = $characters['canvas']['objects'];
$text = explode("||", $content);
$i = -1;
$z = -1;
foreach ($characters as $row) {
$check = $row['type'] ;
if($check=="i-text")
{
$i++;
if($i == 0)
{
$textWrite = $text[0];
}
elseif($i == 1)
{
$textWrite = $text[1];
}
else
{
$textWrite = $row['text'];
}
$multiply =33;
$regex = "@(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?).*$)@";
$textWrite = preg_replace($regex, ' ', $textWrite);
$textWrite= smart_wordwrap($textWrite, $multiply) . "\n";
$textWrite = removeslashes($textWrite);
$textWrite = strip_tags($textWrite);
$fontJson .= '{"family": "'.$row['activeFont']['family'].'" , "category": "'.$row['activeFont']['category'].'" , "type": "'.$row['activeFont']['type'].'" },';
$json .=' {
"type": "i-text",
"version": "4.3.1",
"originX": "'.$row['originX'].'",
"originY": "'.$row['originY'].'",
"left": '.$row['left'].',
"top": '.$row['top'].',
"width": '.$row['width'].',
"height": '.$row['height'].',
"fill": "'.$row['fill'].'",
"stroke": "#000",
"strokeWidth": 0.1,
"strokeDashArray": null,
"strokeLineCap": "butt",
"strokeDashOffset": 0,
"strokeLineJoin": "miter",
"strokeUniform": false,
"strokeMiterLimit": 4,
"scaleX": 1,
"scaleY": 1,
"angle": 0,
"flipX": false,
"flipY": false,
"opacity": '.$row['opacity'].',
"shadow": null,
"visible": true,
"backgroundColor": null,
"fillRule": "nonzero",
"paintFirst": "fill",
"globalCompositeOperation": "source-over",
"skewX": 0,
"skewY": 0,
"text": "'.$textWrite.'",
"fontSize": '.$row['fontSize'].',
"fontWeight": '.$row['fontWeight'].',
"fontFamily": "'.$row['fontFamily'].'",
"fontStyle": "'.$row['fontStyle'].'",
"lineHeight": 1.42857143,
"underline": false,
"overline": false,
"linethrough": false,
"textAlign": "'.$row['textAlign'].'",
"textBackgroundColor": "'.$row['textBackgroundColor'].'",
"charSpacing": 0,
"selectable": true,
"evented": true,
"lockMovementX": false,
"lockMovementY": false,
"lockRotation": false,
"lockScalingX": false,
"lockScalingY": false,
"lockUniScaling": false,
"hasControls": true,
"hasBorders": true,
"hasRotatingPoint": true,
"name": "'.$row['name'].'",
"data": {
"id": "'.$row['data']['id'].'"
},
"activeFont": {
"family": "'.$row['activeFont']['family'].'",
"category": "'.$row['activeFont']['category'].'",
"type": "'.$row['activeFont']['type'].'"
},
"styles": [
]
},';
}
if($check=="i-taext")
{
$i++;
if($i == 0)
{
$textWrite = $text[0];
}
elseif($i == 1)
{
$textWrite = $text[1];
}
else
{
$textWrite = $row['text'];
}
$textWrite= smart_wordwrap($textWrite, 40) . "\n ";
$fontJson .= '{"family": "'.$row['activeFont']['family'].'" , "category": "'.$row['activeFont']['category'].'" , "type": "'.$row['activeFont']['type'].'" },';
$json .=' {
"type": "i-text",
"version": "3.6.6",
"originX": "'.$row['originX'].'",
"originY": "'.$row['originY'].'",
"left": '.$row['left'].',
"top": '.$row['top'].',
"width": '.$row['width'].',
"height": '.$row['height'].',
"fill": "'.$row['fill'].'",
"stroke": "'.$row['stroke'].'",
"strokeWidth": '.$row['strokeWidth'].',
"strokeDashArray": '.$row['strokeWidth'].',
"strokeLineCap": "'.$row['strokeWidth'].'",
"strokeDashOffset": '.$row['strokeWidth'].',
"strokeLineJoin": "'.$row['strokeWidth'].'",
"strokeMiterLimit": '.$row['strokeWidth'].',
"scaleX": '.$row['scaleX'].',
"scaleY": '.$row['scaleY'].',
"angle": "'.$row['angle'].'",
"flipX": "'.$row['flipX'].'",
"flipY": "'.$row['flipY'].'",
"opacity": "'.$row['opacity'].'",
"shadow": "'.$row['shadow'].'",
"visible": true,
"clipTo": null,
"backgroundColor": "'.$row['backgroundColor'].'",
"fillRule": "nonzero",
"paintFirst": "fill",
"globalCompositeOperation": "source-over",
"transformMatrix": null,
"skewX": 0,
"skewY": 0,
"selectable": true,
"evented": true,
"lockMovementX": true,
"lockMovementY": true,
"lockRotation": false,
"lockScalingX": false,
"lockScalingY": false,
"lockUniScaling": false,
"hasControls": true,
"hasBorders": true,
"hasRotatingPoint": true,
"name": "'.$row['name'].'",
"data": {
"id": "'.$row['data']['id'].'"
},
"activeFont": {
"family": "'.$row['activeFont']['family'].'",
"category": "'.$row['activeFont']['category'].'",
"type": "'.$row['activeFont']['type'].'"
},
"text": "'.$textWrite.'",
"fontSize": '.$row['fontSize'].',
"fontWeight": '.$row['fontWeight'].',
"fontFamily": "'.$row['fontFamily'].'",
"fontStyle": "'.$row['fontStyle'].'",
"lineHeight":1.1,
"underline": false,
"overline": false,
"linethrough": false,
"textAlign": "'.$row['textAlign'].'",
"textBackgroundColor": "'.$row['textBackgroundColor'].'",
"charSpacing": 0,
"styles": {}
},';
} if($check=="image")
{
$z++;
if($z == 0)
{
$rowX = getEachTweetPicture($tweetID ,0);
$urlX = $rowX["tweet_media"];
if(!empty($urlX))
{
$newPic = $urlX;
$imageSrc = $urlX;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $imageSrc);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // good edit, thanks!
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); // also, this seems wise considering output is image.
$data = curl_exec($ch);
curl_close($ch);
$brand = imagecreatefromstring($data);
$imageW = imagesx($brand);
$imageH = imagesy($brand);
// $r = $imageW / $imageH;
// $w = $row['width'];
// $h = $row['height'];
// if ($w/$h > $r) {
// $imageW = $h*$r;
// $imageH = $h;
// } else {
// $imageW = $w/$r;
// $imageH = $w;
// }
// $imageW = $row['width'];
// $imageH = $row['height'];
}
else
{
$imageSrc = $row['src'];
$imageW = $row['width'];
$imageH = $row['height'];
}
}
else {
$imageSrc = $row['src'];
$imageW = $row['width'];
$imageH = $row['height'];
}
$json .= '{
"type": "image",
"version": "3.6.6",
"originX": "center",
"originY": "center",
"left": '.$row['left'].',
"top": '.$row['top'].',
"width": '.$imageW.',
"height": '.$imageH.',
"fill": "rgb(30, 139, 195)",
"stroke": "#000",
"strokeWidth": 0,
"strokeDashArray": null,
"strokeLineCap": "butt",
"strokeDashOffset": 0,
"strokeLineJoin": "miter",
"strokeMiterLimit": 4,
"scaleX":'.$row['scaleX'].',
"scaleY": '.$row['scaleY'].',
"angle": '.$row['angle'].',
"flipX": false,
"flipY": false,
"opacity": 1,
"shadow": null,
"visible": true,
"clipTo": null,
"backgroundColor": null,
"fillRule": "nonzero",
"paintFirst": "fill",
"globalCompositeOperation": "source-over",
"transformMatrix": null,
"skewX": 0,
"skewY": 0,
"crossOrigin": "anonymous",
"cropX": 0,
"cropY": 0,
"selectable": true,
"evented": true,
"lockMovementX": true,
"lockMovementY": true,
"lockRotation": false,
"lockScalingX": true,
"lockScalingY": true,
"lockUniScaling": false,
"hasControls": true,
"hasBorders": true,
"hasRotatingPoint": true,
"name": "image",
"data": {
"id": "'.$row['data']['id'].'"
},
"src": "'.$imageSrc.'",
"filters": []
},';
}
//include("redesignArray.php");
}
$fontJson = "[".rtrim($fontJson, ',')."]";;
$json = "[".rtrim($json, ',')."]";
$characters = json_decode($json,true);
$charactersFonts = json_decode($fontJson,true);
$this->response["canvas"] = array();
$this->response["canvas"]["version"] = "3.6.6";
$this->response["canvas"]["objects"] = $characters;
$this->response["editor"]["fonts"] = $charactersFonts;
$this->response["canvasWidth"] = $designWidth;
$this->response["canvasHeight"] = $designHeight;
$theJson = json_encode($this->response);;
?>