Latest web development tutorials

PHP imageantialias – 是否使用抗鋸齒(antialias)功能

PHP 圖像處理 PHP圖像處理

imageantialias — 是否使用抗鋸齒(antialias)功能。

語法

bool imageantialias ( resource $image , bool $enabled )

對線段和多邊形啟用快速畫圖抗鋸齒方法。 不支持alpha 部分。 使用直接混色操作。 僅用於真彩色圖像。

不支持線寬和風格。

使用抗鋸齒和透明背景色可能出現未預期的結果。 混色方法把背景色當成任何其它顏色使用。 缺乏alpha 部分的支持導致不允許基於alpha 抗鋸齒方法。

參數

  • image :由圖像創建函數(例如imagecreatetruecolor())返回的圖像資源。
  • enabled :是否啟用抗鋸齒。

返回值

成功時返回TRUE, 或者在失敗時返回FALSE。

實例

<?php
//  使用抗锯齿图片和一个普通图片
$aa = imagecreatetruecolor(400, 100);
$normal = imagecreatetruecolor(200, 100);

// 使用抗锯齿功能
imageantialias($aa, true);

// 设置颜色
$red = imagecolorallocate($normal, 255, 0, 0);
$red_aa = imagecolorallocate($aa, 255, 0, 0);

// 画两条线
imageline($normal, 0, 0, 200, 100, $red);
imageline($aa, 0, 0, 200, 100, $red_aa);

// 合并图像
imagecopymerge($aa, $normal, 200, 0, 0, 0, 200, 100, 100);

// 输出图像
header('Content-type: image/png');

imagepng($aa);
imagedestroy($aa);
imagedestroy($normal);
?>

以上實例輸出結果的圖片如下:

PHP 圖像處理 PHP圖像處理