Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP gd库,如何在现有PNG图像上绘制线_Php_Gd - Fatal编程技术网

PHP gd库,如何在现有PNG图像上绘制线

PHP gd库,如何在现有PNG图像上绘制线,php,gd,Php,Gd,也许有人能帮我,因为我被困在这里了。 所以我有一张560x225大小的zem.png图像。它有透明的背景。我需要用gd库从x,y到x1,x2画线(我需要画5-7条线,但最好能得到一个简单的例子,如何画一条线) 以下是如何创建我的透明图像: // Kuriame paveiksleli pasinaudodami GD library keliams tarp miestu pavaizduoti $im = imagecreatetruecolor(560, 225); $red = image

也许有人能帮我,因为我被困在这里了。 所以我有一张560x225大小的zem.png图像。它有透明的背景。我需要用gd库从x,y到x1,x2画线(我需要画5-7条线,但最好能得到一个简单的例子,如何画一条线)

以下是如何创建我的透明图像:

// Kuriame paveiksleli pasinaudodami GD library keliams tarp miestu pavaizduoti
$im = imagecreatetruecolor(560, 225);
$red = imagecolorallocate($im, 255, 0, 0);
$black = imagecolorallocate($im, 0, 0, 0);

// Make the background transparent
imagecolortransparent($im, $black);

// Issaugome paveiksleli
imagepng($im, './zem.png');
imagedestroy($im);
创建此图像后,我将其用作表或div的背景图像。我的表格ir div被划分为x-35块和y-25块

我选择了4个点或4个块来放置其他图像,下面是我如何生成这些rondom块:

$x = rand(1, 35);
$y = rand(1, 25);
$x2 = rand(1, 35);
$y2 = rand(1, 25);
$x3 = rand(1, 35);
$y3 = rand(1, 25);
$x4 = rand(1, 35);
$y4 = rand(1, 25);
单块大小为16x9。我需要从每个生成的块到其他块(代表城市的道路)画一条线,所以我必须将x(x2,x3..)乘以16,y乘以9,才能准确地知道线的起点和终点的正确坐标。所以我要这样做:

// Breziame kelius
$kordinate = $x * 16;
$kordinate2 = $y * 9;
$kordinate3 = $x2 * 16;
$kordinate4 = $y2 * 9;

好的,我现在有一条线的坐标了。这就是我被困的地方。我试过很多例子,比如人们预先创造了funkcions等等。但我仍然无法使用PHPGD库来划分界限。那么也许有人可以提出一些建议?要在imagecreating代码中添加一些内容,或者简单地删除它,只需留下空白的透明图像并打开它,然后画一条线……

当我制作表格或地图图像时,我总是准备一个类和函数。我不确定它是否有用,但这是我的示例代码。您可以将此文件命名为GridTb.php并运行它

 <?php
header('Content-type: image/png');
$GridTb = new GridTb();
$GridTb->pngfile(330, 700);

class GridTb {

    function pngfile($width, $height) {

        define("WIDTH", $width);
        define("HEIGHT",$height);


        $png_image = imagecreate(WIDTH, HEIGHT);

        imagecolorallocate($png_image, 255, 255, 255);
        imagesetthickness($png_image, 1);
        $black = imagecolorallocate($png_image, 0, 0, 0);

        $x = 0;
        $y = 0;
        $w = imagesx($png_image) - 1;
        $z = imagesy($png_image) - 1;
        //basic square frame
        imageline($png_image, $x, $y, $x, $y + $z, $black);
        imageline($png_image, $x, $y, $x + $w, $y, $black);
        imageline($png_image, $x + $w, $y, $x + $w, $y + $z, $black);
        imagerectangle($png_image, $x, $y + $z, $x + $w, $y + $z, $black);

        $wid = 30;
        // $h=40;
        for ($row = 0; $row < 10; $row++) {

            imageline($png_image, $wid, HEIGHT, $wid, 0, $black);
            $wid+=30;
            imageline($png_image, $wid, HEIGHT, $wid, 0, $black);

            for ($h = 40; $h < 701; $h++) {

                $h2 = array(60,200,150,150,100);
                imageline($png_image, WIDTH, $h, 0, $h, $black);
                $h+=60;
                imageline($png_image, WIDTH, $h, 0, $h, $black);
                $h+=200;
                imageline($png_image, WIDTH, $h, 0, $h, $black);
                $h+=150;
                imageline($png_image, WIDTH, $h, 0, $h, $black);
                $h+=150;
                imageline($png_image, WIDTH, $h, 0, $h, $black);
                $h+=100;
                imageline($png_image, WIDTH, $h, 0, $h, $black);
                //sum of $h = 700
            }
        }
        imagepng($png_image);
        imagedestroy($png_image);
    }

}

?>
<IMG src="GridTb.php">


那你有什么问题?您使用线条绘制功能,但没有效果?还是别的?是的,没有效果。下面是我使用的函数示例:imageline($im,$kordinate,$kordinate2,$kordinate3,$kordinate4,$red);什么也没发生:/你能分享整个绘图代码吗?哦,找出,错误在代码的其他部分。。。我真傻。整个代码很长而且很混乱,所以我认为它对其他人没有多大帮助。那么,你解决了你的问题吗?顺便说一句,我实际上只谈到了绘图代码:)