Portrety Uliczne Nieznajomych - zobacz wyjątkową galerię portretów z warszawskich ulic
ZALOGUJ SIĘ
login:
hasło:
przypomnij hasło
załóż konto użytkownika
(i zobacz kilka porad gratis)
   
WYSZUKIWARKA I DZIAŁY
całe porady  tytuły
zaznacz działy do przeszukania
(brak wyboru = wszystkie działy)
PHP
MySQL >
PostgreSQL
SQLite
Perl
Java
XML
XSLT
XPath
WML
SVG
RegExp
Wyszukiwarki
Ochrona
VBScript
Google Plus
XHTML/CSS
JavaScript
Grafika
Flash
Photoshop
Windows
Linux
Bash
Apache
Procmail
E-biznes
Explorer
Opera
Firefox
Inne porady
   
KURSY, DOKUMENTACJE
Własne:
XHTML/CSS
JavaScript
ActionScript
WML, RSS, SSI
Pozostałe:
PHP
MySQL
Java API
więcej...
   
użytkowników online: 86
W CZYM MOGĘ POMÓC?


   
OPINIE UŻYTKOWNIKÓW
W takich dniach, jak ten, nie żałuję, że wykupiłem abonament. Korzystam z porad na tych stronach nawet kilkanaście razy w tygodniu i dzięki nim prace nad stronami dla klientów idą mi o wiele szybciej, a strony wyglądają bardziej profesjonalnie. Nie wiem, jak mogłem wcześniej pracować bez dostępu do porad w tym serwisie!

Wojciech Miszkiewicz

   
GALERIA FOTOGRAFII
   
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]

imagearc

(PHP 3, PHP 4, PHP 5)

imagearc -- Draw a partial ellipse

Description

int imagearc ( resource image, int cx, int cy, int w, int h, int s, int e, int color )

imagearc() draws a partial ellipse centered at cx, cy (top left is 0, 0) in the image represented by image. W and h specifies the ellipse's width and height respectively while the start and end points are specified in degrees indicated by the s and e arguments. 0° is located at the three-o'clock position, and the arc is drawn clockwise.

Przykład 1. Drawing a circle with imagearc()

<?php

// create a 200*200 image
$img = imagecreate(200, 200);

// allocate some colors
$white = imagecolorallocate($img, 255, 255, 255);
$black = imagecolorallocate($img, 0, 0, 0);
  
// draw a black circle
imagearc($img, 100, 100, 150, 150, 0, 360, $black);

// output image in the browser
header("Content-type: image/png");
imagepng($img);
  
// free memory
imagedestroy($img);

?>

See also imageellipse(), imagefilledellipse(), and imagefilledarc().




User Contributed Notes

mojiro at awmn dot net
13-Dec-2005 09:28

A previous for the Rotated (Filled)Ellipse note from(nojer2 at yahoo dot com, 02-Apr-2001 12:06) has a mistake, at the second arc. Replace them with the following listing.

if ($filled) {
   triangle($im, $cx, $cy, $cx+$px, $cy+$py, $cx+$x, $cy+$y, $colour);
   triangle($im, $cx, $cy, $cx-$px, $cy-$py, $cx-$x, $cy-$y, $colour);
} else {
   imageline($im, $cx+$px, $cy+$py, $cx+$x, $cy+$y, $colour);
   imageline($im, $cx-$px, $cy-$py, $cx-$x, $cy-$y, $colour);
}


hans at lintoo dot dk
18-Jul-2004 04:19

When doing a pie chart... you really should not use imagearc, use imagefilledarc instead... it is much much easier...(and I guess every hosting company should support it by now)

3D Piechart:
Se my modified code at: http://dk.php.net/manual/en/function.imagefilledarc.php

For a quick sample see the online demo at:
http://webstatistik.lintoo.dk/


ruturaj_v at yahoo dot com
17-May-2004 03:32

this is another piechart eg. very simple ...

<?php
global $deg;

function
get_polar($xrel, $yrel, $ang, $radius) {
  
$i = $ang;
  
$ang = ($ang * pi())/ 180;
  
  
$ix = abs($radius*cos($ang));
  
$iy = abs($radius*sin($ang));
  
   if (
$i>=0 && $i<=90) {
      
$ix = $xrel + $ix;
      
$iy = $yrel - $iy;
   }
   if (
$i>90 && $i<=180) {
      
$ix = $xrel - $ix;
      
$iy = $yrel - $iy;
   }
   if (
$i>180 && $i<=270) {
      
$ix = $xrel - $ix;
      
$iy = $yrel + $iy;
   }
   if (
$i>270 && $i<=360) {
      
$ix = $xrel + $ix;
      
$iy = $yrel + $iy;
   }

  
$ix = floor($ix);
  
$iy = floor($iy);
  
//echo ($ix . " $iy<br>");
  
$returnvals = array (
                      
'x1' => $xrel,
                      
'y1' => $yrel,
                      
'x2' => $ix,
                      
'y2' => $iy
                      
);
   return
$returnvals;
}

function
get_degtotal($degindex)
{
   global
$deg;
   if (
$degindex == 0 ) {
       return ( 
$deg[$degindex] );
   }
   else {       
       return (
$deg[$degindex] + get_degtotal($degindex-1) );
   }   
}

$im  = imagecreate (400, 400);
$w  = imagecolorallocate ($im, 255, 255, 255);
$black  = imagecolorallocate ($im, 0, 0, 0);
$red = imagecolorallocate ($im, 255, 0, 0);
$green = imagecolorallocate ($im, 0, 180, 0);

