473,554 Members | 5,383 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Finding X & Y co-ords of text on an image

118 New Member
Hi all,

I have a dynamic image that picks out data from a dynamically created .line file.

showimage.php(5 )
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include("linesfile.php5");
  3. $linesDataFile = new DataFile("data.line");
  4.  
  5. //$image = ImageCreate(660,240); // create the image canvas
  6. $image = ImageCreateFromPNG("background.png");
  7. $blue = ImageColorAllocate($image, 200, 200, 255); // prepare some blueness
  8. $black = ImageColorAllocate($image, 0, 0, 0); // ... and whiteness
  9.  
  10. $cur_line_y = 63;  // This stores how far down the image the current line will print
  11. $cur_line_x = 24; // This stores how far across the image the current line will print
  12. $pagecharwidth = 75; // this is the maximum length of the line before it wraps;
  13. $lineheight = 15; // This is how much to move down to print the next line
  14. $pagelinelimit = 12; // This is the maximum number lines of text that can be displayed
  15.  
  16. ImageFill($image, 0, 0, $blue); // fill the canvas
  17.  
  18. //ImageString($image, 3, 15, $cur_line_y, trim(stripslashes($wordwrapped[0])), $black);
  19.  
  20. $numberOfLines = $pagelinelimit;
  21.  
  22.  
  23.  
  24. for($i=0;$i<$numberOfLines;$i++) {
  25.     $data = $linesDataFile->getReverseIterate();
  26.     if (count($data)==0) continue;
  27.     $name = "[" . $data[0] . "] ";
  28.     $color = $data[1];
  29.     $font = $data[2];
  30.     $line = $data[3];
  31.  
  32.     $line = $name . $line;
  33.  
  34.  
  35.  
  36. //ImageString($image, 2, $cur_line_x, $cur_line_y, trim($line), getColor($color));
  37.  
  38.  
  39.             imagettftext($image,10,0,$cur_line_x,$cur_line_y,getColor($color),getfont($font),trim($line));
  40.  
  41.     $cur_line_y += $lineheight;
  42.  
  43. }
  44.  
  45. function getColor($color) {
  46.     global $image;
  47.  
  48.     switch($color) {
  49.         case "black" :
  50.             return ImageColorAllocate($image, 0, 0, 0); 
  51.         case "white" :
  52.             return ImageColorAllocate($image, 255, 255, 255); 
  53.         case "blue" :
  54.             return ImageColorAllocate($image, 0, 0, 205); 
  55.         case "red" :      
  56.             return ImageColorAllocate($image, 255, 0, 0); 
  57.         case "yellow" :
  58.             return ImageColorAllocate($image, 255, 255, 0); 
  59.         case "green" :
  60.             return ImageColorAllocate($image, 0, 255, 0); 
  61.                 case "orange" :
  62.                         return ImageColorAllocate($image, 255, 127, 36);
  63.                 case "aqua" :
  64.                         return ImageColorAllocate($image, 0, 255, 255);
  65.         default: 
  66.             return ImageColorAllocate($image, 255, 255, 255); 
  67.  
  68.     }
  69. }
  70.  
  71. function getfont($font) {
  72.     global $image;
  73.     global $font;
  74.  
  75.     switch($font) {
  76.         case "fixedsys" :
  77.             return "fixedsys.ttf";
  78.         case "Courbd" :
  79.             return "courbd.ttf";
  80.         case "arial" :
  81.             return "arialbd.ttf";
  82.         case "timesnr" :
  83.             return "timesbd.ttf";
  84.         case "calibri" :
  85.             return "calibrib.ttf";
  86.         case "comicsans" :
  87.             return "comicsans.ttf";
  88.         case "palab" :
  89.             return "palab.ttf";
  90.         default:
  91.             return "courbd.ttf";
  92.     }
  93. }
  94.  
  95.  
  96. header("Content-Type: image/png"); // tell the browser what we're gonna give it
  97. ImagePng($image); // paint the image in browser
  98. ImagePng($image, "./chatbox.png"); //export as png file
  99. ImageDestroy($image); // clean up resources
  100. ?>
