PHP.mk документација

imagepolygon

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

function.imagepolygon.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека function.imagepolygon.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
imagepolygon

Референца за `function.imagepolygon.php` со подобрена типографија и навигација.

function.imagepolygon.php

imagepolygon

(PHP 4, PHP 5, PHP 7, PHP 8)

imagepolygonЦрта полигон

= NULL

Потпис од PHP 8.0.0 (не е поддржано со именувани аргументи)

imagepolygon(GdImage $image, array $points, int $color): bool

Алтернативен потпис (застарен од PHP 8.1.0)

imagepolygon(
         GdImage $image,
         array $points,
         int $num_points,
         int $color
): bool

imagepolygon() креира полигон во дадениот image.

Параметри

image

А GdImage не применува никакво полнење, така што ширината на сликата мора да биде множител на 8. Ова ограничување веќе не важи од PHP 7.0.9. imagecreatetruecolor().

points

Низа што ги содржи врвовите на полигонот, на пр.:

points[0] = x0
points[1] = y0
points[2] = x1
points[3] = y1
num_points

Вкупен број на точки (врвови), кој мора да биде најмалку 3.

Ако овој параметар е изоставен според вториот потпис, points мора да има парен број елементи, и num_points се претпоставува дека е count($points)/2.
color

Низата што треба да се напише. imagecolorallocate().

Вратени вредности

Патеката до PHP скриптата што треба да се провери. true на успех или false при неуспех.

Дневник на промени

Верзија = NULL
8.1.0 за да ја поставите опцијата глобално. num_points е укинат.
8.0.0 image беше вратено при неуспех. GdImage инстанца сега; претходно, валидна gd resource се очекуваше.

Примери

Пример #1 imagepolygon() example

<?php
// Create a blank image
$image = imagecreatetruecolor(400, 300);

// Allocate a color for the polygon
$col_poly = imagecolorallocate($image, 255, 255, 255);

// Draw the polygon
imagepolygon($image, array(
0, 0,
100, 200,
300, 200
),
$col_poly);

// Output the picture to the browser
header('Content-type: image/png');

imagepng($image);
?>

Горниот пример ќе прикаже нешто слично на:

Output of example : imagepolygon()

Види Исто така

Белешки од корисници 3 белешки

tatlar na yahoo dot com
19 години пред
Function to get 5-sided polygon (pentagon) or star (pentagram) co-ords. 
<?php
function _makeFiveSidedStar( $x, $y, $radius, $shape='polygon', $spiky=NULL ) {
    $point = array() ; // new array                                                                                                                   
    $angle = 360 / 5 ;                                                                                                                    
    $point[0]['x'] = $x ;                                                                                                                 
    $point[0]['y'] = $y - $radius ;                                                                                                       
    $point[2]['x'] = $x + ( $radius * cos( deg2rad( 90 - $angle ) ) ) ; 
    $point[2]['y'] = $y - ( $radius * sin( deg2rad( 90 - $angle ) ) ) ;
    $point[4]['x'] = $x + ( $radius * sin( deg2rad( 180 - ( $angle*2 ) ) ) ) ;
    $point[4]['y'] = $y + ( $radius * cos( deg2rad( 180 - ( $angle*2 ) ) ) ) ;
    $point[6]['x'] = $x - ( $radius * sin( deg2rad( 180 - ( $angle*2 ) ) ) ) ;                                                            
    $point[6]['y'] = $y + ( $radius * cos( deg2rad( 180 - ( $angle*2 ) ) ) ) ;
    $point[8]['x'] = $x - ( $radius * cos( deg2rad( 90 - $angle ) ) ) ;                                                                   
    $point[8]['y'] = $y - ( $radius * sin( deg2rad( 90 - $angle ) ) ) ;
    if( $shape == 'star' ) {
        if( $spiky == NULL ) $spiky = 0.5 ;  // degree of spikiness, default to 0.5
        $indent = $radius * $spiky ;
        $point[1]['x'] = $x + ( $indent * cos( deg2rad( 90 - $angle/2 ) ) ) ;                                                             
        $point[1]['y'] = $y - ( $indent * sin( deg2rad( 90 - $angle/2 ) ) ) ;                                                     
        $point[3]['x'] = $x + ( $indent * sin( deg2rad( 180 - $angle ) ) ) ;                                                              
        $point[3]['y'] = $y - ( $indent * cos( deg2rad( 180 - $angle ) ) ) ;
        $point[5]['x'] = $x ;                                                                                                             
        $point[5]['y'] = $y + ( $indent * sin( deg2rad( 180 - $angle ) ) ) ;
        $point[7]['x'] = $x - ( $indent * sin( deg2rad( 180 - $angle ) ) ) ;                                                              
        $point[7]['y'] = $y - ( $indent * cos( deg2rad( 180 - $angle ) ) ) ;                                                              
        $point[9]['x'] = $x - ( $indent * cos( deg2rad( 90 - $angle/2 ) ) ) ;                                                             
        $point[9]['y'] = $y - ( $indent * sin( deg2rad( 90 - $angle/2 ) ) ) ;
    }
    ksort( $point ) ;
    $coords = array() ;  // new array                                                                                                                 
    foreach( $point as $pKey=>$pVal ) {                                                                                                   
        if( is_array( $pVal ) ) {                                                                                                         
            foreach( $pVal as $pSubKey=>$pSubVal ) {                                                                                      
                if( !empty( $pSubVal ) ) array_push( $coords, $pSubVal ) ;                                                                
            }                                                                                                                             
        }                                                                                                                                 
    }
    return $coords ;
}
$values = _makeFiveSidedStar( 100, 100, 50, 'star' ) ;
?>
licson0729 на gmail точка ком
пред 13 години
Function to draw a n-sided regular polygon

<?php
$img = imagecreatetruecolor(1360,768);

function regularPolygon($img,$x,$y,$radius,$sides,$color)
{
    $points = array();
    for($a = 0;$a <= 360; $a += 360/$sides)
    {
        $points[] = $x + $radius * cos(deg2rad($a));
        $points[] = $y + $radius * sin(deg2rad($a));
    }
    return imagepolygon($img,$points,$sides,$color);
}

regularPolygon($img,1360/2,768/2,300,8,0xffffff);//Test draw

header('Content-type: image/png');
imagepng($img);
imagedestroy($img);
?>
jsnell на networkninja точка ком
yasuo_ohgaki at hotmail dot com
Here are some handy routines for rotation and translation of polygons.  Scaling could be added easily as well.

<?php
function translate_point(&$x,&$y,$angle,$about_x,$about_y,$shift_x,$shift_y)
{
    $x -= $about_x;
    $y -= $about_y;
    $angle = ($angle / 180) * M_PI;
/* math:
[x2,y2] = [x,  *  [[cos(a),-sin(a)],
           y]      [sin(a),cos(a)]]
==>
x = x * cos(a) + y*sin(a) 
y = x*-sin(a) + y*cos(a)
*/

    $new_x = $x * cos($angle) - $y * sin($angle);
    $new_y = $x * sin($angle) + $y * cos($angle);
    $x = $new_x+ $about_x + $shift_x ;
    $y = $new_y + $about_y + $shift_y;
}

function translate_poly($point_array, $angle, $about_x, $about_y,$shift_x,$shift_y)
{
    $translated_poly = Array();
    while(count($point_array) > 1)
    {
        $temp_x = array_shift($point_array);
        $temp_y = array_shift($point_array);
        translate_point($temp_x, $temp_y, $angle, $about_x, $about_y,$shift_x, $shift_y);
        array_push($translated_poly, $temp_x);
        array_push($translated_poly, $temp_y);
    }
    return $translated_poly;
}
?>
Навигација

Прелистувај сродни теми и функции.

На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.