php gd imagesetpixel,像素与像素和图像内部模型的关系不是1对1

时间:2010-07-08 20:24:57

标签: php gd

<?
    $img_w = 800;
    $img_h = 600;
    $img = imagecreate($img_w, $img_h);
    $color = imagecolorallocate($img, 230, 230, 230);
    $imgname = "gd_img.png";


    for($n=0; $n < $img_w; $n++)
    {
        plot($n , $img_h/2, imagecolorallocate($img, 200, 0, 0));
        plot($n+4 , $img_h/2 + 10, imagecolorallocate($img, 0, 200, 0));
        plot($n*2 , $img_h/2 + 20, imagecolorallocate($img, 0, 0, 200));
    }
    imagepng($img, $imgname, $color);
    imagedestroy($img);


    function plot($x, $y, $color=0)
    {

        imagesetpixel($GLOBALS['img'], $x, $y, $color);
    }

?>

尝试一下,你会看到应该有一个800像素宽的实线。至少在我的结尾没有。 FireFox WebDeveloper插件(misc-&gt;显示标尺下的标尺工具)显示大约83像素宽的顶行。

1 个答案:

答案 0 :(得分:0)

根据您插入图片的HTML代码,您的浏览器可以调整图片大小以适合页面元素。