0

我无法组合这些代码。我已经测试但没有工作(错误)。请帮助我

显示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);
    ?>

+ 背景图片

<?php
$im = imagecreatefrompng("imagetest.png");
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>

在文件(image.php)中/请帮助我/谢谢

4

1 回答 1

0

您要做的是将第一个脚本中的前 2 行(除了<?php)和第四行替换为第二个脚本中的第一行。

在第一个脚本中,您将创建图像资源、创建颜色资源然后填充背景。相反,您想从图像创建图像资源并用该图像填充背景。

尝试这个:

<?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);

我没有对此进行测试,但是我自己做过类似的事情,我相信它会起作用。但是,我建议您不要对文本的位置进行硬编码,而是可以根据图像的大小来计算放置它的最佳位置。查看getimagesize函数。

于 2017-08-08T05:05:49.130 回答