PHP - Text In Image
Is there any option to put text into this boxes where are red lines ?
Similar TutorialsThis code is creating broken image.please check it png and gd is enabled. i also remove the header but still getting broken image. there is no space before/after php tags.thanks you my code Code: [Select] <?php // Set the content-type header('Content-Type: image/png'); // Create the image $im = imagecreatetruecolor(400, 30); // 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, 399, 29, $white); // The text to draw $text = 'Testing...'; // Replace path by your own font path $font = 'arial.ttf'; // Add some shadow to the text imagettftext($im, 20, 0, 11, 21, $grey, $font, $text); // Add the text imagettftext($im, 20, 0, 10, 20, $black, $font, $text); // Using imagepng() results in clearer text compared with imagejpeg() imagepng($im); imagedestroy($im); ?> hi, i would like to no how people do this http://runelink.org/site/sc.php?server=TestScapez its an image with the name and votes of a server in a mysql database how would i do this? Okay I don't think I made myself clear last time. If this is too much hassle I will pay a small fee. But what I'm looking for is to be able to have a picture generated from my variables. I need 2 text inputs which put out the two lines shown. also need the background to gather from file directory. Also the biggest help i need is the text to be centered, since i keep messing that up PNG format = preferable. EXAMPLE - Thanks again. Hello. I would like to create a banner that gets two variables $one and $two. Then write them both onto my 468 by 60 image for examples sake "image.jpg" I know its something to do with imagettftext. However I can't find any good help around. Thanks Hello guys. Well I've ran into a sorta crossroad here with this script. See I'm trying to create like a click to make point system on an image. I have it all working except 1 problem.. At the moment the text to image script is only adding 1 bit of text onto the image, that is fine, that is because this is the only one in the php file: Code: [Select] Imagettftext($im, 12, 0, $X, $Y, $black, 'verdana.ttf', "$text"); But, what I am trying to do is to let the user create more points. I thought I could achieve this by a database and just echoing out all of the rows from point txt which are like the above. So it will be like Imagettftext($im, 12, 0, 342, 455 $black, 'verdana.ttf', "$text"); Imagettftext($im, 12, 0, 443, 953, $black, 'verdana.ttf', "$text"); Imagettftext($im, 12, 0, 553, 445, $black, 'verdana.ttf', "$text"); And every time a user adds another point another one of the above is added to the database, it is then read by the TXT file, and displayed onto the image. Although I only have this running at the moment: Code: [Select] <?php echo $row['pointtxt']; ?><br> And for a test I just tried a simple echo command, and this is the only record or row in the database in the field pointtxt: Code: [Select] echo "hello"; As you can image, I don't think an echo can echo PHP commands, sorry this is really hard to explain, if anyone needs further explaining tho I will try. Its basically I just want a user to add one of these into the database Imagettftext($im, 12, 0, 553, 445, $black, 'verdana.ttf', "$text"); And on the image, it will grab all of those from the database, and run them so they all appear on the image. Thanks for your help. is this possible to get the text in an image? is there anway way of being able to paste a picture into a textarea? So basically I have text which appears on an image. Code: [Select] $ability = "$title gets ability"; //Create Ability imagettfbbox(30, 0, $font, $ability); imagettftext($image, 30, 0, 70, 700, $fontcolor, $font, stripslashes($ability)); But the line of text is longer than the width of the area on the image it needs to fit in. How can I change this so it automatically starts a new line once it reaches the end of said area? hello world! First post here! I'm a newbie trying to make my own cms, everything is working except the import of image into the post, this becomes text. Here is the code: Code: [Select] function connect() { $con = mysql_connect($this->host, $this->username, $this->password) or die (mysql_error()); mysql_select_db ($this->db, $con) or die (mysql_error()); } function get_content($id = '') { if($id != ""): $id = mysql_real_escape_string($id); $sql = "SELECT * FROM cms_content WHERE id = '$id'"; else: $sql = "SELECT * FROM cms_content ORDER BY id DESC"; endif; $return = '<a href="index.php">go back</a>'; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) != 0): while($row = mysql_fetch_assoc($res)) { echo '<div class="title"><h1><a href="index.php?id=' . $row['id'] . '">' . $row['title'] . '</a></h1></div>'; echo '<div class="date"><p>' . $row['date'] . '</p></div>'; echo '<div class="photo"><p>' . $row['photo'] . '</p></div>'; echo '<div class="txt"><p>' . $row['body'] . '</p></div>'; } else: echo '<p class="results_">uH oh!</p>'; endif; echo $return; } function add_content($p) { $title = mysql_real_escape_string($p['title']); $date = mysql_real_escape_string($p['date']); $photo = mysql_real_escape_string($p['photo']); $body = mysql_real_escape_string($p['body']); // if they write wrong if(!$title | | !$body): if(!$title): echo "<p>The Title is Required</p>"; endif; if(!$photo): echo "<p>No photo</p>"; endif; if(!$body): echo "<p>The body is Required</p>"; endif; echo '<p><a href="add-content.php">Try again</a></p>'; else: // add to db $sql = "INSERT INTO cms_content VALUES (null, '$title', '$date', '$photo', '$body')"; $res = mysql_query($sql) or die(mysql_error()); echo "<p class='results_'>Added with success!</p>"; // [END] add to db endif; // [END] if they write wrong } and in the html i got a form Code: [Select] <form enctype="multipart/form-data" method="post" action="index.php"> <input type="hidden" name="add" value="true"> <div> <label for="title"><p>Title:</p></label> <input type="text" name="title" id="title" /> </div> <div> <input type="file" name="photo"><br> </div> <div> <label for="body"><p>Body:</p></label> <textarea name="body" id="body" rows="8" cols="40"></textarea> </div> <input type="submit" name="submit" value="Add Content"> </form> Hello i just learned how to use .ttf fonts on a webpage ,but i noticed that IE Browsers arent supporting it so i thought to make add the Fonted Text into a image so IE Browsers will see the font in a image and not a replaced font text Could someone please provide me a Simple Script to make a PNG image with the text and font and a invisible background ? hey, i'm trying to add a watermark to pictures that show up, however it is only showing as text here is the code $watermark = imagecreatefrompng('watermark1.png'); $image = imagecreatefromjpeg("/userImages/big/".$pic); imagecopymerge($image, $watermark, 5, 5, 0, 0, 135, 35, 100); imagejpeg($image); imagedestroy($image); imagedestroy($watermark); also, where i fould how to do this, said u have to put a header('content-type: image/jpeg'); code at the top of the page or else it would read as text, however, when i do that, the whole page disappears except for a question mark thing indicating a picture should be there? what do i do?? Hi I have a database with all my game collection on and have the code to display it on a webpage, my problem is in one field called Media, i have the text 'Physical' in it and i would like to change this within PHP to an image of a floppy disk when it displays on the webpage. Can this be done. I have done something similar with and if statement to display a 'tick' instead of a 1.
IF ( owned = 1, '✔', 'X' ) AS owned, IF ( completed = 1, '✔', ' ' ) AS completed i would like to do this as above rather than adding it to the MySQL database - the floppy image is on my computer in a folder called Images. Hi, I have a project, where i want to place a text over the image dynamically, just like if it is sold, i want to make it as SOLD text over the image Looking for idea to implement this, Thanks, For starters. I'm relatively new to PHP programming. I've had minor VB and I have SOME understanding of programming in general. I was trying to find this solution myself without consulting anyone but with PHP5 and it's deprecated functions. I can't just paste code from the net and it work. Currently I have PHP 5.3.5 installed. I'm running on the newest Apache and MySQL builds. Now to the part I want to get to work. I'm trying this just because I can. Basically. I would like php to scan a certain path and filter out the images. I have a script that does that fine. What I want to do is take the file names, append my host address and turn it into a clickable link. I also have a script that will turn text into URL's. I will paste the snippets I have. I was initially trying to use eregi_replace() but apparently that's been deprecated and I believe I should now use FileInfo() or something like that. Not quite sure what they do but am really wanting to learn. Thanks for any help you guys can offer. <?php $path = 'http://www.krasikart.no-ip.org'; $dir=$_SERVER['DOCUMENT_ROOT']."/htdocs/pics/"; $total = ''; // Retrieve all the images. $files = glob ("$dir{*.jpg,*.jpeg,*.gif}", GLOB_BRACE); // Confirm that matches were made. if (is_array($files)) { // Loop through the array. foreach ($files as $image) { $total = $path . $image; print "$total \n"; // The Regular Expression filter $reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; // The Text you want to filter for urls $text = "$total"; // Check if there is a url in the text if(preg_match($reg_exUrl, $text, $url)) { // make the urls hyper links echo preg_replace($reg_exUrl, '<a href="'.$url[0].'" rel="nofollow">'.$url[0].'</a>', $text); } else { // if no urls in the text just return the text } } } else { echo 'No files matched the search pattern!'; } ?> I've taken this eg from php manual site for displaying txt on image wonder why it is not working Code: [Select] <?php // Create a 300x150 image $im = imagecreatetruecolor(300, 150); $black = imagecolorallocate($im, 0, 0, 0); $white = imagecolorallocate($im, 255, 255, 255); // Set the background to be white imagefilledrectangle($im, 0, 0, 299, 299, $white); // Path to our font file $font = './arial.ttf'; // First we create our bounding box for the first text $bbox = imagettfbbox(10, 45, $font, 'Powered by PHP ' . phpversion()); // This is our cordinates for X and Y $x = $bbox[0] + (imagesx($im) / 2) - ($bbox[4] / 2) - 25; $y = $bbox[1] + (imagesy($im) / 2) - ($bbox[5] / 2) - 5; // Write it imagettftext($im, 10, 45, $x, $y, $black, $font, 'Powered by PHP ' . phpversion()); // Create the next bounding box for the second text $bbox = imagettfbbox(10, 45, $font, 'and Zend Engine ' . zend_version()); // Set the cordinates so its next to the first text $x = $bbox[0] + (imagesx($im) / 2) - ($bbox[4] / 2) + 10; $y = $bbox[1] + (imagesy($im) / 2) - ($bbox[5] / 2) - 5; // Write it imagettftext($im, 10, 45, $x, $y, $black, $font, 'and Zend Engine ' . zend_version()); // Output to browser header('Content-Type: image/png'); imagepng($im); imagedestroy($im); ?> So its a virtual pet script I'm making. This script changes the image of the pet with time. It also puts the user's name,in text on the image. For some reason It doesnt turn out too well= http://amiteka.comli.com/viewpet_forum.php?id=1 Can someone tell me what is wrong with the script or how I can make it show something like; Error on line # <?php require_once('./inc/config.php'); function greaterDate($dformat, $beginDate, $endDate) { $subtract = $endDate - $beginDate; if($subtract > 0) { return 1; } else { return 0; } } function check(){ $pid = mysql_real_escape_string($_GET['id']); $result = mysql_query("SELECT * FROM `pets_adopted` WHERE `id` = '{$pid}'"); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $results = mysql_query("SELECT * FROM `pets_list` WHERE `id` = '{$row [petid]}'"); $pet = mysql_fetch_array($results); $results2 = mysql_query("SELECT * FROM `users` WHERE `id` = '{$row [adopter]}'"); $usercc = mysql_fetch_array($results2); if(greaterDate(".", $row[fulldate], date('Ymd')) > 0) { $im = showpet_forum($pet[adulturl]); $image = imagecreatefrompng($im); return imagepng($image); header('Content-type: image/png'); } elseif(greaterDate(".", $row[halfdate], date('Ymd')) > 0 && greaterDate (".", $row[fulldate], date('Ymd')) <= 0){ $im = showpet_forum($pet[teenurl]); $image = imagecreatefrompng($im); return imagepng($image); header('Content-type: image/png'); } elseif(greaterDate(".", $row[halfdate], date('Ymd')) <= 0){ $im = showpet_forum($pet[babyurl]); $image = imagecreatefrompng($im); return imagepng($image); } } } echo check(); ?> Thank you for any help. I'm wondering if anyone can help me find/create a script which allows a preview of a link to be generated? Basically I need a user to be able to simply enter a url and click submit and then a preview of that link will be shown in the form of some text and an image. Very similar to what Facebook does when a user shares a link. I think they use the description tag of the site in general. Can anyone point me in the right direction in doing this? I need to be able to do it in php/javascript alone without the use of jquery or plugins. This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=357646.0 Hi, How to create an invisible text in an image. Any idea? Thanks. hi all .. I want to write arabic text in image .. this is my code .. <?php header("Content-Type: image/png; charset=utf8"); $im = imagecreatetruecolor(150, 30); // Create some colors $white = imagecolorallocate($im, 100, 255, 255); $grey = imagecolorallocate($im, 128, 128, 128); $black = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 399, 29, $white); $font = 'tahoma.ttf'; $t = 'إن الدين عند الله الإسلام'; $text=utf8_encode($t); imagettftext($im, 20, 0, 10, 20, $black, $font, $text); imagepng($im); imagedestroy($im); ?> |