php GD image showing something with text - php

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.

Related

Working with Multiline Texts on imagettftext

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);
}
?>

PHP: Deboss the text with font

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);

Change the font used by ImageString

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);

Making captcha image in PHP

I'm trying to use the GD graphics library to make this captcha image, and the box shows up how Id like it to, but the text isn't being displayed over the image at all. I can't figure out why it's not showing up.
<?php
session_start();
putenv('GDFONTPATH=' . realpath('.') );
$font = 'Molle';
header('Content-Type: image/png');
$im = imagecreatetruecolor(260, 40);
$white = imagecolorallocate($im, 255, 255,255);
$grey = imagecolorallocate($im, 215, 215, 215);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 3, 3, 255, 34, $grey);
$text = 'Testing';
$_SESSION["captcha"] = $text;
imagettftext( $im, 20, 0, 16, 26, $white, $font, $text );
imagettftext( $im, 20, 0, 15, 25, $black, $font, $text );
imagepng($im);
imagedestroy($im);
?>

PHP Json Terraria Server Status

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!

Categories