|
użytkowników online: 82
|
OPINIE UŻYTKOWNIKÓW
|
Prawdziwa skarbnica wiedzy na temat tworzenia stron WWW i nie tylko. Korzystam z porad praktycznie codziennie, jest mi to niezbędne w mojej pracy. Sam zajmuję się tworzeniem serwisów, ale porady pisane przez Darka sa dla mnie nieocenioną pomocą! Proste, czytelne i zrozumiałe dla każdego! Czekam na więcej!
Krzysztof Szypulski
KESS - projektowanie stron
|
|
PODRĘCZNIK PHP 5.x, 4.x, 3.x - częściowo spolszczony / źródło: www.php.net
[Spis]
[A]
[B]
[C]
[D]
[E]
[F]
[G]
[H]
[I]
[J]
[K]
[L]
[M]
[N]
[O]
[P]
[Q]
[R]
[S]
[T]
[U]
[V]
[X]
[W]
[Z]
imageantialias (PHP 4 >= 4.3.2, PHP 5) imageantialias --
Should antialias functions be used or not
Descriptionbool imageantialias ( resource im, bool on ) | Ostrzeżenie | Ta funkcja jest obecnie
nieudokumentowana, dostępna jest jedynie lista jej argumentów.
|
Notatka: Ta funkcja jest dostępna tylko jeśli
PHP zostało skompilowane z dołączoną wersją biblioteki GD.
See also imagecreatetruecolor().
User Contributed Notesvoinic at NOSgmailPAM dot com
12-Jan-2006 11:22
The only trick I found to draw an antialiased polygon AND keep it transparent (to use them as overlays in google maps for example)... make two images and merge them. Order of operations is important and the transparency color of the final image must be set after the merge:
<?
header("Content-type: image/png");
$values = array(
40, 50, 20, 240, 60, 60, 240, 20, 50, 40, 10, 10 );
$im = imagecreate(250, 250);
$bg = imagecolorallocate($im, 255, 255, 255);
$im2 = imagecreatetruecolor(250, 250);
$bg2 = imagecolorallocate($im2, 255, 255, 255);
imagefilledrectangle($im2,0,0,249,249,$bg2);
imagecolortransparent($im2, $bg);
imageantialias($im2, true);
$c_red = imagecolorallocate($im2, 255, 0, 0);
imagepolygon($im2, $values, 6, $c_red);
imageantialias($im2, false);
imagecopymerge($im, $im2,0,0,0,0,250,250,50);
imagecolortransparent($im, $bg);
$c_red_alpha = imagecolorallocatealpha($im, 255, 0, 0, 60);
imagefilledpolygon($im, $values, 6, $c_red_alpha);
imagepng($im);
imagedestroy($im);
imagedestroy($im2);
?>
sebbi at conceptT dot com
26-Sep-2005 04:06
I did a search in google and got following url:
http://www.isocalc.com/tutorials/antialias.htm
With this tutorial I was able to write a function to convert this algorithm into php, the result for a filled circel is this:
<?php
function imagefilledcircleantialiased(&$im, $cx, $cy, $r, $fgcolor, $bgcolor) {
$fgcolors = imagecolorsforindex($im,$fgcolor);
$bgcolors = imagecolorsforindex($im,$bgcolor);
for ( $x = $cx - $r; $x <= $cx + $r; $x++ ) {
for ( $y = $cy - $r; $y <= $cy + $r; $y++ ) {
$rx = $x - $cx; $ry = $y - $cy;
$ir = sqrt(( $rx == 0 ? 0 : pow($rx - 0.5*abs($rx)/$rx, 2) ) + ( $ry == 0 ? 0 : pow($ry - 0.5*abs($ry)/$ry, 2) ));
$or = sqrt(( $rx == 0 ? 0 : pow($rx + 0.5*abs($rx)/$rx, 2) ) + ( $ry == 0 ? 0 : pow($ry + 0.5*abs($ry)/$ry, 2) ));
if ( $or <= $r ) {
imagesetpixel($im, $x, $y, $fgcolor);
}
elseif ( $ir < $r ) {
$filled = 0;
for ( $xx = $x - 0.45; $xx < $x + 0.5; $xx+=0.1 ) {
for ( $yy = $y - 0.45; $yy < $y + 0.5; $yy+=0.1 ) {
$rxx = $xx - $cx; $ryy = $yy - $cy;
if ( sqrt(pow($rxx, 2) + pow($ryy, 2)) < $r ) $filled++;
}
}
$red = round($bgcolors['red'] + ( $fgcolors['red'] - $bgcolors['red'] ) * $filled / 100);
$green = round($bgcolors['green'] + ( $fgcolors['green'] - $bgcolors['green'] ) * $filled / 100);
$blue = round($bgcolors['blue'] + ( $fgcolors['blue'] - $bgcolors['blue'] ) * $filled / 100);
imagesetpixel($im, $x, $y, imagecolorclosest($im, $red, $green, $blue));
}
}
}
}
$width = 160;
$height = 200;
$r = 20;
$bgc = "651713";
$fgc = "b12b2c";
$im = imagecreate($width, $height);
$bgcolor = imagecolorallocate($im, hexdec(substr($bgc, 0, 2)), hexdec(substr($bgc, 2, 2)), hexdec(substr($bgc, 4, 2)));
for( $i = 0; $i < 100; $i++ ) {
imagecolorallocate($im, ( hexdec(substr($fgc, 0, 2)) + $i*hexdec(substr($bgc, 0, 2))) / ($i + 1), ( hexdec(substr($fgc, 2, 2)) + $i*hexdec(substr($bgc, 2, 2))) / ($i + 1), ( hexdec(substr($fgc, 4, 2)) + $i*hexdec(substr($bgc, 4, 2))) / ($i + 1));
}
$fgcolor = imagecolorclosest($im, hexdec(substr($fgc, 0, 2)), hexdec(substr($fgc, 2, 2)), hexdec(substr($fgc, 4, 2)));
imagefilledcircleantialiased($im, 80, 100, $r, $fgcolor, $bgcolor);
header("Content-Type: image/png");
imagepng($im);
?>
An improvement would be to draw the inner rectangle or more rectangles in the circle with the builtin rectangle function to reduce the usage of imagesetpixel() from (2*r)^2 to 2*Pi*(r + epsilon), in other words, the dependency on r would break down from square to linear.
Another improvement would be to determine filled and unfilled triangles in the observed pixel and calculate their areas, so we can get rid of the inner loops for getting the fraction filled/unfilled.
One can easily modify this function to solve other problems like lines, unfilled circles, etc.
trimbo
06-Sep-2005 09:25
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:
<?php
$points=array($x,$y, $x2,$y2, $x3,$y3);
imageFilledPolygon($im, $points, 3, $gray );
imagePolygon($im, $points, 3, $gray );
?>
klaas at kosmokrator dot com
24-May-2004 04:21
logang at deltatee dot com
06-Aug-2003 12:28
I've writen some antialiasing functions for people who don't have the requirements for the builtin antialiasing.
You can download a copy at: http://grey.deltatee.com/image.phps
Igor Garcia
30-Jun-2003 11:57
This function its only available if you have the BUNDLED version of GD.
(PHP 4.3.2)
|