-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathplayer_portrait.php
143 lines (128 loc) · 5.48 KB
/
player_portrait.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
/**
* Created by PhpStorm.
* User: Ricardo
* Date: 23/03/2018
* Time: 23:30
* @param $new_image
* @param $image_source
*/
require_once "vendor/autoload.php";
use GDText\Box;
use GDText\Color;
require 'config/config.php';
// comment to show E_NOTICE [undefinied variable etc.], comment if you want make script and see all errors
error_reporting(E_ALL ^ E_STRICT ^ E_NOTICE);
// true = show sent queries and SQL queries status/status code/error message
define('DEBUG_DATABASE', FALSE);
define('INITIALIZED', TRUE);
if (!defined('ONLY_PAGE'))
define('ONLY_PAGE', TRUE);
// check if site is disabled/requires installation
include_once('./system/load.loadCheck.php');
// fix user data, load config, enable class auto loader
include_once('./system/load.init.php');
// DATABASE
include_once('./system/load.database.php');
function setTransparency ($new_image, $image_source)
{
$transparencyIndex = imagecolortransparent($image_source);
$transparencyColor = array('red' => 255, 'green' => 255, 'blue' => 255);
if ($transparencyIndex >= 0) {
$transparencyColor = imagecolorsforindex($image_source, $transparencyIndex);
}
$transparencyIndex = imagecolorallocate($new_image, $transparencyColor['red'], $transparencyColor['green'], $transparencyColor['blue']);
imagefill($new_image, 0, 0, $transparencyIndex);
imagecolortransparent($new_image, $transparencyIndex);
}
function playerPortraitCreate ($base, $player)
{
// Obtendo o tamanho original
list($width_orig, $height_orig) = getimagesize($base);
list($width_orig2, $height_orig2) = getimagesize($player);
// Calculando a proporção
$ratio_orig = $width_orig / $height_orig;
$ratio_orig2 = $width_orig2 / $height_orig2;
/// Largura e altura máximos (máximo, pois como é proporcional, o resultado varia)
// No caso da pergunta, basta usar $_GET['width'] e $_GET['height'], ou só
// $_GET['width'] e adaptar a fórmula de proporção abaixo.
$width = 500;
$height = 500;
$width2 = 100;
$height2 = 100;
if ($width / $height > $ratio_orig) {
$width = $height * $ratio_orig;
} else {
$height = $width / $ratio_orig;
}
if ($width2 / $height2 > $ratio_orig2) {
$width2 = $height2 * $ratio_orig2;
} else {
$height2 = $width2 / $ratio_orig2;
}
// O resize propriamente dito. Na verdade, estamos gerando uma nova imagem.
$extension = explode(".", $base);
$extension = $extension[count($extension) - 1];
$image_p = imagecreatetruecolor($width, $height);
$image = NULL;
if ($extension == "jpg" || $extension == "jpeg") {
$image = imagecreatefromjpeg($base);
} elseif ($extension == "gif") {
$image = imagecreatefromgif($base);
} elseif ($extension == "png") {
$image = imagecreatefrompng($base);
}
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
$image_player = imagecreatetruecolor($width2, $height2);
$marcadagua = imagecreatefromgif($player);
setTransparency($image_player, $marcadagua);
imagecopyresized($image_player, $marcadagua, 0, 0, 0, 0, $width2, $height2, $width_orig2, $height_orig2);
// imagedestroy($marcadagua);
//pega o tamanho da imagem principal
$dwidth = imagesx($image_p);
$dheight = imagesy($image_p);
//pega o tamanho da imagem que vai ser centralizada
$mwidth = imagesx($image_player);
$mheight = imagesy($image_player);
//Calcula a x e y posição pra colocar a imagem no centro da outra
//A função round arredonda os valores
$xPos = round(($dwidth - $mwidth) / 2 - 40);
$yPos = round(($dheight - $mheight) / 2 - 40);
imagecopymerge($image_p, $image_player, $xPos, $yPos, 0, 0, $mwidth, $mheight, 100);
// imagedestroy($image_player);
// imagecopyresampled($image_p, $image_player, $xPos, $yPos, 0, 0, $mwidth, $mheight, 100,100);
return $image_p;
}
if (isset($_REQUEST['name'])) {
$name = $_REQUEST['name'];
$p = new Player();
$p->loadByName($name);
$url1 = 'images/bg.png';
$url2 = "https://outfits.ferobraglobal.com/animoutfit.php?id={$p->getLookType()}&addons={$p->getLookAddons()}&head={$p->getLookHead()}&body={$p->getLookBody()}&legs={$p->getLookLegs()}&feet={$p->getLookFeet()}&mount={$p->getLookMount()}";
$player_portrait = playerPortraitCreate($url1, $url2);
$im = $player_portrait;
$w = imagesx($im);
$h = imagesy($im);
$box = new Box($im);
$box->setFontFace(__DIR__."/images/martel.ttf"); // http://www.dafont.com/elevant-by-pelash.font
$box->setFontColor(new Color(240, 209, 164));
$box->setStrokeColor(new Color(1, 1, 1)); // Set stroke color
$box->setStrokeSize(1); // Stroke size in pixels
$box->setTextAlign('center', 'center');
$box->setFontSize(30);
if($p->getLookMount() != 0){
$box->setBox(0, -90, $w, $h);
}else{
$box->setBox(0, -60, $w, $h);
}
$box->draw(ucfirst($p->getName())); // Text to draw
$box->setFontSize(30);
$box->setBox(0, 40, $w, $h);
$box->draw(ucfirst($p->getVocationName())); // Text to draw
$box->setFontFace(__DIR__.'/images/Roboto-Regular.ttf');
// $box->setBox(0, 400, $w, $h);
// $box->draw("Level: {$p->getLevel()}"); // Text to draw
header('Content-Type: image/png');
imagepng($im, NULL, 9, PNG_ALL_FILTERS);
imagedestroy($im);
}