I'm unable to combine these codes. I have tested but not working (error). Pls help me
show ip
<?php
$img_number = imagecreate(275,225);
$backcolor = imagecolorallocate($img_number,102,102,153);
$textcolor = imagecolorallocate($img_number,205,205,205);
imagefill($img_number,0,0,$backcolor);
$number = " Your IP is $_SERVER[REMOTE_ADDR]";
Imagestring($img_number,10,5,5,$number,$textcolor);
header("Content-type: image/jpeg");
imagejpeg($img_number);
?>
+ background image
<?php
$im = imagecreatefrompng("imagetest.png");
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>
in a file (image.php) /please help me /thanks
What you want to do is replace the first 2 lines (except <?php
) and fourth line in the first script with the first line in the second script.
In the first script, you are creating the image resource, creating a color resource and then filling the background. Instead, you want to create the image resource from an image and fill the background with that image.
Try this:
<?php
$img = imagecreatefrompng("imagetest.png");
$textcolor = imagecolorallocate($img,205,205,205);
$number = "Your IP is {$_SERVER[REMOTE_ADDR]}"; //Also note the interpolation here. Not neccesary but it is nicer
imagestring($img,10,5,5,$number,$textcolor);
header("Content-type: image/jpeg");
imagejpeg($img);
imagedestroy($img);
I have not tested this, however with having done similar things myself, I am confident that it will work. I would suggest however, that rather than hard coding the position of the text, you can compute the best place to put it based on the image's size. look at the getimagesize function.