$randcolor[0] = imagecolorallocate($im, 243, 54, 163);
$randcolor[1] = imagecolorallocate($im, 179, 51, 247);
$randcolor[2] = imagecolorallocate($im, 103, 48, 250);
$randcolor[3] = imagecolorallocate($im, 53, 145, 244);
$randcolor[4] = imagecolorallocate($im, 54, 243, 243);
$randcolor[5] = imagecolorallocate($im, 107, 245, 180);
$randcolor[6] = imagecolorallocate($im, 203, 242, 111);
$randcolor[7] = imagecolorallocate($im, 248, 201, 105);

$data[0] = 30;
$data[1] = 20;
$data[2] = 15;
$data[3] = 10;
$data[4] = 8;
$data[5] = 7;
$data[6] = 5;
$data[7] = 5;

$datasum = array_sum($data);

$deg[0] = number_format((30 / $datasum * 360), 2, ".", "");
$deg[1] = number_format((20 / $datasum * 360), 2, ".", "");
$deg[2] = number_format((15 / $datasum * 360), 2, ".", "");
$deg[3] = number_format((10 / $datasum * 360), 2, ".", "");
$deg[4] = number_format((8 / $datasum * 360), 2, ".", "");
$deg[5] = number_format((7 / $datasum * 360), 2, ".", "");
$deg[6] = number_format((5 / $datasum * 360), 2, ".", "");
$deg[7] = number_format((5 / $datasum * 360), 2, ".", "");
echo (
'<pre>');

//print_r($deg);

$datadeg = array();
$datapol = array();
$degbetween = array();
$databetweenpol = array();

for (
$i=0; $i < count($deg) ; $i++) {
  
$datadeg[$i] = get_degtotal($i);
  
$datapol[$i] = get_polar(200, 200, $datadeg[$i], 100);
}

for (
$i=0; $i < count($datadeg) ; $i++) {
  
/*this is a trick where you take 2deg angle before
   and get the smaller radius so that you can have a pt to
   `imagefill` the chartboundary
   */
  
$degbetween[$i] = ($datadeg[$i]-2);
  
$databetweenpol[$i] = get_polar(200, 200, $degbetween[$i], 50);
}

print_r($datadeg);
print_r($degbetween);
print_r($databetweenpol);
//exit;

for ($i=0; $i<count($deg); $i++) {
  
imageline ($im, 200, 200, $datapol[$i]['x2'], $datapol[$i]['y2'], $black);
}
imagearc($im, 200, 200, 200, 200, 0, 360, $black);

for (
$i=0; $i<count($deg); $i++) {
  
imagefill ($im, $databetweenpol[$i]['x2'], $databetweenpol[$i]['y2'], $randcolor[$i]);

}

//header ("Content-type: image/png");
imagepng($im, 'piechart.png');
?>
<img src='piechart.png'>


jerryscript at aol dot com
26-Dec-2003 11:05

[note-Apache/1.3.29 (Win32) PHP/4.3.4]

The imagearc (and imageellipse) functions do not accept line thicknesses when drawn from 0 to 360 degrees.

Drawing from 0 to 359 and again from 359 to 360 does create an ellipse with the current line thickness.

Jerry


eamon at hostelworld dot com
17-Dec-2003 04:24

Right...
possibly the easiest way of drawing a filled circle:
Loop through the imagearc function incrementing the diameter by one pixel:
<?
 
// --- code fragment --- //

for($i=1; $i<$Diameter; $i++){
 
imagearc($Image, $CenterX, $CenterY, $i, $i, $Start, $End, $Color);
}

// --------------------- //

?>

This works great for circles with diameters up to about 60 or 70 pixels wide. After that, you start to get pixle gaps.


logang at deltatee dot com
05-Aug-2003 05:19

Heres a function to make a curve between two points... This will be a downward curve but it wouldn't be hard to make a similar function to make an upward curve. The first point has to be to the left of the second point ($x1 < $x2), and height is actually backwards. The larger height is the less of a crest the curve has. I imagine with a few modifications this functions could make upward curves as well.

function ImageCurveDown ($image, $x1, $y1, $x2, $y2, $height, $color) {
   $presicion = 1;

   for ($left = ($x1-$x2); $left < 0; $left++){
       if ($y1 < $y2) {
           $cy = $y2 + $height;
           $cx = $x1 - $left;
       } else {
           $cy = $y1 + $height;
           $cx = $x2 + $left;
       }
       $nx1 = abs($x1 - $cx);
       $ny1 = abs($y1 - $cy);
       $nx2 = abs($x2 - $cx);
       $ny2 = abs($y2 - $cy);

       if ($y1 < $y2) {
           if ($nx2 == 0 || $ny1 == 0) continue;
           $angle1 = atan($height/$nx2);
           $A1 = $nx2/cos ($angle1);
           $B1 = $ny2/sin ($angle1);
           $angle2 = pi()/2 +atan($left/$ny1);
           $A2 = $nx1/cos ($angle2);
           $B2 = $ny1/sin ($angle2);
       } else {
           if ($ny2 == 0 || $nx1 == 0) continue;
           $angle1 = atan($ny2/$nx2);
           $A1 = abs($nx2/cos ($angle1));
           $B1 = abs($ny2/sin ($angle1));
           $angle2 = atan($height/$nx1);
           $A2 = abs ($nx1/cos ($angle2));
           $B2 = abs($ny1/sin ($angle2));
       }

       if (abs($A1 - $A2) < $presicion && abs ($B1 - $B2) < $presicion) {
           ImageArc($image, $cx, $cy, $A1*2, $B1*2, 180+rad2deg($angle2), 360-rad2deg($angle1), $color);
       }
   }
}


23-Jan-2003 05:55

Please note that in order to draw a complete circle or ellipse (without using the imageellipse) you mustn't use 0

 

 
  © 1996-2012 & Reporter.plmiejscao serwisieabonamentwarunki korzystaniaRSSkontakt