imageellipse

(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)

imageellipse β€” РисуСт эллипс

ОписаниС

function imageellipse(
Β Β Β Β GdImage $image,
Β Β Β Β int $center_x,
Β Β Β Β int $center_y,
Β Β Β Β int $width,
Β Β Β Β int $height,
Β Β Β Β int $color
): true

Ѐункция рисуСт эллипс с Ρ†Π΅Π½Ρ‚Ρ€ΠΎΠΌ Π² Π·Π°Π΄Π°Π½Π½Ρ‹Ρ… ΠΊΠΎΠΎΡ€Π΄ΠΈΠ½Π°Ρ‚Π°Ρ….

Бписок ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ΠΎΠ²

image
ΠžΠ±ΡŠΠ΅ΠΊΡ‚ GdImage, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ Π²Π΅Ρ€Π½ΡƒΠ»Π° функция imagecreatetruecolor() ΠΈΠ»ΠΈ другая функция Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΠΈ ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠΉ.
center_x

ΠšΠΎΠΎΡ€Π΄ΠΈΠ½Π°Ρ‚Π° Ρ†Π΅Π½Ρ‚Ρ€Π° ΠΏΠΎ оси x.

center_y

ΠšΠΎΠΎΡ€Π΄ΠΈΠ½Π°Ρ‚Π° Ρ†Π΅Π½Ρ‚Ρ€Π° ΠΏΠΎ оси y.

width

Π¨ΠΈΡ€ΠΈΠ½Π° эллипса.

height

Высота эллипса.

color

Π¦Π²Π΅Ρ‚ эллипса. Π˜Π΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ Ρ†Π²Π΅Ρ‚Π°, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ Π΄ΠΎΠ±Π°Π²ΠΈΠ»Π° Π² ΠΏΠ°Π»ΠΈΡ‚Ρ€Ρƒ изобраТСния функция imagecolorallocate().

Π’ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅ΠΌΡ‹Π΅ значСния

Ѐункция Π²ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅Ρ‚ логичСскоС Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ true.

Бписок измСнСний

ВСрсия ОписаниС
8.0.0 ΠŸΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ image Ρ‚Π΅ΠΏΠ΅Ρ€ΡŒ ΠΏΡ€ΠΈΠ½ΠΈΠΌΠ°Π΅Ρ‚ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚ GdImage; Ρ€Π°Π½ΡŒΡˆΠ΅ ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ ΠΏΡ€ΠΈΠ½ΠΈΠΌΠ°Π» ΠΊΠΎΡ€Ρ€Π΅ΠΊΡ‚Π½Ρ‹ΠΉ gd-рСсурс (resource).

ΠŸΡ€ΠΈΠΌΠ΅Ρ€Ρ‹

ΠŸΡ€ΠΈΠΌΠ΅Ρ€ #1 ΠŸΡ€ΠΈΠΌΠ΅Ρ€ рисования эллипса Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠ΅ΠΉ imageellipse()

<?php

// Π‘ΠΎΠ·Π΄Π°Ρ‘ΠΌ пустоС ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅
$image = imagecreatetruecolor(400, 300);

// ΠžΠΏΡ€Π΅Π΄Π΅Π»ΡΠ΅ΠΌ Ρ†Π²Π΅Ρ‚ Ρ„ΠΎΠ½Π°
$bg = imagecolorallocate($image, 0, 0, 0);

// Π—Π°ΠΊΡ€Π°ΡˆΠΈΠ²Π°Π΅ΠΌ Ρ„ΠΎΠ½ Ρ†Π²Π΅Ρ‚ΠΎΠΌ
imagefill($image, 0, 0, $bg);

// УстанавливаСм Ρ†Π²Π΅Ρ‚ эллипса
$col_ellipse = imagecolorallocate($image, 255, 255, 255);

// РисуСм эллипс
imageellipse($image, 200, 150, 300, 200, $col_ellipse);

// УстанавливаСм Π·Π°Π³ΠΎΠ»ΠΎΠ²ΠΎΠΊ с MIME-Ρ‚ΠΈΠΏΠΎΠΌ изобраТСния ΠΈ Π²Ρ‹Π²ΠΎΠ΄ΠΈΠΌ Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚
header("Content-type: image/png");
imagepng($image);

Π’Ρ‹Π²ΠΎΠ΄ ΠΏΡ€ΠΈΠ²Π΅Π΄Ρ‘Π½Π½ΠΎΠ³ΠΎ ΠΏΡ€ΠΈΠΌΠ΅Ρ€Π° Π±ΡƒΠ΄Π΅Ρ‚ ΠΏΠΎΡ…ΠΎΠΆ Π½Π°:

Π’Ρ‹Π²ΠΎΠ΄ ΠΏΡ€ΠΈΠΌΠ΅Ρ€Π°: imageellipse()

ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΡ

Π—Π°ΠΌΠ΅Ρ‡Π°Π½ΠΈΠ΅:

Ѐункция imageellipse() ΠΈΠ³Π½ΠΎΡ€ΠΈΡ€ΡƒΠ΅Ρ‚ установку Ρ‚ΠΎΠ»Ρ‰ΠΈΠ½Ρ‹ Π»ΠΈΠ½ΠΈΠΈ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠ΅ΠΉ imagesetthickness().

Π‘ΠΌΠΎΡ‚Ρ€ΠΈΡ‚Π΅ Ρ‚Π°ΠΊΠΆΠ΅

  • imagefilledellipse() - РисуСт эллипс с Π·Π°Π»ΠΈΠ²ΠΊΠΎΠΉ
  • imagearc() - РисуСт Π΄ΡƒΠ³Ρƒ
οΌ‹Π”ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ

ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΡ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Π΅ΠΉ 3 notes

up
-1
simon_nuttall at hotmail dot com ΒΆ
20 years ago
This is an optimised and bug fixed version of nojer at yahoo dot com's rotatedellipse function. I've changed it so that the arguments are compatible with imageellipse. See notes on imagearc for original version.

<?php

function rotatedellipse($im, $cx, $cy, $width, $height, $rotateangle, $colour, $filled=false) {
  // modified here from nojer's version
  // Rotates from the three o-clock position clockwise with increasing angle.
  // Arguments are compatible with imageellipse.

  $width=$width/2;
  $height=$height/2;

  // This affects how coarse the ellipse is drawn.
  $step=3;

  $cosangle=cos(deg2rad($rotateangle));
  $sinangle=sin(deg2rad($rotateangle));

  // $px and $py are initialised to values corresponding to $angle=0.
  $px=$width * $cosangle;
  $py=$width * $sinangle;
  
  for ($angle=$step; $angle<=(180+$step); $angle+=$step) {
    
    $ox = $width * cos(deg2rad($angle));
    $oy = $height * sin(deg2rad($angle));
    
    $x = ($ox * $cosangle) - ($oy * $sinangle);
    $y = ($ox * $sinangle) + ($oy * $cosangle);
 
    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);
    }
    $px=$x;
    $py=$y;
  }
}

function triangle($im, $x1,$y1, $x2,$y2, $x3,$y3, $colour) {
   $coords = array($x1,$y1, $x2,$y2, $x3,$y3);
   imagefilledpolygon($im, $coords, 3, $colour);
}

?>
up
-1
julian ΒΆ
21 years ago
if you want to display an ellipse in the upper left corner of an image, you can easily calculate the corresponding cx and cy values. this example will draw an ellipse having the same width and height as the image.

<?php

$ellipse_width = 100;
$ellipse_height = 200;

$ellipse_cx = ($ellipse_width / 2);
$ellipse_cy = ($ellipse_height / 2);

$img_x = $ellipse_width;
$img_y = $ellipse_height;

$img = imagecreate($img_x, $img_y);
$bg = imagecolorallocate($img, 255,255,255);

$ellipse_color = imagecolorallocate($img, 0, 0, 0);

imageellipse($img, $ellipse_cx, $ellipse_cy, $ellipse_width, $ellipse_height, $ellipse_color);

header("Content-type: image/png");
imagepng($img);
imagedestroy($img);

?>
up
-2
agentyoungsoo at hanmail dot net ΒΆ
23 years ago
When you wana use "ImageEllipse" function 
in under GD 2.0.2 version, you can use "ImageArc" like bellow

----------------------------------------------------
$file_name = "test.png";

$screen_x = 300;
$screen_y = 200;

$x1 = $screen_x / 2;
$y1 = $screen_y / 2;

$radius = 30;

$image = ImageCreate($screen_x, $screen_y);
$black = ImageColorAllocate($image, 0,0,0);

ImageArc($image, $x1, $y1, $radius , $radius , 0, 360, $black);

ImagePng($image, $file_name); 
ImageDestroy($image); 
----------------------------------------------------