怎麼使用php的gd庫畫一條消除鋸齒的粗斜線

來源:互聯網
上載者:User
如何使用php的gd庫畫一條消除鋸齒的粗斜線?
如題,使用多邊形畫的填充圖是有鋸齒的。imageantialias函數是無效的。

------解決方案--------------------
點陣圖有鋸齒是必然的
imageantialias 的消除鋸齒是有作用的,你可以對比他開啟和關閉時的效果
如果你對 imageantialias 的效果不滿意(畢竟GD不是專業的影像處理包),那就要你自己編程解決了

------解決方案--------------------
他是擾碼加密的,有空研究一下
------解決方案--------------------
好無聊啊,最終是用 js 實現的
------解決方案--------------------
JS有現成的外掛程式 做出來的很漂亮。。。用PHP幹嘛
------解決方案--------------------
給你一個早年寫的代碼,供參考
PHP code
create(func_get_arc(0),func_get_arc(1));    else        $this->create(400,300);  }  /**   * 在($x,$y)處畫點   */  function pixel($x,$y) {    $p = $this->get_view($x,$y);    imagesetpixel($this->im,$p['x'],$p['y'],$this->color);    $this->xo = $p['x'];    $this->yo = $p['y'];  }  /**   * 移動到($x,$y)處   */  function moveto($x,$y) {    $p = $this->get_view($x,$y);    $this->xo = $p['x'];    $this->yo = $p['y'];  }  /**   * 從($x1,$y1)到($x2,$y2)處畫線   */  function line($x1,$y1,$x2,$y2) {    $p1 = $this->get_view($x1,$y1);    $p2 = $this->get_view($x2,$y2);    imageline($this->im,$p1['x'],$p1['y'],$p2['x'],$p2['y'],$this->color);  }  /**   * 從當前位置到($x,$y)處畫線   */  function lineto($x,$y) {    $p = $this->get_view($x,$y);    imageline($this->im, $this->xo, $this->yo, $p['x'], $p['y'], $this->color);    $this->xo = $p['x'];    $this->yo = $p['y'];  }  /**   * 設定使用中色彩   */  function color($clr) {    $r = ($clr>>16) & 0xff;     $g = ($clr>>8) & 0xff;     $b = ($clr) & 0xff;     $this->color = ImageColorAllocate($this->im, $r,$g,$b);    $this->fillcolor = ImageColorAllocate($this->im, $r,$g,$b);    $this->filldarkcolor = ImageColorAllocate($this->im, $r/2,$g/2,$b/2);    return $this->color;  }  /**   * 設定當前充填顏色   */  function fillcolor($clr) {    $r = ($clr>>16) & 0xff;     $g = ($clr>>8) & 0xff;     $b = ($clr) & 0xff;     $this->fillcolor = ImageColorAllocate($this->im, $r,$g,$b);    return $this->fillcolor;  }  /**   * 建立GD控制代碼並設定座標系   */  function create($x,$y) {    $this->im = imagecreatetruecolor($x,$y);imageantialias($this->im, 1);imagefill($this->im, 0, 0, $this->color(0xffffff));    $this->viewx = $x-1;    $this->viewy = -($y-1);    $this->winx = $x;    $this->winy = $y;    $this->orgx = 0;    $this->orgy = 0;//$y;    $this->colors = $this->color(0xffffff);    settype($this->ksin,"double");    settype($this->kcos,"double");    $this->ksin = sin(deg2rad(0));    $this->kcos = cos(deg2rad(0));  }  /**   * 座標映射   */  function get_view($x,$y) {    $this->xo = $x*$this->kcos - $y*$this->ksin;    $this->yo = $x*$this->ksin + $y*$this->kcos;    $p['x'] = ($this->xo + $this->orgx)*($this->viewx/$this->winx);    $p['y'] = ($this->yo + $this->orgy)*($this->viewy/$this->winy)-$this->viewy;    return $p;  }  /**   * 設定限度   */  function set_ext($x,$y=0) {    $this->winx = $x;    if($y == 0) {        $this->winy = - $x * $this->viewy / $this->viewx;    }else {        $this->winy = $y;    }  }  /**   * 設定旋轉角   */  function set_r($p) {    $this->ksin = sin(deg2rad($p));    $this->kcos = cos(deg2rad($p));  }  /**   * 構造圖形,必需在衍生類別中重載本方法   */  function paint() {    /**     * 必需由衍生類別重載     * 必需包含語句 $this->create(寬度,高度);     */    die("paint 方法必需由衍生類別重載!");  }  /**   * 輸出圖形   */  function run() {    $this->paint();    $func = "Image".$this->type;    if(! function_exists($func)) {        $this->type = "png";        $func = "Image".$this->type;    }    Header("Content-type: image/{$this->type}");    $func($this->im);    imageDestroy($this->im);  }  /**   * 圓類圖形資料產生,參數$p為座標旋轉角   */  function get_point($ox,$oy,$w,$h,$start,$end) {    $a = $w/2;    $b = $h/2;    $rs = array();    $i = $start;    for($i=$start;$i<=$end;$i+=5) {        $n = deg2rad($i);        $x = $a*cos($n);        $y = $b*sin($n);        $p = $this->get_view($ox+$x,$oy+$y);        $rs[] = $p['x'];        $rs[] = $p['y'];        if($i == $end) break;        if($i+5 > $end) $i = $end - 5;    }    $p = $this->get_view($ox,$oy);    $rs[] = $p['x'];    $rs[] = $p['y'];    $rs[] = $rs[0];    $rs[] = $rs[1];    return $rs;  }  /**   * 弓形   */  function chord($left,$top,$w,$h,$start,$end,$z=0) {    $ar = $this->get_point($left,$top,$w,$h,$start,$end,$p);    for($i=0;$iget_view($ar[$i],$ar[$i+1]);        $ar[$i] = $p['x'];        $ar[$i+1] = $p['y'];    }    imagefilledpolygon($this->im,$ar,count($ar)/2-1,$this->fillcolor);    imagepolygon($this->im,$ar,count($ar)/2-1,$this->color);  }  /**   * 扇形   */  function pie($left,$top,$w,$h,$start,$end,$z=0) {    $this->get_view($left,$top+$z);    $ar = $this->get_point($left,$top+$z,$w,$h,$start,$end);    $this->get_view($left,$top);    $arh = $this->get_point($left,$top,$w,$h,$start,$end);    for($j=0;$jfilltype)            imagefilledpolygon($this->im,$t,4,$this->filldarkcolor);        else            imagepolygon($this->im,$t,4,$this->color);    }    if($this->filltype)        imagefilledpolygon($this->im,$ar,count($ar)/2-1,$this->fillcolor);  }  /**   * 弧形   */  function arc($left,$top,$w,$h,$start,$end,$z=0) {    $ar = $this->get_point($left,$top,$w,$h,$start,$end,$p);    $this->moveto($ar[0],$ar[1]);    for($i=2;$ilineto($ar[$i],$ar[$i+1]);  }}/** * 重載基類的paint方法 */class myGraph extends Graph {  function paint() {//    $this->create(400,300);    $this->create(200,150);$this->set_ext(400);    $this->set_r(10); // 旋轉    $this->filltype = false; //充填    $k = 40;    //高    $a =200;    //中心x    $b = 150;    //中心y    $c = 200;    //長軸    $d = 100;    //短軸    $this->color(0x000000);    $this->color(0xff0000);    $this->pie($a,$b,$c,$d,0,100,$k);    $this->color(0x00ff00);    $this->pie($a,$b,$c,$d,120,240,$k);    $this->color(0x0000ff);    $this->pie($a+10,$b-10,$c,$d,240,360,$k);    $this->color(0x8080ff);    $this->pie(50,80,40,20,0,360,50);    $this->line($a,0,$a,$b*2);    $this->line(0,$b,$a*2,$b);  }}$g = new myGraph;$g->run();
  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.