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

imageantialias

(PHP 4 >= 4.3.2, PHP 5, PHP 7, PHP 8)

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

說明

imageantialias(resource $image, bool $enabled): bool

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

不支援線寬和風格。

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

參數

image

由圖像建立函式(例如imagecreatetruecolor())返回的 GdImage 對象。

enabled

是否啟用抗鋸齒。

返回值

成功時返回 true, 或者在失敗時返回 false。

範例

示例 #1 A comparison of two lines, one with anti-aliasing switched on

<?php
// Setup an anti-aliased image and a normal image
$aa = imagecreatetruecolor(400, 100);
$normal = imagecreatetruecolor(200, 100);

// Switch antialiasing on for one image
imageantialias($aa, true);

// Allocate colors
$red = imagecolorallocate($normal, 255, 0, 0);
$red_aa = imagecolorallocate($aa, 255, 0, 0);

// Draw two lines, one with AA enabled
imageline($normal, 0, 0, 200, 100, $red);
imageline($aa, 0, 0, 200, 100, $red_aa);

// Merge the two images side by side for output (AA: left, Normal: Right)
imagecopymerge($aa, $normal, 200, 0, 0, 0, 200, 100, 100);

// Output image
header('Content-type: image/png');

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

以上例程的輸出類似於:

Output of example : A comparison of two lines, one with anti-aliasing switched on

註釋

參見

Leave a Reply

Your email address will not be published. Required fields are marked *