the php in Index.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.             include("linesfile.php5");
  3.             $filename = "data.line";
  4.             set_magic_quotes_runtime(0);
  5.             if ($_POST['submit']) {
  6.             // grab the inputted text
  7.             $text = stripcslashes($_POST['input'] . "\n");
  8.             $username = stripslashes($_POST['username']);
  9.             $color = $_POST['color'];
  10.             $font = $_POST['font'];
  11.             $ip = $_SERVER['REMOTE_ADDR'] . "\n";
  12.             $_SESSION['username'] = $username;
  13.             $_SESSION['color'] = $color;
  14.  
  15.  
  16.                     $dirty = array('many', 'bad', 'words', 'in', 'here'); // I took out the real array just to keep the thread 'clean'.
  17.  
  18.                         foreach($dirty AS $bad_word){
  19.                         $text = preg_replace("/$bad_word/i","****", $text);
  20.                       }
  21.             $data[] ="\n".$username;
  22.             $data[] =trim($color);
  23.             $data[] =trim($font);
  24.             $data[] =trim($text);
  25.  
  26.  
  27.             $datafile = new DataFile($filename);
  28.             if(!$datafile->writeNewLine($data)) die("Error writing to file");
  29. }
  30.           ?>
my plan/idea is to impliment smilies into the image. If the user enters data such as 'Yay, it works!! =D' it will replace '=D' with a .gif image.

To do this I believe I will use Imagecopymerge( ). but how would I go about getting the X & Y co-ords for the text that needs changing, in this case '=D'? Baring in mind that everytime a new post is submitted the previous line is moved down.

How would I do this?

Thanks,
Sam

myChatbox - the site, just so you get a feel for the image and input
Nov 1 '07 #1
1 1750
pbmods
5,821 Recognized Expert Expert
Heya, Sam.

No good way to do it that I know of. I think you're hitting the limit of what a graphical chatbox can do.
Nov 27 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
3795
by: Han | last post by:
Determining the pattern below has got my stumped. I have a page of HTML and need to find all occurrences of the following pattern: score=9999999999&amp; The number shown can be 5-10 characters in length. I would like to extract only the number, stripping off the "score=" and "&amp;".
4
2333
by: Glutinous | last post by:
I've been studying this for hours, searching the www & usenet, and still can't figure out why 'each' returns an array of four key/value pairs, when it looks like just two pairs would suffice... That is, it looks to me like & are the same, and also & , so what's the point of duplicating them?
7
1951
by: Pete | last post by:
I'm working (playing) on a mouse following script. Yes, the sort no one likes but I'm having great fun tinkering with it - sad. Anyway, if there's enough page content to cause scrolling and I want the objects (colored divs) to scroll with the mouse in Opera 6. I give the mouse y coords (-) window.pageYOffset and the objects (+)...
4
2416
by: kinne | last post by:
The following code is supposed to reverse the date in "yyyy-mm-dd" format, but it produces different results in Firefox 1.0 and in Internet Explorer 6SP1. In Firefox, the result is correct ("2004-11-29") but it's wrong in Internet Explorer 6SP1 ("00:20:15-11-29"). If I change "dateParts" to "dateParts", it's exactly the opposite that occures:...
1
1290
by: John M | last post by:
hi, I'm finding this problem most frustrating. (It's probably my lack of undersating of functions!) I want to fill a control in a report with the result of a function. I'm calculating the average of a number of fields for the current record. It all works .. to a point!! Using for and next I can identify the fileds and get the data. All...
27
3809
by: Daniel Vallstrom | last post by:
I'm having problems with inconsistent floating point behavior resulting in e.g. assert( x > 0.0 && putchar('\n') && x == 0.0 ); holding. (Actually, my problem is the dual one where I get failed assertions for assertions that at first thought ought to hold, but that's not important.) At the end is a full program containing the above...
72
4151
by: Paminu | last post by:
In math this expression: (a < b) && (b < c) would be described as: a < b < c But why is it that in C these two expressions evaluate to something different for the same values of a, b and c?
9
1739
by: find clausen | last post by:
How can I use this: if (!zxmes && self.name != "menu") and add if (zmes == 1) if (!zxmes && self.name != "menu" || zmes == 1) and make it work.
3
1934
by: Paul Sijben | last post by:
I am running a multi-threaded python application in a dual core intel running Ubuntu. I am using python 2.5.1 that I compiled myself. At random points I am getting segmentation faults (sometimes indicating a duplicate free). Below is the backtrace of the latest segfault. I am thinking this might be an issue related to the dual core CPU so...
6
1280
by: mansi sharma | last post by:
create table mail3(email varchar(50)) insert into mail3 values('mansi.sharma@yahoo.co.in') insert into mail3 values('mansi.sharma+yahoo.co.in') insert into mail3 values('mansi.sharma^yahoo.co.in') insert into mail3 values('mansi.sharma*yahoo.co.in') insert into mail3 values('mansi.sharma&yahoo.co.in') insert into mail3...
0
7580
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7503
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7781
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7538
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6121
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5421
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5140
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1113
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
817
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.