Hi folks,
I have a script that pulls user comments from a database, which works fine.
It's an image based script so I'm trying to now add emoticons, for such as =D or =)
To do this I was planning to use list(,,,,,,$left,$top) for the imagettfbox of where =D or =) can be found in the text..
How would I get php to return the location of where the '=D' is in the text? Str_split wouldn't work well enough.
How could I then, from getting the location of it, get it in a imagettfbbox to get the top left X and Y values for it in relation to the text?
Hope that makes sense.
Sam
2 1393
Hi folks,
I have a script that pulls user comments from a database, which works fine.
It's an image based script so I'm trying to now add emoticons, for such as =D or =)
To do this I was planning to use list(,,,,,,$left,$top) for the imagettfbox of where =D or =) can be found in the text..
How would I get php to return the location of where the '=D' is in the text? Str_split wouldn't work well enough.
How could I then, from getting the location of it, get it in a imagettfbbox to get the top left X and Y values for it in relation to the text?
Hope that makes sense.
Sam
PHP will only work if you submit the post. ie. if you type :) it will not automatically change to a smiley until you submit it. You can do it, but that would be javascript. If you do still want to use php, please post some code so we can help you with YOUR code, rather than making our own for you. That's what we do here, fix code, not make it!
Point taken, here is the code I have.
Explanation: I have a main page for my shoutbox, which contains a form for a user to input a username, message, font(select menu), colour(select), which posts to itself and adds the information they just posted to the database.
In the main page there is an dynamically created image.
showimage.php -
<?php
-
$user_id = mysql_real_escape_string(htmlspecialchars($_GET['uid']));
-
-
$sqls = "SELECT username FROM user WHERE user_id='$user_id'";
-
-
$results = mysql_query($sqls) or die("error in sqls: " . mysql_error());
-
$rows = mysql_fetch_array($results);
-
-
$counts = mysql_num_rows($results);
-
$font = "palab.ttf";
-
$user = $rows['username'];
-
$_SESSION['user'] = $user;
-
-
-
$im = ImageCreate(230, 35);
-
$black_a = imagecolorallocate($im, 0, 0, 0);
-
$white_a = imagecolortransparent($im, $black);
-
$white = ImageColorAllocate($im, 255, 255, 255);
-
ImageFill($im, 0, 0, $white_a);
-
Imagettftext($im, 15, 0, 10, 30, $white, $font, $user . "'s Shoutbox");
-
-
$grin = imagecreatefromgif("icon_lol.gif");
-
$blark = ImageColorAllocate($grin, 0, 0, 0);
-
-
-
//$image = ImageCreate(660,240); // create the image canvas
-
$image = ImageCreateFromGIF("660x240background2.gif");
-
$blue = ImageColorAllocate($image, 200, 200, 255); // prepare some blueness
-
$black = ImageColorAllocate($image, 0, 0, 0); // ... and whiteness
-
-
$cur_line_y = 60; // This stores how far down the image the current line will print
-
$cur_line_x = 24; // This stores how far across the image the current line will print
-
$pagecharwidth = 75; // this is the maximum length of the line before it wraps;
-
$lineheight = 18; // This is how much to move down to print the next line
-
$pagelinelimit = 1; // This is the maximum number lines of text that can be displayed
-
-
-
//ImageString($image, 3, 15, $cur_line_y, trim(stripslashes($wordwrapped[0])), $black);
-
-
$numberOfLines = $pagelinelimit;
-
-
-
$sql = "SELECT * FROM user INNER JOIN tblcomments ON tblcomments.user_id=user.user_id INNER JOIN tblattributes ON tblcomments.id = tblattributes.id INNER JOIN tblip ON tblattributes.id = tblip.id WHERE tblcomments.user_id='$user_id' AND tblattributes.user_id='$user_id' AND tblip.user_id='$user_id' ORDER BY tblcomments.`id` DESC LIMIT 0,10";
-
-
$result = mysql_query($sql) or die("error in sql: " . mysql_error());
-
-
for ($i = 0; $i < $numberOfLines; $i++) {
-
while ($row = mysql_fetch_array($result)) {
-
-
-
$name = "[" . htmlspecialchars_decode($row['username']) . "] ";
-
$font = $row['font'];
-
$color = $row['color'];
-
$line = htmlspecialchars_decode($row['comment']);
-
-
-
-
if ($name == "[] ") {
-
$name = "";
-
-
$line = $name . $line;
-
} else {
-
-
$line = $name . $line;
-
}
-
-
if ($color == "white" || $color == "yellow" || $color == "green" || $color ==
-
"orange" || $color == "aqua") {
-
Imagettftext($image, 10, 0, $cur_line_x, $cur_line_y, getColor($color), getfont
-
($font), trim($line));
-
-
-
} elseif ($color != "white" || $color != "yellow" || $color != "green" || $color !=
-
"orange" || $color != "aqua") {
-
Imagettftext($image, 10, 0, $cur_line_x, $cur_line_y, $white, getfont($font),
-
trim($line));
-
-
-
} elseif ($font == "fixedsys" || $font == "Courbd" || $font == "arial" || $font ==
-
"timesnr" || $font == "calibri" || $font == "comicsans" || $font == "palab") {
-
Imagettftext($image, 10, 0, $cur_line_x, $cur_line_y, getColor($color), getfont
-
($font), trim($line));
-
-
-
} else {
-
Imagettftext($image, 10, 0, $cur_line_x, $cur_line_y, $white, "courbd.ttf", trim
-
($line));
-
-
-
}
-
-
$cur_line_y += $lineheight;
-
-
-
}
-
-
-
}
-
-
-
function getColor($color)
-
{
-
global $image;
-
-
switch ($color) {
-
case "white":
-
return ImageColorAllocate($image, 255, 255, 255);
-
case "yellow":
-
return ImageColorAllocate($image, 255, 255, 0);
-
case "green":
-
return ImageColorAllocate($image, 0, 255, 0);
-
case "orange":
-
return ImageColorAllocate($image, 255, 127, 36);
-
case "aqua":
-
return ImageColorAllocate($image, 0, 255, 255);
-
default:
-
return ImageColorAllocate($image, 255, 255, 0);
-
-
}
-
}
-
-
-
function getfont($font)
-
{
-
global $image;
-
global $font;
-
-
switch ($font) {
-
case "fixedsys":
-
return "fixedsys.ttf";
-
case "Courbd":
-
return "courbd.ttf";
-
case "arial":
-
return "arialbd.ttf";
-
case "calibri":
-
return "calibrib.ttf";
-
case "comicsans":
-
return "comicsans.ttf";
-
case "palab":
-
return "palab.ttf";
-
default:
-
return "palab.ttf";
-
}
-
}
-
-
ImageCopyMerge($image, $im, 20, 0, 0, 0, 230, 50, 100);
-
-
header("Content-Type: image/gif"); // tell the browser what we're gonna give it
-
imagegif($image); // paint the image in browser
-
imagegif($image, "user/" . $user . ".gif"); //export as gif file
-
ImageDestroy($image); // clean up resources
-
-
?>
-
This is the code for the image, on the main page if the posted comment contains =D, :D, :d or =d a session is started $_SESSION['smile'];
For this in shoutbox.php: -
$smiles = array('=D', "=d", ":d", ":D");
-
foreach($smiles as $smile) {
-
if (preg_match("/$smile/i", $text)) {
-
$_SESSION['smile'] = $smile;
-
}
-
}
-
I attempted to use, in showimage.php -
if (isset($_SESSION['smile'])) {
-
-
$smile = $_SESSION['smile'];
-
-
if (preg_match("/$smile/i", $line)) {
-
list(, , , , , , ,$left, $top) = imagettfbbox(10, 0, getfont($font), $smile);
-
-
imagecopymerge($image, $grin, $left, $top, 0, 0, 15, 15, 100);
-
}
-
-
}
-
but to no avail, it didn't work; I even changed $left and $top in the imagecopymerge to 350 and 100, respectively. This would have shown if the image was being rendered ontop of the main image, but for some reason it didn't show up at all.. any ideas?
Also, will that imagettfbbox(10, 0, getfont($font), $smile) return the coordinates for the '=D' in relation to its place in the line of text? If not, how would I get that to work?
Hope that makes more sense,
Sam
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Michael Bierman |
last post by:
Please forgive the simplicy of this question. I have the following code
which attempts to determine the color of some text and set other text
to match that color. It works fine in Firefox, but does...
|
by: Alan Silver |
last post by:
Hello,
I have a repeater that has code like this...
<ItemTemplate>
<asp:CheckBox ID="chkDelete" Text="" RunAt="server"/>
.... other stuff goes here
</ItemTemplate>
There is a button below...
|
by: Chris Riesbeck |
last post by:
I have an image with a class and the class defines a clip rectangle.
In Firefox 2 and 3, and Opera 9, I can access the rectangle with
document.defaultView.getComputedStyle().
But that doesn't...
|
by: hgarg |
last post by:
The onpaint() is getting called before calculating the required parameters by listBox1_SelectedIndexChanged function. I tried calling it at the end of this function. But of no use. Due to this issue...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| | |