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


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

语法

  1. bool imageantialias ( resource $image , bool $enabled )

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

不支持线宽和风格。

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

参数

  • image: 由图象创建函数(例如imagecreatetruecolor())返回的图象资源。
  • enabled: 是否启用抗锯齿。

返回值

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

实例

  1. <?php
  2. // 使用抗锯齿图片和一个普通图片
  3. $aa = imagecreatetruecolor(400, 100);
  4. $normal = imagecreatetruecolor(200, 100);
  5.  
  6. // 使用抗锯齿功能
  7. imageantialias($aa, true);
  8.  
  9. // 设置颜色
  10. $red = imagecolorallocate($normal, 255, 0, 0);
  11. $red_aa = imagecolorallocate($aa, 255, 0, 0);
  12.  
  13. // 画两条线
  14. imageline($normal, 0, 0, 200, 100, $red);
  15. imageline($aa, 0, 0, 200, 100, $red_aa);
  16.  
  17. // 合并图像
  18. imagecopymerge($aa, $normal, 200, 0, 0, 0, 200, 100, 100);
  19.  
  20. // 输出图像
  21. header('Content-type: image/png');
  22.  
  23. imagepng($aa);
  24. imagedestroy($aa);
  25. imagedestroy($normal);
  26. ?>

以上实例输出结果的图片如下: