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);
}
?>
Related
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 a prorgam that uses imagecopymerge. Here, I'm using two images. First image for background and second one to be placed inside it. I am able to do so, but now I want the second image to be on a certain size. this image is uploaded by user and saved at my server so i dont have control on it's size. How can I resize the second image before using it in my imagecopymerge? Thanks a lot for answering. Please also consider that resizing it during upload is my least option. I want the size to be 255x175.
This is what I have:
$uploadFilename = $uploadsDirectory.$now.'-'.$_FILES[$fieldname]['name'])
$upload = $uploadFilename;
$im = imagecreatefromjpeg("bg.jpg");
$img2 = imagecreatefromjpeg($upload);
$black = imagecolorallocate($im, 0, 0, 0);
$font = 'arialbi.ttf';
$font2 = 'ariali.ttf';
$newtitle = wordwrap($title, 28, "\n", true);
$newertitle = explode("\n", $newtitle);
imagettftext($im, 28, 0, 7, 270, $black, $font, $newertitle[0]);
imagettftext($im, 28, 0, 7, 320, $black, $font, $newertitle[1]);
imagettftext($im, 10, 0, 320, 362, $black, $font, $namehere);
imagecopymerge($im, $img2, 10, 350, 0, 0, imagesx($img2), imagesy($img2), 100);
imagedestroy($im);
http://php.net/manual/en/function.imagecopyresampled.php
Take your code...
imagecopymerge($im, $img2, 10, 350, 0, 0, imagesx($img2), imagesy($img2), 100);
And change it to...
imagecopyresampled($im, $img2, 10, 350, 0, 0, 255, 175, imagesx($img2), imagesy($img2));
Just simply use php function
given as:
$img = imagecreatefromjpeg("source_of_img.jpg");
$imgresize = imagescale($dp,200,200);
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);
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);
?>
this is Index file , it's task is to provide values to the cover.php file and get the image in return...
<?php
require('cover.php');
$name="Tushar Kesarwani";
$id=112200333;
$dob="9/9/1990";
$email="tushar.kesarwani2#gmail.com";
$profilelink="http://www.facebook.com/iamtusharDOTcom";
$relationship= "single";
$me = imagecreatefrompng('me.png');
$ob= new createimage();
$ob->create($name,$id,$dob,$email,$profilelink,$relationship,$me);
?>
<h1>hdhdhdh</h1>
this is cover.php, it's task is to create a image
<?php
class createimage
{
function create($name,$id,$dob,$email,$profilelink,$relationship,$me)
{
$base = imagecreatefromjpeg('fb.jpg');
$white = ImageColorAllocate($base, 255, 255, 255);
imagecopy($base, $me, 93, 102, 0, 0, imagesx($me), imagesy($me));
$font = 'ARIAL.TTF';
$font2='Cacophony Loud.ttf';
imagettftext($base, 25, 0, 228, 133, $white, $font2, $name);
imagettftext($base, 16, 0, 268, 183, $white, $font, $id);
imagettftext($base, 16, 0, 291, 224, $white, $font, $dob);
imagettftext($base, 13, 0, 126, 294, $white, $font, $email);
imagettftext($base, 13, 0, 126, 323, $white, $font, $profilelink);
imagettftext($base, 13, 0, 126, 353, $white, $font, $relationship);
// Output and free memory
header('Content-type: image/png');
imagejpeg($base);
imagedestroy($base);
}
}
?>
The problem is that.. images is printing but tag or anything after the image is not working
This is because you're sending an actual image. The header image/png is what is doing it. If you want to set it as an img, save the file to the server and load it in the src attribute, or base64 encode it in the src attribute (properly)
To save it as an image do something to the tune of:
// Remove the proceeding line
// header('Content-type: image/png');
$name = '/location/where/you/want/to/save/file.jpg';
imagejpeg($base, $name);
echo "<img src='$name' />";
Also, you're sending headers for png files but you're creating a jpeg file. You might want to correct that.