Jump to content

ImageMerge or similar, help needed!


helraizer

Recommended Posts

Hi folks and folkesses,

 

myChatbox

 

Again with my chatbox, I am trying to impliment 'smilies' into it, which is proving a challenge.  :P

 

My plan is that if the user types, for example, '=(' it will replace it with a sad emoticon.

I am imagining that I will need to merge (or similar function) the smilie image onto the chatbox image.

 

How would I go about doing this? also how would I get it to put the emoticon at the location of the word that it will replace?

 

Hope this makes sense.

 

Sam

Link to comment
https://forums.phpfreaks.com/topic/75588-imagemerge-or-similar-help-needed/
Share on other sites

myChatbox is a dynamic image made with php and gd2. The text strings in it are being pulled out from a dynamically made .line file. So for this reason it won't behave in quite the same way.

 

So if I just replace the text with the gif instead of the string reading "Yay, that works! =D" it would read "Yay, that works! biggrin.gif" - actually quote the image name rather than the image itself.

 

Would there be anyway, using the merge function or any other function to impose the new/replacement image onto the chatbox image?

 

Sam

well i can explain the basic's of HTML and then suggest you look at the other thread.. or just ask did you read the code in the other thread!?

 

as for a GD2 Chat room.. your going to have a ton of problem... why re-create the wheel!

 

EDIT:

just wondering .. why cant you use imagecopymerge().. ? i assume your using it already for a chat room image!

 

It's not a chatroom as such, more a dynamic shoutbox for use as a forum signature. So far I have implimented colour and font choices. No problems with anything so far!

 

I shall try and impliment the code from the other thread into it, but I already tried something similar and it merely changed the '=)' to the file name, which doesn't really have the same effect. :P

 

I'll give it a go.

 

Sam

 

Edit: So far I'm not using ImageCopyMerge(). This is how my image works.

 

<?php
include("linesfile.php5");
$linesDataFile = new DataFile("data.line");

//$image = ImageCreate(660,240); // create the image canvas
$image = ImageCreateFromPNG("background.png");
$blue = ImageColorAllocate($image, 200, 200, 255); // prepare some blueness
$black = ImageColorAllocate($image, 0, 0, 0); // ... and whiteness

$cur_line_y = 63;  // 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 = 15; // This is how much to move down to print the next line
$pagelinelimit = 12; // This is the maximum number lines of text that can be displayed

ImageFill($image, 0, 0, $blue); // fill the canvas

//ImageString($image, 3, 15, $cur_line_y, trim(stripslashes($wordwrapped[0])), $black);

$numberOfLines = $pagelinelimit;



for($i=0;$i<$numberOfLines;$i++) {
$data = $linesDataFile->getReverseIterate();
if (count($data)==0) continue;
$name = "[" . $data[0] . "] ";
$color = $data[1];
$font = $data[2];
$line = $data[3];

$line = $name . $line;



//ImageString($image, 2, $cur_line_x, $cur_line_y, trim($line), getColor($color));


		imagettftext($image,10,0,$cur_line_x,$cur_line_y,getColor($color),getfont($font),trim($line));

$cur_line_y += $lineheight;

}

function getColor($color) {
global $image;

switch($color) {
	case "black" :
		return ImageColorAllocate($image, 0, 0, 0); 
	case "white" :
		return ImageColorAllocate($image, 255, 255, 255); 
	case "blue" :
		return ImageColorAllocate($image, 0, 0, 205); 
	case "red" :      
		return ImageColorAllocate($image, 255, 0, 0); 
	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, 255); 

}
}

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 "timesnr" :
		return "timesbd.ttf";
	case "calibri" :
		return "calibrib.ttf";
	case "comicsans" :
		return "comicsans.ttf";
	case "palab" :
		return "palab.ttf";
	default:
		return "courbd.ttf";
}
}


header("Content-Type: image/png"); // tell the browser what we're gonna give it
ImagePng($image); // paint the image in browser
ImagePng($image, "./chatbox.png"); //export as png file
ImageDestroy($image); // clean up resources
?>

 

on the index.php page

 

<?php
		include("linesfile.php5");
		$filename = "data.line";
		set_magic_quotes_runtime(0);
		if ($_POST['submit']) {
		// grab the inputted text
		$text = stripcslashes($_POST['input'] . "\n");
		$username = stripslashes($_POST['username']);
		$color = $_POST['color'];
		$font = $_POST['font'];
		$ip = $_SERVER['REMOTE_ADDR'] . "\n";
		$_SESSION['username'] = $username;
		$_SESSION['color'] = $color;


                $dirty = array('many', 'bad', 'words', 'in', 'here'); // I took out the real array just to keep the thread 'clean'.

                        foreach($dirty AS $bad_word){
                        $text = preg_replace("/$bad_word/i","****", $text);
                      }
		$data[] ="\n".$username;
		$data[] =trim($color);
		$data[] =trim($font);
		$data[] =trim($text);


		$datafile = new DataFile($filename);
		if(!$datafile->writeNewLine($data)) die("Error writing to file");
}
      	?>

i think i know what you mean now.. the problem isn't going to getting the image but setting the XY-coordinate

 

outline code only

<?php

function smillies($text)
{
$smilies = array(
  "" => "smile1.gif",
  "" => "wink.gif",
  "" => "grin.gif",
  "" => "tongue.gif",
  "" => "sad.gif",
  ":'(" => "cry.gif",
  ":|" => "noexpression.gif",
  ":-/" => "confused.gif",
  ":-O" => "ohmy.gif",
  "" => "cool1.gif",
  "O:-" => "angel.gif",
  "" => "sleep.gif",
  ":grrr:" => "angry.gif",
  ":smile:" => "smile2.gif",
  "" => "laugh.gif",
  ":cool:" => "cool2.gif",
  ":fun:" => "fun.gif",
  ":thumbsup:" => "thumbsup.gif",
  ":thumbsdown:" => "thumbsdown.gif",
  ":blush:" => "blush.gif"
);

$board = imagecreatefrompng("board.png");

//text for image, problem is find the XY
foreach($smilies as $K => $V)
{
$newtext = str_replace($K, "(15px gap!)", $text); //Get the XY
//pass the XY to here
$Smile= imagecreatefrompng("$V");
imagecopymerge($board, $Smile, X, Y, 0, 0, 15, 15, 100);//15x15 smileiy size

}

//etc

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.