PHP 繪圖技術

來源:互聯網
上載者:User

1、圖片格式:目前網站開發常見的圖片格式有gif,jpg/jpeg,png .....

區別:
  • gif 圖片壓縮率高,但是只能顯示256色,可能造成顏色的丟失,可以顯示動畫
  • jpg/jpeg 圖片壓縮率高(有損壓縮),可以用較小的檔案來顯示,網頁上用得比較多
  • png 該格式綜合了gif和jpg的優勢,缺點是不能顯示動畫

2、通過PHP編程來繪圖

<?php    //繪圖技術 基本步驟 前提:在php.ini檔案中啟用gd庫    //建立畫布 預設背景是黑色的    $img=imagecreatetruecolor(400,300);    //繪製各種圖形    //建立一個顏色    $background = imagecolorallocate($img, 255, 0, 0);    //畫圓    //imageellipse($img,30,30,50,50,$background);    //橢圓    //imageellipse($img,30,30,50,30,$background);    //畫直線    //imageline($img,0,0,400,300,$background);    //畫矩形    //imagerectangle ($img, 50 , 20 , 100 , 40 , $background);    //填充矩形    //imagefilledrectangle ($img, 50 , 20 , 100 , 40 , $background);    //畫弧線    //imagearc($img, 100, 100, 150, 150, 180, 270, $background);    //畫扇型  IMG_ARC_CHORD直線串連了起始和結束點   IMG_ARC_PIE    //imagefilledarc($img, 100, 100, 150, 150, 180, 270, $background,IMG_ARC_PIE);        //拷貝圖片到畫布/*    $scrImg=imagecreatefromgif('http://www.baidu.com/img/shouye_b5486898c692066bd2cbaeda86d74448.gif');    $scrImgInfo=getimagesize('http://www.baidu.com/img/shouye_b5486898c692066bd2cbaeda86d74448.gif');    imagecopy ($img,$scrImg,10,10,0,0,$scrImgInfo[0],$scrImgInfo[1]);*/    //imagecopy ($img,$scrImg,10,10,0,0,270,129);        //寫字    //imagestring ($img , 5 , 20 , 20 , "hello,world", $background );    //寫中文    $str="PHP繪畫技術";    imagettftext ($img , 30 , 0 , 50 ,50, $background , "MSYHBD.TTF" , $str);    //輸出映像到網頁(或者另存新檔)    header("content-type: image/png");    imagepng($img);    //銷毀該圖片(釋放記憶體)    imagedestroy($img);?>

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.