Hướng dẫn dùng anti alias trong PHP

[PHP 4 >= 4.3.2, PHP 5, PHP 7, PHP 8]

imageantialiasShould antialias functions be used or not

Description

imageantialias[GdImage $image, bool $enable]: bool

Thickness and styled are not supported.

Using antialiased primitives with transparent background color can end with some unexpected results. The blend method uses the background color as any other colors. The lack of alpha component support does not allow an alpha based antialiasing method.

Parameters

image

A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor[].

enable

Whether to enable antialiasing or not.

Return Values

Returns true on success or false on failure.

Changelog

VersionDescription
8.0.0 image expects a GdImage instance now; previously, a resource was expected.
7.2.0 imageantialias[] is now generally available. Formerly it was only available if PHP was compiled with the bundled version of the GD library.

Examples

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

The above example will output something similar to:

padigan

15 years ago

If you can't be bothered creating [or searching for] a full screen antialias function.
You can actually cheat [well a bit of a dirty inefficient hack really!!]
and perform a fake antialias on an image by using 'imagecopyresampled'...

first create your source image twice the size of what you really want.

Then use 'imagecopyresampled' to shrink it to half the size, the function
automatically interpolates pixels to create an antialias effect!

I've used this in a pie chart function and it works brilliantly,
not as slow as I thought it might be!

the rough code below should give you the idea...

trimbo

16 years ago

So far using PHP 5.0.4 I've managed to get Imageantialias[] to work well with:
ImageLine[]
ImagePolygon[]

but not with:
ImageArc[]
ImageEllipse[]
ImageFilled*[]

You can still draw antialiased filled polygons by drawing a hollow polygon on top of a filled one with the same dimensions:

n-dream at gmx dot ch

16 years ago

The following function draws an AntiAliased [unfilled] Ellipse.
It is used just liked the nomral ImageEllipse function.
The optional parameter sets the number of segments...

function ImageEllipseAA[ &$img, $x, $y, $w, $h,$color,$segments=70]
{
    $w=$w/2;
    $h=$h/2;
    $jump=2*M_PI/$segments;
    $oldx=$x+sin[-$jump]*$w;
    $oldy=$y+cos[-$jump]*$h;
    for[$i=0;$i

Bài Viết Liên Quan

Chủ Đề