php建立不失真高清圖片實現代碼

來源:互聯網
上載者:User

//建立映像
$im=imagecreatetruecolor(100,100);
//將背景設為紅色
$red=imagecolorallocate($im,255,0,0);
imagefill($im,0,0,$red);
//輸出映像
header('content-type: image/png');
imagepng($im);
imagedestroy($im);
/*
執行該代碼,將產生背景為紅色的圖形。
*/

//代碼二

//建立真彩色映像
$img=imagecreatetruecolor(400,400);
//通過迴圈執行操作
for($i=10;$i<=350;$i=$i+20)
{
  //定義顏色
  $color=imagecolorallocate($img,200,50,$i);
  //畫出橢圓
  imageellips教程e($img,200,200,350,$i,$color);
}
//輸出映像
header("content-type: image/png");
imagepng($img);
//銷毀映像
imagedestroy($img);
/*
該代碼的執行結果如圖:22.7所示:
*/
//代碼三

//建立真彩色映像
$img=imagecreatetruecolor(200,200);
$white=imagecolorallocate($img,255,255,255);
$red=imagecolorallocate($img,255,0,0);
$blue=imagecolorallocate($img,0,0,255);
//在映像上畫圖
imagearc($img,100,100,50,150,360,0,$red);
imagearc($img,100,100,150,50,0,360,$blue);
//輸出映像
header("content-type: image/png");
imagepng($img);
//銷毀映像
imagedestroy($img);
/*
該代碼的的執行結果如圖22.6所示:
*/


//執行個體四

//發送標頭檔
header("content-type: image/png");
//建立映像,如果失敗輸出內容
$im=imagecreatetruecolor(500,500);      //建立映像
//定義背景顏色
$black=imagecolorallocate($im,0,0,0);
//定義線顏色
$color=imagecolorallocate($im,0,255,255);
//在映像上畫出虛線
imageline($im,1,1,450,450,$color);
//輸出影像檔
imagepng($im);
//銷毀映像
imagedestroy($im);

聯繫我們

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