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 图像处理