导航首页 » 技术教程 » PHP:imageantialias()的用法_GD库图像处理函数
PHP:imageantialias()的用法_GD库图像处理函数 146 2023-12-15   

imageantialias

(PHP 4 >= 4.3.2, PHP 5)

imageantialias — 是否使用抗锯齿(antialias)功能

说明

bool imageantialias ( resource $image , bool $enabled )

对线段和多边形启用快速画图抗锯齿方法。不支持 alpha 部分。使用直接混色操作。仅用于真彩色图像。

不支持线宽和风格。

使用抗锯齿和透明背景色可能出现未预期的结果。混色方法把背景色当成任何其它颜色使用。缺乏 alpha 部分的支持导致不允许基于 alpha 抗锯齿方法。

参数

image

由图象创建函数(例如imagecreatetruecolor())返回的图象资源。

enabled

是否启用抗锯齿。

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

范例

Example #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);
?>

以上例程的输出类似于:

注释

Note: 此函数仅在与 GD 库捆绑编译的 PHP 版本中可用。

参见

imagecreatetruecolor() - 新建一个真彩色图像


!!!站长长期在线接!!!

网站、小程序:定制开发/二次开发/仿制开发等

各种疑难杂症解决/定制接口/定制采集等

站长微信:lxwl520520

站长QQ:1737366103