在图像的底部画一条黑线,PHP

在图像的底部画一条黑线,PHP,php,image,Php,Image,我写了这段代码,本来应该在图像底部画一条1px的黑线,但它没有按预期工作,它生成了一个完全黑色的图像: $img = imagecreatefrompng("image.png"); $dest = imagecreatetruecolor(50, 25); imagecopy($dest, $img, 0, 0, $px + $position[$pos][0], $py + $position[$pos][1] , 50, 25); $w = imag

我写了这段代码,本来应该在图像底部画一条1px的黑线,但它没有按预期工作,它生成了一个完全黑色的图像:

    $img = imagecreatefrompng("image.png");    
    $dest = imagecreatetruecolor(50, 25);
    imagecopy($dest, $img, 0, 0, $px + $position[$pos][0], $py + $position[$pos][1] , 50, 25);
    $w = imagesx($dest);
    $h = imagesy($dest);
    $out = ImageCreateTrueColor(imagesx($dest),imagesy($dest)) or die('Problem In Creating image');

    for( $x=0; $x<$w; $x++) {
        imagesetpixel($out, $x, $h, imagecolorallocate($out, 0, 0, 0));
    }
$img=imagecreatefrompng(“image.png”);
$dest=imagecreatetruecolor(50,25);
图像复制($dest、$img、0、0、$px+$position[$pos][0]、$py+$position[$pos][1]、50、25);
$w=图像X($dest);
$h=图像系统($dest);
$out=ImageCreateTureColor(imagesx($dest)、imagesy($dest))或die(‘创建图像时出现问题’);

对于($x=0;$x您的
$y
没有设置,我认为这只是一个打字错误,您设置了
$h
,并使用了
$y

问题是您在
$out
图像上画线,而该图像中没有任何内容

  • 您可以加载
    $img
    (原件)
  • 您可以创建
    $dest
  • 您可以将
    $img
    调整为
    $dest
  • 您可以创建
    $out
  • 您可以在
    $out
    上划线

  • $out
    从未获得原始图像或已调整大小的图像的副本,因此它保持默认的全黑。然后在黑色图像上画一条黑线…最终得到一个黑色图像。

    谢谢!但这并没有解决错误,我几分钟前注意到它,即使我更改它,图像结果也是全黑的。p.S.$y已准备就绪但是设置为使打字不起很大作用:)您是否尝试过:
    imageline(资源$image,int$x1,int$y1,int$x2,int$y2,int$color)
    (看起来更简单)?另外,在循环之前,您能否确认图片输出是否正确?您在哪里设置标题?