I really searched a long time on google/stackoverflow and didn't find my answer.
I'm trying to put an image to see if my Terraria server is online or not and if yes, who's connected etc.. :p I'm really noob in php but I'm trying to learn! I got this source code from geek85 on tshock.co . Here's the source :
<?php
error_reporting(E_ERROR);
//variables
$ip = 'XXX.XXX.XXX.XXX';
$port = '7878'; //port of rest server, not terraria server
$json = json_decode(file_get_contents('http://'.$ip.':'.$port.'/status/'), true);
header('Content-Type: image/png');
$im = #imagecreatefrompng('terraria_online.png');
$font = 'visitor1.ttf';
//$font2 = 'fonts/visitor2.ttf';
$red = imagecolorallocate($im, 255, 24, 24);
$blue = imagecolorallocate($im, 50,50,255);
$black = imagecolorallocate($im, 10,10,10);
$purple = imagecolorallocate($im, 127,0,127);
$grey = imagecolorallocate($im, 50, 50, 50);
$white = imagecolorallocate($im, 255, 255, 255);
//server found and running
if ($json['status'] == '200')
{
// text in the grey box
$playerarray = explode(', ',$json['players']);
imagettftext($im, 18, 0, 31, 16, $grey, $font, $json['name']);
imagettftext($im, 18, 0, 30, 15, $red, $font, $json['name']);
imagettftext($im, 14, 0, 31, 34, $grey, $font, 'IP: '.$ip);
imagettftext($im, 14, 0, 30, 33, $black, $font, 'IP: '.$ip);
imagettftext($im, 14, 0, 31, 49, $grey, $font, 'Port: '.$json['port']);
imagettftext($im, 14, 0, 30, 48, $black, $font, 'Port: '.$json['port']);
imagettftext($im, 14, 0, 9, 71, $grey, $font, 'Joueurs en ligne: '.$json['playercount']);
imagettftext($im, 14, 0, 8, 70, $blue, $font, 'Joueurs en ligne: '.$json['playercount']);
// show VIPs' avatar
if ($json['playercount'] > 0)
{
//array of VIP players - (next step : a txt file with names and coordinates to parse...)
$vip = array('QcSeb','Marlin','Twingo','Gaston');
$num = count($vip);
for ($i=0; $i<$num; $i++)
{
if (in_array($vip[$i], $playerarray))
{
$player = #imagecreatefrompng('Images/'.strtolower($vip[$i]).'.png');//This line doesn't work for now
$long = imageSX($player);
$haut = imageSY($player);
switch ($vip[$i])
{
//here, it's a bit difficult: these are the coordinate where to place VIP players in the image.
case 'QcSeb':
$x = 350;
$y = 133;
break;
case 'Gaston':
$x = 300;
$y = 68;
break;
case 'Marlin':
$x = 261;
$y = 68;
break;
case 'Twingo':
$x = 307;
$y = 133;
break;
}
$ok = imagecopy($im,$player,$x,$y-$haut,0,0,$long,$haut);
}
}
// name of players (VIP or not)
$i = -1;
$j = 0;
// since my server only accept 8 players, I don't have any overflow control on the number of player's name to write but this code can do the work for any number of player (< to width of image / 75)
foreach( $playerarray as $player )
{
if ($i++ >= 6)
{
$i = 0;
$j++;
}
imagettftext($im, 11, 0, 11+($j*75), 101+($i*15), $grey, $font, $player);
imagettftext($im, 11, 0, 10+($j*75), 100+($i*15), $purple, $font, $player);
}
}
}
// offline or not "statut == 200"
else
{
$im = #imagecreatefrompng('terraria_offline.png');
imagettftext($im, 18, 0, 11, 31, $purple, $font, 'IP:'.$ip.':'.$port);
imagettftext($im, 18, 0, 10, 30, $grey, $font, 'IP:'.$ip.':'.$port);
imagettftext($im, 42, 17, 16, 131, $purple, $font, 'offline');
imagettftext($im, 42, 17, 15, 130, $black, $font, 'offline');
}
imagepng($im);
imagedestroy($im);
?>
I'm using 000webhost : sebserver.comuf.com (/ServerStatus1.php).
When I go on
http://XXX.XXX.XXX.XXX:7878/status/ I get :
{
"status": "200",
"name": "TShock Server",
"port": "7777",
"playercount": "1",
"players": "QcSeb"
}
Because only me is on the server actually.
(XXX.XXX.XXX.XXX = My hidden IP :P)
Here's an example of what I'm trying to do : http://renagadez.square7.de/gen.php?ip=111.111.111.111&port=1111
Thanks for your help in advance!
Related
My code is here, Im trying to create png widget for a website. I do correct others but when im trying to fit my long text in to my cards 181*312 px
I must fit my text in to text area, and its impossible to change my widget sizes
So how can wrap my text?
$kartquery = mysql_query("SELECT * FROM status");
While($kartqueryyaz=mysql_fetch_array($kartquery)){
// Q & A
$id = $kartqueryyaz['id'];
$longdesc = $kartqueryyaz['longdesc'];
$correct = $kartqueryyaz['correct'];
$wrong1 = $kartqueryyaz['wrong1'];
$wrong2 = $kartqueryyaz['wrong2'];
$wrong3 = $kartqueryyaz['wrong3'];
$wrong4 = $kartqueryyaz['wrong4'];
// carttype
$png_image = imagecreatefrompng('card1.png');
// Text Color #white ffffff
$white = imagecolorallocate($png_image, 255, 255, 255);
// Font
$font_path = 'GothamBook.ttf';
$font_pathdogru = 'GothamRoundedBold.ttf';
imagettftext($png_image, 25, 0, 55, 230, $white, $font_path, $longdesc);
imagettftext($png_image, 25, 0, 150, 730, $white, $font_pathdogru, $correct);
imagettftext($png_image, 25, 0, 150, 850, $white, $font_path, $wrong1);
imagettftext($png_image, 25, 0, 150, 970, $white, $font_path, $wrong2);
imagettftext($png_image, 25, 0, 150, 1100, $white, $font_path, $wrong3);
imagettftext($png_image, 25, 0, 150, 1220, $white, $font_path, $wrong4);
//imagepng($png_image);
imagepng($png_image, "img/".$id.".png");
imagedestroy($png_image);
}
?>
Please have a look on the following link, you will get the deboss text:
http://www.wristbandtoday.com/wristband/gd/load.php?route=font&size=30&name=1391601784Artbrush.ttf&effect=debossed&color=222222&text=Debossed
I know how to emboss the text:
$emboss = array(array(2, 0, 0), array(0, -1, 0), array(0, 0, -1));
imageconvolution($im, $emboss, 3, 235);
This is the following code to make the text by php and get emboss effect:
header('Content-Type: image/png');
// The text to draw
$text = "Ebossed";
// Replace path by your own font path
$font = WWW_ROOT.DS.'fonts/uploads/9559122015-03-27Artbrush.ttf';
$fontSize = 32;
$text_angle = 0;
$text_padding = 0;
$the_box = $this->_calculateTextBox($text, $font, $fontSize, $text_angle);
$imgWidth = $the_box["width"] + $text_padding;
$imgHeight = $the_box["height"] + $text_padding;
$im = imagecreatetruecolor($imgWidth, $imgHeight);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, $imgWidth-1, $imgHeight-1, $white);
// Add some shadow to the text
imagettftext($im, $fontSize, $text_angle, 0, 32, $grey, $font, $text);
// Add the text
imagettftext($im, $fontSize, $text_angle, 0, 32, $black, $font, $text);
$emboss = array(array(2, 0, 0), array(0, -1, 0), array(0, 0, -1));
imageconvolution($im, $emboss, 3, 235);
imagepng($im,WWW_ROOT.DS.IMAGES_URL.'test/newtes.png'); // image path
imagedestroy($im);
How do U create the Deboss effect?
For Deboss Effect please apply the following line of code:
$debosseffect = array
(
array(0, 0, 1),
array(0, -1, 1),
array(0, 0, -1)
);
Thanks
Finally I got the solution for getting deboss effect
$image = imagecreatefromjpeg(WWW_ROOT.DS.IMAGES_URL.'cliparts/'.$img);
$sharpenMatrix = array
(
array(0, 0, 1),
array(0, -1, 1),
array(0, 0, -1)
);
// calculate the sharpen divisor
$divisor = 3;
$offset = 235;
// apply the matrix
imageconvolution($image, $sharpenMatrix, $divisor, $offset);
header('Content-Type: image/png');
imagepng($image, null, 9);
imagegd($image);
imagedestroy($image);
I am trying to make signature it working correct but in someusers it show after text "r"
ex: http://grabcnr.net/sign/goldzoro
however http://grabcnr.net/sign/bangobng, some users work correct
Full code
http://pastebin.com/Dk2u83JV
<?php
$user = $_GET['user'];
$user = strtolower($user);
$player = $user;
$hits = file_get_contents("http://grabcnr.net/adminsys/grabdatabase.php?pass=grabapi1&user=$player&f=sighits");
$arrests = file_get_contents("http://grabcnr.net/adminsys/grabdatabase.php?pass=grabapi1&user=$player&f=sigarrests");
$arrested = file_get_contents("http://grabcnr.net/adminsys/grabdatabase.php?pass=grabapi1&user=$player&f=sigarrested");
$robs = file_get_contents("http://grabcnr.net/adminsys/grabdatabase.php?pass=grabapi1&user=$player&f=sigrobs");
$robbed = file_get_contents("http://grabcnr.net/adminsys/grabdatabase.php?pass=grabapi1&user=$player&f=sigrobbed");
$score = file_get_contents("http://grabcnr.net/adminsys/grabdatabase.php?pass=grabapi1&user=$player&f=sigscore");
$lotto = file_get_contents("http://grabcnr.net/adminsys/grabdatabase.php?pass=grabapi1&user=$player&f=siglotto");
$mb = file_get_contents("http://grabcnr.net/adminsys/grabdatabase.php?pass=grabapi1&user=$player&f=sigmb");
$plate = file_get_contents("http://grabcnr.net/adminsys/grabdatabase.php?pass=grabapi1&user=$player&f=sigplate");
$hits = str_replace("/[^0-9]/","",$hits);
$plate = strip_tags($plate);
header('Content-Type: image/png');
$image = imagecreatefrompng("sig.png");
$white = imagecolorallocate($image, 255, 255, 255);
$whitesemi = imagecolorallocatealpha($image, 255, 255, 255, 60);
$black = imagecolorallocate($image, 0, 0, 0);
$red = imagecolorallocate($image, 165,10,10);
$a1 = "hits Done:$hits";
//choose a default php font number 1 to 5
$font = 2;
imagestring($image, 5, 90, 4, "$user", $red);
imagestring($image, 3, 10, 25, "$a1", $white);
imagestring($image, 3, 10, 40, "Arrests:$arrests", $white);
imagestring($image, 3, 10, 55, "Arrested:$arrested", $white);
imagestring($image, 3, 10, 70, "Robs:$robs", $white);
imagestring($image, 3, 10, 85, "Robbed:$robbed", $white);
imagestring($image, 3, 130, 25, "Score:$score", $white);
imagestring($image, 3, 130, 40, "Lotto Won:$lotto", $white);
imagestring($image, 3, 130, 55, "Money Bags:$mb", $white);
imagestring($image, 3, 130, 70, "Plate:$plate", $white);
imagestring($image, 3, 130, 85, "www.grabcnr.net", $whitesemi);
imagepng($image);
imagedestroy($image);
?>
Try below query to check whether there are possible \r or \r\n in your data:
SELECT * FROM mytable WHERE mycolumn REGEXP "\r\n";
OR
SELECT * FROM mytable WHERE mycolumn REGEXP "\r";
If you find any any then you have to replace it.
I have this PHP code:
<?php
//Other part of code
Header("Content-type: image/png");
$im = imagecreatefromPng("./images/signatures/background.png");
$red = ImageColorAllocate($im, 255, 0, 0);
$black = ImageColorAllocate($im, 0, 0, 0);
ImageString($im, 5, 15, 5, "$callsign", $black);
ImageString($im, 5, 15, 20, "$name $surname", $black);
ImageString($im, 5, 15, 35, "Location: $location", $black);
ImageString($im, 5, 15, 50, "HUB: $hub", $black);
ImageString($im, 5, 15, 65, "Hours: $hours", $black);
$font_width = ImageFontWidth(5);
ImagePng($im);
?>
I want to change the font that PHP uses to write in the image. How can i do that?? I try but I canĀ“t.
Assuming that you mean font:
http://www.php.net/manual/en/function.imageloadfont.php
http://php.net/manual/en/function.imagettftext.php this may help if your using ttf fonts
You can use imageloadfont ();
syntax:
int imageloadfont ( string $file )
Example:
// Create a new image instance
$im = imagecreatetruecolor(50, 20);
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
// Make the background white
imagefilledrectangle($im, 0, 0, 49, 19, $white);
// Load the gd font and write 'Hello'
$font = imageloadfont('./04b.gdf');
imagestring($im, $font, 0, 0, 'Hello', $black);
// Output to browser
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
so change your code to:
//Other part of code
Header("Content-type: image/png");
$im = imagecreatefromPng("./images/signatures/background.png");
$font = imageloadfont('./fonts/arial.gdf');//change the parameter based on your font file name
$red = ImageColorAllocate($im, 255, 0, 0);
$black = ImageColorAllocate($im, 0, 0, 0);
ImageString($im, $font, 15, 5, "$callsign", $black);
ImageString($im, $font, 15, 20, "$name $surname", $black);
ImageString($im, $font, 15, 35, "Location: $location", $black);
ImageString($im, $font, 15, 50, "HUB: $hub", $black);
ImageString($im, $font, 15, 65, "Hours: $hours", $black);
$font_width = ImageFontWidth(5);
ImagePng($im);
While developing I faced a problem. After calling imagedestroy my script won't execute some PHP nor HTML.
When I delete the header it execute the PHP / HTML after the imagedestroy, but I need that header in my script. So my question is; how can a PHP header affect the PHP script.
<?php
header('Content-Type: image/png;');
$im = #imagecreatefrompng('ticket.png') or die("Cannot select the correct image. Please contact the webmaster.");
$text_color = imagecolorallocate($im, 0,0,0);
/*
$name = $_GET['name'];
$from = $_GET['from'];
$to = $_GET['to'];
$time = $_GET['time'];
$date = $_GET['date'];
$agent = $_GET['agent'];
$sno = $_GET['sno'];
$flightno = $_GET['flightno'];
$boardingtime = $_GET['boardingtime'];
$gate = $_GET['gate'];
$seat = $_GET['seat'];
*/
$name = $_POST['name'];
$from = $_POST['from'];
$to = $_POST['to'];
$time = $_POST['time'];
$date = $_POST['date'];
$agent = $_POST['agent'];
$sno = rand(101, 199);
$flightno = $_POST['flightno'];
$boardingtime = $_POST['boardingtime'];
$gate = $_POST['gate'];
$seat = $_POST['seat'];
$text_name = "$name";
$text_from = "$from";
$text_to = "$to";
$text_time = "$time";
$text_date = "$date";
$text_agent = "$agent";
$text_sno = "$sno";
$text_flightno = "$flightno";
$text_boardingtime = "$boardingtime";
$text_gate = "$gate";
$text_seat = "$seat";
$font = 'font.ttf';
#Basis in het midden.
imagettftext($im, 12, 0, 119, 168, $text_color, $font, $text_name);
imagettftext($im, 12, 0, 119, 184, $text_color, $font, $text_from);
imagettftext($im, 12, 0, 100, 201, $text_color, $font, $text_to);
imagettftext($im, 12, 0, 185, 235, $text_color, $font, $text_time);
imagettftext($im, 12, 0, 498, 167, $text_color, $font, $text_date);
imagettftext($im, 12, 0, 509, 184, $text_color, $font, $text_agent);
imagettftext($im, 21, 0, 544, 260, $text_color, $font, $text_sno);
#Top
imagettftext($im, 14, 0, 97, 85, $text_color, $font, $text_flightno);
imagettftext($im, 14, 0, 289, 85, $text_color, $font, $text_boardingtime);
imagettftext($im, 14, 0, 398, 85, $text_color, $font, $text_gate);
imagettftext($im, 14, 0, 486, 85, $text_color, $font, $text_seat);
$rand = rand(0, 3498);
imagepng($im);
imagepng($im, 'images/' . $rand . '.png');
imagedestroy($im);
echo 'This does not display';
?>
I have a feeling that the issue is that the browser doesn't know how to handle the data it's receiving. According to the docs, if you do not supply a path to imagepng() it will output the data to the browser. If you have not specified the correct headers, it should output as text. If you have, it should output as an image. If you provide the headers that tell the browser to treat it as an image, the image parser will probably discard the extra characters 'This does not display' that are appended to the end of the image data.
Try getting rid of imagepng($im) and watch as it saves the image then outputs 'This does not display'.
http://us2.php.net/imagepng