PHP Conference Japan 2024

imageline

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

imageline繪製直線

描述

imageline(
    GdImage $image,
    int $x1,
    int $y1,
    int $x2,
    int $y2,
    int $color
): bool

在兩個給定的點之間繪製一條線。

參數

image

一個 GdImage 物件,由影像建立函式之一傳回,例如 imagecreatetruecolor()

x1

第一個點的 x 座標。

y1

第一個點的 y 座標。

x2

第二個點的 x 座標。

y2

第二個點的 y 座標。

color

線條顏色。使用 imagecolorallocate() 建立的顏色識別碼。

傳回值

成功時傳回 true,失敗時傳回 false

變更記錄

版本 描述
8.0.0 image 現在預期是 GdImage 的實例;先前,預期是有效的 gd 資源

範例

範例 #1 繪製粗線

<?php

function imagelinethick($image, $x1, $y1, $x2, $y2, $color, $thick = 1)
{
/* 這種方式只適用於正交線
imagesetthickness($image, $thick);
return imageline($image, $x1, $y1, $x2, $y2, $color);
*/
if ($thick == 1) {
return
imageline($image, $x1, $y1, $x2, $y2, $color);
}
$t = $thick / 2 - 0.5;
if (
$x1 == $x2 || $y1 == $y2) {
return
imagefilledrectangle($image, round(min($x1, $x2) - $t), round(min($y1, $y2) - $t), round(max($x1, $x2) + $t), round(max($y1, $y2) + $t), $color);
}
$k = ($y2 - $y1) / ($x2 - $x1); //y = kx + q
$a = $t / sqrt(1 + pow($k, 2));
$points = array(
round($x1 - (1+$k)*$a), round($y1 + (1-$k)*$a),
round($x1 - (1-$k)*$a), round($y1 - (1+$k)*$a),
round($x2 + (1+$k)*$a), round($y2 - (1-$k)*$a),
round($x2 + (1-$k)*$a), round($y2 + (1+$k)*$a),
);
imagefilledpolygon($image, $points, 4, $color);
return
imagepolygon($image, $points, 4, $color);
}

?>

參見

新增註解

使用者貢獻的註解 28 則註解

4
Jonathan W.
17 年前
我修改了先前在極座標系統上繪圖的條目,以便根據 360º 整圓方位更好地表示角度。

<?php

function imagepolarline($image,$x1,$y1,$length,$angle,$color)
{
$x2 = $x1 + sin( deg2rad($angle) ) * $length;
$y2 = $y1 + cos( deg2rad($angle+180) ) * $length;

imageline($image,$x1,$y1,$x2,$y2,$color);
}

?>
4
pb_2001 at haefft dot de
18 年前
這是一個繪製虛線的函式。它接受(實際上是需要)7 個參數,如果一切順利則返回 1,如果出現問題則返回 0。

int imagelinedotted ( resource im, int x1, int y1, int x2, int y2, int dist, int col )

imagelinedotted() 在圖像 im 中從 x1, y1 到 x2, y2(左上角為 0, 0)繪製顏色為 col 的線,其中 dist 定義一個點和另一個點之間的距離(以像素為單位測量)。

<?php
function imagelinedotted ($im, $x1, $y1, $x2, $y2, $dist, $col) {
$transp = imagecolortransparent ($im);

$style = array ($col);

for (
$i=0; $i<$dist; $i++) {
array_push($style, $transp); // 生成樣式陣列 - 迴圈用於自訂點之間的距離
}

imagesetstyle ($im, $style);
return (integer)
imageline ($im, $x1, $y1, $x2, $y2, IMG_COLOR_STYLED);
imagesetstyle ($im, array($col)); // 重置樣式 - 以防萬一...
}
?>
5
sbm007 at gmail dot com
15 年前
這是一個系統時間的類比時鐘表示,以及小時的數字和分鐘/秒的小點。

<?php
$img
= imagecreatetruecolor(450, 450);

$white = imagecolorallocate($img, 255, 255, 255);
$red = imagecolorallocate($img, 255, 0, 0);
$black = imagecolorallocate($img, 0, 0, 0);
$grey = imagecolorallocate($img, 211, 211, 211);

imagefill($img, 0, 0, $white);
imagearc($img, 224, 224, 400, 400, 0, 0, $black);
imagefilledarc($img, 224, 224, 15, 15, 0, 0, $black, IMG_ARC_PIE);

for (
$zz = 0; $zz < 60; $zz++) {
$digitCoords['x'][] = 175 * cos(deg2rad(($zz-10) * (360/60))) + 224;
$digitCoords['y'][] = 175 * sin(deg2rad(($zz-10) * (360/60))) + 224;
}

for (
$zz = 0; $zz < 60; $zz++) {
if (
$zz % 5 == 0)
imagestring($img, 5, $digitCoords['x'][$zz] - 4, $digitCoords['y'][$zz] - 6, ($zz/5) + 1, $black);
else
imagefilledarc($img, $digitCoords['x'][$zz], $digitCoords['y'][$zz], 3, 3, 0, 0, $grey, IMG_ARC_PIE);
}

$seconds = date('s');
$minutes = date('i') + ($seconds/60);
$hours = date('h') + ($minutes/60);

$r_sec = 175;
$r_min = 175;
$r_hr = 125;

$x_sec = $r_sec * cos(deg2rad(($seconds-15) * (360/60))) + 224;
$y_sec = $r_sec * sin(deg2rad(($seconds-15) * (360/60))) + 224;

$x_min = $r_min * cos(deg2rad(($minutes-15) * (360/60))) + 224;
$y_min = $r_min * sin(deg2rad(($minutes-15) * (360/60))) + 224;

$x_hr = $r_hr * cos(deg2rad(($hours-3) * (360/12))) + 224;
$y_hr = $r_hr * sin(deg2rad(($hours-3) * (360/12))) + 224;

imageline($img, 224, 224, $x_sec, $y_sec, $red);
imagesetthickness($img, 3);
imageline($img, 224, 224, $x_min, $y_min, $black);
imagesetthickness($img, 5);
imageline($img, 224, 224, $x_hr, $y_hr, $black);

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

imagedestroy($img);
?>
3
d [AT] sprid [DOT] de
19 年前
這是我的函式,可以解決所有問題。有了這個,你可以先畫出平滑的線條(基本程式碼改編自 code_couturier 在 graffiti dot net 的程式碼,並做了一些效能上的改進)。特別的是,你可以定義線條的 alpha 值(0 = 一般平滑線條,127 = 完全透明)。你可以隨意修改讓它更好,但請貼出你的結果 ;)

<?php
/**
* function imageSmoothAlphaLine() - version 1.0
* Draws a smooth line with alpha-functionality
*
* @param ident the image to draw on
* @param integer x1
* @param integer y1
* @param integer x2
* @param integer y2
* @param integer red (0 to 255)
* @param integer green (0 to 255)
* @param integer blue (0 to 255)
* @param integer alpha (0 to 127)
*
* @access public
*
* @author DASPRiD <d@sprid.de>
*/
function imageSmoothAlphaLine ($image, $x1, $y1, $x2, $y2, $r, $g, $b, $alpha=0) {
$icr = $r;
$icg = $g;
$icb = $b;
$dcol = imagecolorallocatealpha($image, $icr, $icg, $icb, $alpha);

if (
$y1 == $y2 || $x1 == $x2)
imageline($image, $x1, $y2, $x1, $y2, $dcol);
else {
$m = ($y2 - $y1) / ($x2 - $x1);
$b = $y1 - $m * $x1;

if (
abs ($m) <2) {
$x = min($x1, $x2);
$endx = max($x1, $x2) + 1;

while (
$x < $endx) {
$y = $m * $x + $b;
$ya = ($y == floor($y) ? 1: $y - floor($y));
$yb = ceil($y) - $y;

$trgb = ImageColorAt($image, $x, floor($y));
$tcr = ($trgb >> 16) & 0xFF;
$tcg = ($trgb >> 8) & 0xFF;
$tcb = $trgb & 0xFF;
imagesetpixel($image, $x, floor($y), imagecolorallocatealpha($image, ($tcr * $ya + $icr * $yb), ($tcg * $ya + $icg * $yb), ($tcb * $ya + $icb * $yb), $alpha));

$trgb = ImageColorAt($image, $x, ceil($y));
$tcr = ($trgb >> 16) & 0xFF;
$tcg = ($trgb >> 8) & 0xFF;
$tcb = $trgb & 0xFF;
imagesetpixel($image, $x, ceil($y), imagecolorallocatealpha($image, ($tcr * $yb + $icr * $ya), ($tcg * $yb + $icg * $ya), ($tcb * $yb + $icb * $ya), $alpha));

$x++;
}
} else {
$y = min($y1, $y2);
$endy = max($y1, $y2) + 1;

while (
$y < $endy) {
$x = ($y - $b) / $m;
$xa = ($x == floor($x) ? 1: $x - floor($x));
$xb = ceil($x) - $x;

$trgb = ImageColorAt($image, floor($x), $y);
$tcr = ($trgb >> 16) & 0xFF;
$tcg = ($trgb >> 8) & 0xFF;
$tcb = $trgb & 0xFF;
imagesetpixel($image, floor($x), $y, imagecolorallocatealpha($image, ($tcr * $xa + $icr * $xb), ($tcg * $xa + $icg * $xb), ($tcb * $xa + $icb * $xb), $alpha));

$trgb = ImageColorAt($image, ceil($x), $y);
$tcr = ($trgb >> 16) & 0xFF;
$tcg = ($trgb >> 8) & 0xFF;
$tcb = $trgb & 0xFF;
imagesetpixel ($image, ceil($x), $y, imagecolorallocatealpha($image, ($tcr * $xb + $icr * $xa), ($tcg * $xb + $icg * $xa), ($tcb * $xb + $icb * $xa), $alpha));

$y ++;
}
}
}
}
// end of 'imageSmoothAlphaLine()' function
?>
3
kramesch_NOSPAM_ at _nospam_idsolutions dot at
22 年前
這是一個簡單的程式碼,可以用任意的筆觸繪製線條。參數 aStroke 會被當作一個循環的布林陣列,其中 true 等於「設定一個點」。
例如:$aDotStroke = array(true,false);

function ImageStrokeLine($im,$x1,$y1,$x2,$y2,$farbe, $aStroke)
{
$deltax = abs($x2 - $x1);
$deltay = abs($y2 - $y1);
$x = $x1;
$y = $y1;

if ($x2 >= $x1)
{
$xinc1 = 1;
$xinc2 = 1;
}
else
{
$xinc1 = -1;
$xinc2 = -1;
}

if ($y2 >= $y1)
{
$yinc1 = 1;
$yinc2 = 1;
}
else
{
$yinc1 = -1;
$yinc2 = -1;
}

if ($deltax >= $deltay)
{
$xinc1 = 0;
$yinc2 = 0;
$den = $deltax;
$num = $deltax / 2;
$numadd = $deltay;
$numpixels = $deltax;
}
else
{
$xinc2 = 0;
$yinc1 = 0;
$den = $deltay;
$num = $deltay / 2;
$numadd = $deltax;
$numpixels = $deltay;
}

for ($curpixel = 0; $curpixel <= $numpixels; $curpixel++)
{
if ($iStrokeCount >= count($aStroke))
{
$iStrokeCount = 0;
}

if ($aStroke[$iStrokeCount++])
{
ImageSetPixel($im,$x, $y,$farbe);
}
$num += $numadd;
if ($num >= $den)
{
$num -= $den;
$x += $xinc1;
$y += $yinc1;
}
$x += $xinc2;
$y += $yinc2;
}
}
2
Nils
12 年前
這是一個我寫的快速函式,使用 imageline,讓我能夠指定起點、角度和向量長度。

覺得其他人可能會覺得這很有用。

<?php
$size
= 600;
$img = imagecreatetruecolor($size, $size);

$white = imagecolorallocate($img, 255, 255, 255);
$black = imagecolorallocate($img, 0, 0, 0);

imagefilledrectangle($img,0,0,$size,$size,$white);

function
Vector($palette,$startx,$starty,$angle,$length,$colour){
$angle = deg2rad($angle);
$endx = $startx+cos($angle)*$length;
$endy = $starty-sin($angle)*$length;
return(
imageline($palette,$startx,$starty,$endx,$endy,$colour));
}

Vector($img,$size/2,$size/2,30,200,$black);

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

?>

這個腳本中的角度是以逆時針方向運作(修改函式中的 + 和 - 可以改變 0 度的起始位置以及計算角度的方向)
1
nanobot at chipx86 dot com
21 年前
這裡有一個函式可以製作反鋸齒線條

function imagesmoothline ( $image , $x1 , $y1 , $x2 , $y2 , $color )
{
$colors = imagecolorsforindex ( $image , $color );
if ( $x1 == $x2 )
{
imageline ( $image , $x1 , $y1 , $x2 , $y2 , $color ); // 垂直線
}
else
{
$m = ( $y2 - $y1 ) / ( $x2 - $x1 );
$b = $y1 - $m * $x1;
if ( abs ( $m ) <= 1 )
{
$x = min ( $x1 , $x2 );
$endx = max ( $x1 , $x2 );
while ( $x <= $endx )
{
$y = $m * $x + $b;
$y == floor ( $y ) ? $ya = 1 : $ya = $y - floor ( $y );
$yb = ceil ( $y ) - $y;
$tempcolors = imagecolorsforindex ( $image , imagecolorat ( $image , $x , floor ( $y ) ) );
$tempcolors['red'] = $tempcolors['red'] * $ya + $colors['red'] * $yb;
$tempcolors['green'] = $tempcolors['green'] * $ya + $colors['green'] * $yb;
$tempcolors['blue'] = $tempcolors['blue'] * $ya + $colors['blue'] * $yb;
if ( imagecolorexact ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] ) == -1 ) imagecolorallocate ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] );
imagesetpixel ( $image , $x , floor ( $y ) , imagecolorexact ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] ) );
$tempcolors = imagecolorsforindex ( $image , imagecolorat ( $image , $x , ceil ( $y ) ) );
$tempcolors['red'] = $tempcolors['red'] * $yb + $colors['red'] * $ya;
$tempcolors['green'] = $tempcolors['green'] * $yb + $colors['green'] * $ya;
$tempcolors['blue'] = $tempcolors['blue'] * $yb + $colors['blue'] * $ya;
if ( imagecolorexact ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] ) == -1 ) imagecolorallocate ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] );
imagesetpixel ( $image , $x , ceil ( $y ) , imagecolorexact ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] ) );
$x ++;
}
}
else
{
$y = min ( $y1 , $y2 );
$endy = max ( $y1 , $y2 );
while ( $y <= $endy )
{
$x = ( $y - $b ) / $m;
$x == floor ( $x ) ? $xa = 1 : $xa = $x - floor ( $x );
$xb = ceil ( $x ) - $x;
$tempcolors = imagecolorsforindex ( $image , imagecolorat ( $image , floor ( $x ) , $y ) );
$tempcolors['red'] = $tempcolors['red'] * $xa + $colors['red'] * $xb;
$tempcolors['green'] = $tempcolors['green'] * $xa + $colors['green'] * $xb;
$tempcolors['blue'] = $tempcolors['blue'] * $xa + $colors['blue'] * $xb;
if ( imagecolorexact ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] ) == -1 ) imagecolorallocate ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] );
imagesetpixel ( $image , floor ( $x ) , $y , imagecolorexact ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] ) );
$tempcolors = imagecolorsforindex ( $image , imagecolorat ( $image , ceil ( $x ) , $y ) );
$tempcolors['red'] = $tempcolors['red'] * $xb + $colors['red'] * $xa;
$tempcolors['green'] = $tempcolors['green'] * $xb + $colors['green'] * $xa;
$tempcolors['blue'] = $tempcolors['blue'] * $xb + $colors['blue'] * $xa;
if ( imagecolorexact ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] ) == -1 ) imagecolorallocate ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] );
imagesetpixel ( $image , ceil ( $x ) , $y , imagecolorexact ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] ) );
$y ++;
}
}
}
}

編輯者:我之前的程式碼有錯誤。請改用這個。
1
ruturaj_v at yahoo dot com
20 年前
這裡有一個函式可以幫助您建立箭頭...

<?php
function get_arrowheads ($x1, $y1, $x2, $y2, $arrhead, $arrang) {
$debug = false;

define("INFINITE", 'INFINITE');
if ((
$x2-$x1)==0) {
if (
$y1 == 0) {
$slope = 0;
} else {
$slope = INFINITE;
}
} else {
$slope = -($y2-$y1)/($x2-$x1);
}

//$slope = number_format($slope, 2, '.','');
if ($slope == 'INFINITE') {
$ang = 90;
} else {
$ang = atan ($slope);
$ang = ($ang * 180)/pi();
}
//$ang = number_format($ang, 2, '.', '');
//echo ($ang);
//exit;

//convert the angle
$arrang1 = ($ang - $arrang);
$arrangdeg1 = ($ang - $arrang);
//echo ($arrang1);exit;
$arrang1 = ($arrang1*pi())/180;

$arrang2 = ($ang + $arrang);
$arrangdeg2 = ($ang + $arrang);
$arrang2 = ($arrang2*pi())/180;
//echo ($arrang1);

$arx1 = (floor(cos($arrang1)*$arrhead));
$ary1 = (floor(sin($arrang1)*$arrhead));
$arx2 = (floor(cos($arrang2)*$arrhead));
$ary2 = (floor(sin($arrang2)*$arrhead));
if (
$debug) {
echo (
"Values of arx1.. before add/sub</br>");
echo (
"$arx1,$ary1&nbsp;&nbsp;&nbsp;$arx2,$ary2</br>");
}
if (
$ang==0) {
if (
$x2 > $x1) {
$arx1 = $x2 - $arx1; $ary1 = $y2 - $ary1;
$arx2 = $x2 - $arx2; $ary2 = $y2 - $ary2;
} elseif (
$x2 < $x1) {
$arx1 = $x2 + $arx1; $ary1 = $y2 - $ary1;
$arx2 = $x2 + $arx2; $ary2 = $y2 - $ary2;
}
}
if (
$ang > 0 && $ang < 90) {
if ((
$x2 > $x1) && ($y2 < $y1)) {
$arx1 = $x2 - $arx1; $ary1 = $y2 + $ary1;
$arx2 = $x2 - $arx2; $ary2 = $y2 + $ary2;
} elseif ((
$x2 < $x1) && ($y2 > $y1)) {
$arx1 = $x2 + $arx1; $ary1 = $y2 - $ary1;
$arx2 = $x2 + $arx2; $ary2 = $y2 - $ary2;
}
}
if (
$ang==90) {
if ((
$y2 > $y1)) {
$arx1 = $x2 - $arx1; $ary1 = $y2 - $ary1;
$arx2 = $x2 - $arx2; $ary2 = $y2 - $ary2;
} elseif ((
$y2 < $y1)) {
$arx1 = $x2 - $arx1; $ary1 = $y2 + $ary1;
$arx2 = $x2 - $arx2; $ary2 = $y2 + $ary2;
}
}
if (
$ang > -90 && $ang < 0) {
if ((
$x2 > $x1) && ($y2 > $y1)) {
$arx1 = $x2 - $arx1; $ary1 = $y2 + $ary1;
$arx2 = $x2 - $arx2; $ary2 = $y2 + $ary2;
} elseif ((
$x2 < $x1) && ($y2 < $y1)) {
$arx1 = $x2 + $arx1; $ary1 = $y2 - $ary1;
$arx2 = $x2 + $arx2; $ary2 = $y2 - $ary2;
}
}

if (
$debug) {
echo (
"Angle of line is (".$ang*180/pi().")</br>");
echo (
"Angle of line1 is $arrangdeg1</br>");
echo (
"Angle of line2 is $arrangdeg2</br>");
echo (
"$arx1,$ary1&nbsp;&nbsp;&nbsp;$x2,$y2</br>");
echo (
"$arx2,$ary2&nbsp;&nbsp;&nbsp;$x2,$y2");
exit;
}

$array_arrows = array (
'x1' =>$arx1,
'y1' => $ary1,
'x2' => $arx2,
'y2' => $ary2
);
return
$array_arrows;

}

$x1 = 200; $y1 = 200;
$x2 = 400; $y2 = 100;
$arrhead = 15; //10px
$arrang = 10; //10 deg

$ar_arrws = get_arrowheads ($x1, $y1, $x2, $y2, $arrhead, $arrang);

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

//creates the base line
imageline ($im, $x1, $y1, $x2, $y2, $green);
imageline ($im, $x1+1, $x2+1, $y1+1, $y2+1, $red);
imageline ($im, $x2, $y2, $ar_arrws['x1'], $ar_arrws['y1'], $green);
imageline ($im, $x2, $y2, $ar_arrws['x2'], $ar_arrws['y2'], $green);

?>
2
Tyron
19 年前
// 這裡有一個函式可以繪製旋轉的漸層矩形(基於先前的註解)

// 建立一個 255x255 的影像
$img = ImageCreateTrueColor(255, 255);

GradientRect($img,50,50,80,80,30);

ImagePng($img,"test.png");
ImageDestroy($img);
echo "<br><img src=\"test.png\">";

function GradientRect($img, $x1, $y1, $x2, $y2, $wdt) {
$alpha = atan2($y2-$y1,$x2-$x1);
$real_wdt = $wdt*sin($alpha);
$real_hgt = $wdt*cos($alpha);
echo "實際寬度:".$real_wdt;
echo "<br>實際高度:".$real_hgt;
echo "<br>角度: ".($angle*180/pi());
$plotD = 0;
$i=0;

$dy = $real_hgt/$wdt;
$dx = $real_wdt/$wdt;
$drgb= 256/$wdt;
while($i++ < $wdt) {
// 繪製一條線並將其向下移動並使其變淺以獲得漸層效果
ImageLine($img, $x1-$i*$dx, $y1+$i*$dy, $x2-$i*$dx, $y2+$i*$dy, ImageColorAllocate($img, $i*$drgb, 0, 0));
ImageLine($img, $x1-$i*$dx+1, $y1+$i*$dy, $x2-$i*$dx+1, $y2+$i*$dy, ImageColorAllocate($img, $i*$drgb, 0, 0));

}
}
2
yl at sota dot ch
20 年前
用於建立 jpg 影像邊框的簡單函式

function createImageBorder($imgName){

$img = substr($imgName, 0, -4); // 移除副檔名
$ext = ".jpg";
$quality = 95;
$borderColor = 255; // 255 = 白色

/*
a b
+-------------------------+
|
| 影像
|
+-------------------------+
c d
*/

$scr_img = imagecreatefromjpeg($img.$ext);
$width = imagesx($scr_img);
$height = imagesy($scr_img);

// 線條 a - b
$abX = 0;
$abY = 0;
$abX1 = $width;
$abY1 = 0;

// 線條 a - c
$acX = 0;
$acY = 0;
$acX1 = 0;
$acY1 = $height;

// 線條 b - d
$bdX = $width-1;
$bdY = 0;
$bdX1 = $width-1;
$bdY1 = $height;

// 線條 c - d
$cdX = 0;
$cdY = $height-1;
$cdX1 = $width;
$cdY1 = $height-1;

// 繪製線條
imageline($scr_img,$abX,$abY,$abX1,$abY1,$borderColor);
imageline($scr_img,$acX,$acY,$acX1,$acY1,$borderColor);
imageline($scr_img,$bdX,$bdY,$bdX1,$bdY1,$borderColor);
imageline($scr_img,$cdX,$cdY,$cdX1,$cdY1,$borderColor);

// 從影像建立副本
imagejpeg($scr_img, $img."_border.jpg", $quality);
imagedestroy($scr_img);
}

createImageBorder("myfile.jpg");
1
v dot krypton at yandex dot ru
8 年前
這個函式會繪製影像的邊框。
function imageborder($img,$color) {
$width = imagesx($img);
$height = imagesy($img);
ImageLine($img, 0, 0, $width, 0, $color);
ImageLine($img, 0, 0, 0, $height, $color);
ImageLine($img, $width-1, 0, $height-1, $height, $color);
ImageLine($img, 0, $height-1, $width, $height-1, $color);
}
0
teixeira dot cmo at gmail.com
7 年前
如果您在使用 js 的 canvas 上繪圖,使用 ctx.lineJoin = "round";然後嘗試在 GD $img 上執行相同的操作,則結果將會不同。
這裡有一個簡單的程式碼可以繪製類似於使用 lineJoin round 所繪製的線條。

$w=5; //設定您的線條粗細;
imagesetthickness($img, $w);
imageline($img, $x1, $y1, $x2, $y2, $color);
imagesetthickness($img, 1);
imagefilledellipse ( $img , $x2 , $y2 , $w ,$w, $color);
0
Anonymous
13 年前
我找到的大多數粗線函式在某些方向的線條上都有問題(它們會以某些角度繪製較小的線條)。要繪製真正的粗線,只需使用此函式即可

<?php
function imageBoldLine($resource, $x1, $y1, $x2, $y2, $Color, $BoldNess=2, $func='imageLine')
{
$center = round($BoldNess/2);
for(
$i=0;$i<$BoldNess;$i++)
{
$a = $center-$i; if($a<0){$a -= $a;}
for(
$j=0;$j<$BoldNess;$j++)
{
$b = $center-$j; if($b<0){$b -= $b;}
$c = sqrt($a*$a + $b*$b);
if(
$c<=$BoldNess)
{
$func($resource, $x1 +$i, $y1+$j, $x2 +$i, $y2+$j, $Color);
}
}
}
}
?>
0
Anonymous
15 年前
這裡提供另一種修改 likavcan 程式碼以顯示填滿箭頭的方法。這使用了 imagefilledpolygon(...) 而不是遞迴函式呼叫。

<?php
function arrow($im, $x1, $y1, $x2, $y2, $alength, $awidth, $color) {
$distance = sqrt(pow($x1 - $x2, 2) + pow($y1 - $y2, 2));

$dx = $x2 + ($x1 - $x2) * $alength / $distance;
$dy = $y2 + ($y1 - $y2) * $alength / $distance;

$k = $awidth / $alength;

$x2o = $x2 - $dx;
$y2o = $dy - $y2;

$x3 = $y2o * $k + $dx;
$y3 = $x2o * $k + $dy;

$x4 = $dx - $y2o * $k;
$y4 = $dy - $x2o * $k;

imageline($im, $x1, $y1, $dx, $dy, $color);
imagefilledpolygon($im, array($x2, $y2, $x3, $y3, $x4, $y4), 3, $color);
}
?>
0
huirong dot jin at gmail dot com
16 年前
一個繪製振幅調變曲線的範例:y = c * sin (x/a) * sin (x/b)。您可以輕鬆修改程式碼來建立您自己的示波器應用程式!

<?php
header
("Content-type: image/png");
$myImage = @imagecreatetruecolor(640, 480)
or die(
"無法初始化新的 GD 影像串流");
$text_color = imagecolorallocate($myImage, 255, 255, 224);
$poly_color = imagecolorallocate($myImage, 124, 120, 224);

//逐點計算 x 值和 y 值
$points = array();
for (
$i=1; $i<640; $i=$i+1)
{
//定義曲線函式
$x = $i; //定義 x 值,即 $i 本身
$y = 150*sin($x/80)*sin($x/5);//定義 y 值

//附加一個點的 x 值和 y 值
$points[] = $x; //x 值
$points[] = 240-$y; //y 值
}

//計算點數
$totalPoints = count($points)/2;

//繪製標題
$title = "最終圖 ($totalPoints 個點)";
imagestring($myImage, 3, 5, 5, $title, $text_color);

/** 逐點繪製,請注意,如果有 10 個點,我們需要繪製 9 條線:
* 1) 從點 0 到 1;
* 2) 從點 1 到 2;
* ...
* ...
* 9) 從點 8 到 9;
*/
for ($i=0; $i<$totalPoints-1; $i++)
{
imageLine($myImage, $points[2*$i], $points[1+2*$i], $points[2+2*$i], $points[3+2*$i], $poly_color);
}

//最終處理
imagepng($myImage);
imagedestroy($myImage);
?>
0
admin at xpmail dot net
17 年前
簡單格線範例...
bool imagegrid ( resource $image, int $width, int $Height, int $size, mixed $color )

<?php
Header
("Content-type: image/png");
$Width=450;
$Height=450;

$img = ImageCreateTrueColor($Width, $Height);

$bg = imagecolorallocate($img, 255, 255, 255);
imagefill($img, 0, 0, $bg);

$grid = imagecolorallocate($img, 225, 245, 249);

imagesetstyle($img, array($bg, $grid));
imagegrid($img, $Width, $Height, 10, IMG_COLOR_STYLED);
//makegrid($img, $Width, $Height, 10, $grid);

ImagePNG($img);
ImageDestroy($img);

function
imagegrid($image, $w, $h, $s, $color)
{
for(
$iw=1; $iw<$w/$s; $iw++){imageline($image, $iw*$s, 0, $iw*$s, $w, $color);}
for(
$ih=1; $ih<$h/$s; $ih++){imageline($image, 0, $ih*$s, $w, $ih*$s, $color);}
}
?>
0
meid at gmx dot at
19 年前
這是一些簡單的程式碼,使用 "imagefilledpolygon" 來繪製特定粗細的線條。如果您使用的 gdlib 不支援 "imagesetthickness",這會很有用。

<?
function dickelinie($img,$start_x,$start_y,$end_x,$end_y,$color,$thickness)
{
$angle=(atan2(($start_y - $end_y),($end_x - $start_x)));

$dist_x=$thickness*(sin($angle));
$dist_y=$thickness*(cos($angle));

$p1x=ceil(($start_x + $dist_x));
$p1y=ceil(($start_y + $dist_y));
$p2x=ceil(($end_x + $dist_x));
$p2y=ceil(($end_y + $dist_y));
$p3x=ceil(($end_x - $dist_x));
$p3y=ceil(($end_y - $dist_y));
$p4x=ceil(($start_x - $dist_x));
$p4y=ceil(($start_y - $dist_y));

$array=array(0=>$p1x,$p1y,$p2x,$p2y,$p3x,$p3y,$p4x,$p4y);
imagefilledpolygon ( $img, $array, (count($array)/2), $color );
}
// 範例
header ("Content-type: image/jpeg");
$img = ImageCreate (210, 210) or die("無法初始化新的 GD 影像串流 ");
$backgroundcolor = ImageColorAllocate ($img, 255, 255, 255);
$orange = ImageColorAllocate($img, 252, 102, 4);
dickelinie($img, 10, 10, 10, 200,$orange,2);
dickelinie($img, 10, 200, 200, 10,$orange,2);
dickelinie($img, 200, 10, 200, 200,$orange,2);
imagejpeg($img);
ImageDestroy($img);

?>
0
ajreading at classixshop dot com
19 年前
<?php
// 一段簡單的程式碼,展示如何使用 ImageLine() 函式來建立漸層

// 建立一個 255x255 的影像
$img = ImageCreateTrueColor(255, 255);

$plotD = 0;
while(
$plotD < 256)
{
// 繪製一條線,並將其向下移動並使其更亮以獲得漸層效果
ImageLine($img, 0, $plotD , 255, $plotD, ImageColorAllocate($img, $plotD, $plotD, $plotD));
$plotD++;
}
Header("Content-type: image/png");
ImagePng($img);
ImageDestroy($img);
?>
0
eviloverlord at gmail dot com
19 年前
這段程式碼用於繪製六角形棋盤 (用於遊戲、課程等)。

<?php
// 繪製六邊形棋盤

// 使用者自訂數值
$maxTiles = 7; // 棋盤中心(最寬部分)的格數
$minTiles = 4; // 棋盤邊緣的格數
$side = 30; // 格子邊長,以像素為單位
$bgColor = array(0, 0, 0); // 背景顏色,以 RGB 格式表示
$fgColor = array(255, 255, 255);// 前景顏色,以 RGB 格式表示

// 計算數值
$widthInTiles = range($maxTiles, $minTiles); // 在此範例中:7, 6, 5, 4
$rowsInTiles = count($widthInTiles)*2-1; // 棋盤上的總行數
$xSide = $side*sin(deg2rad(60)); // 斜邊的 x 部分長度
$ySide = $side*sin(deg2rad(30)); // 斜邊的 y 部分長度
$boardWidth = $xSide*$widthInTiles[0]*2; // 棋盤的總寬度
$boardHeight = $rowsInTiles*($side + $ySide) + $ySide; // 棋盤的總高度

// 建立空白圖片並配置前景、背景顏色
$image = imagecreate($boardWidth, $boardHeight);
$bg = imagecolorallocate($image, $bgColor[0], $bgColor[1], $bgColor[2]);
$fg = imagecolorallocate($image, $fgColor[0], $fgColor[1], $fgColor[2]);

// 繪製棋盤
$row = 0;
foreach(
$widthInTiles as $tiles)
{
for (
$i = 0; $i < $tiles+1; $i++)
{
$x1 = $row*$xSide + $i*$xSide*2;
$y1 = $boardHeight/2;
$y1Dif = ($side/2) + $row*($side+$ySide);

$x2 = $x1 + $xSide;
$y2 = $y1;
$y2Dif = $ySide;

$x3 = $x2 + $xSide;

if (
$i < $tiles)
{
imageline($image, $x1, $y1 - $y1Dif, $x2, $y2 - $y1Dif - $y2Dif, $fg);
imageline($image, $x1, $y1 + $y1Dif, $x2, $y2 + $y1Dif + $y2Dif, $fg);
imageline($image, $x2, $y2 - $y1Dif - $y2Dif, $x3, $y1 - $y1Dif, $fg);
imageline($image, $x2, $y2 + $y1Dif + $y2Dif, $x3, $y1 + $y1Dif, $fg);
}

imageline($image, $x1, $y1 - $y1Dif, $x1, $y1 - $y1Dif + $side, $fg);
imageline($image, $x1, $y1 + $y1Dif, $x1, $y1 + $y1Dif - $side, $fg);
}
$row++;
}

// 輸出圖片
header("Content-type: image/png");
imagepng($image);
imagedestroy($image);
?>
0
Lionel Van Bemten
20 年前
這是繪製「漸層」的程式碼 ...
<?
header("Content-type : image/jpeg");

$image = @ImageCreate(200, 100)
or die ("Erreur de cr?ation de l'image");

$lignes_colorees = 1;
$couleur_fond = ImageColorAllocate($image, 255, 255, 255);

$rouge_depart = 100;
$vert_depart = 255;
$bleu_depart = 0;

$rouge_fin = 0;
$vert_fin = 100;
$bleu_fin = 0;

$lignes = 100; //影像的行數

$vert_diff = $vert_fin - $vert_depart;
$vert1 = $vert_diff / $lignes;

$bleu_diff = $bleu_fin - $bleu_depart;
$bleu1 = $bleu_diff / $lignes;

$rouge_diff = $rouge_fin - $rouge_depart;
$rouge1 = $rouge_diff / $lignes;

while ($lignes_colorees <= 100)
{
$rouge2 = $lignes_colorees * $rouge1; $rouge3 = $rouge_depart + $rouge2;
$rouge = round($rouge3);

$vert2 = $lignes_colorees * $vert1;
$vert3 = $vert_depart + $vert2;
$vert = round($vert2);

$bleu2 = $lignes_colorees * $bleu1;
$bleu3 = $bleu_depart + $bleu2;
$bleu = round($bleu2);

$y1 = $lignes_colorees;
$y2 = $lignes_colorees;
$x1 = 1; $x2 = 200;

$couleur = ImageColorAllocate($image, $rouge, $vert, $bleu);
//繪製直線
ImageLine($image, $x1, $y1, $x2, $y2, $couleur); $lignes_colorees ++;
}

//繪製影像
ImageJpeg($image);
?>
0
mueller at inf dot ufsc dot br
20 年前
一個繪製貝茲曲線的演算法

<?php

$segmentos
=30;
$x=array(0,10,80,30);
$y=array(0,10,40,50);

function
bezier($p,$steps){
$t = 1 / $steps;
$temp = $t * $t;
$ret = array();
$f = $p[0];
$fd = 3 * ($p[1] - $p[0]) * $t;
$fdd_per_2=3*($p[0]-2*$p[1]+$p[2])*$temp;
$fddd_per_2=3*(3*($p[1]-$p[2])+$p[3]-$p[0])*$temp*$t;
$fddd = $fddd_per_2 + $fddd_per_2;
$fdd = $fdd_per_2 + $fdd_per_2;
$fddd_per_6 = $fddd_per_2 * (1.0 / 3);
for (
$loop=0; $loop<$steps; $loop++) {
array_push($ret,$f);
$f = $f + $fd + $fdd_per_2 + $fddd_per_6;
$fd = $fd + $fdd + $fddd_per_2;
$fdd = $fdd + $fddd;
$fdd_per_2 = $fdd_per_2 + $fddd_per_2;
}
return
$ret;
}

$by = bezier($y,$segmentos);
$bx = bezier($x,$segmentos);
header ("Content-type: image/jpeg");
$tam = 200;
$im = imagecreate($tam,$tam);
$background_color = imagecolorallocate ($im, 200, 200, 200);
$tc = imagecolorallocate ($im, 233, 14, 91);
for(
$i=0;$i<$segmentos-1;$i++)
imageline($im,$bx[$i],$tam-$by[$i],$bx[$i+1],$tam-$by[$i+1],$tc);
imagejpeg($im);
imagedestroy($im);
?>
0
code_couturier at graffiti dot net
21 年前
# 反鋸齒 draw_line 函式 1.1 (速度更快)

# 這裡是 nanobot 在 chipx86 dot com 發布的 drawLine()
# 在 php.net 上,並由我自行增強/最佳化 :)

# 以下是我所做的一些變更
# 1. 變更為真彩色影像 (未使用 index_var)
# 2. 將 rgb 提取變更為邏輯位移
# 3. 減少函式呼叫次數

function drawQSLine ($image,$x1,$y1,$x2,$y2,$r,$g,$b) {
$icr=$r;
$icg=$g;
$icb=$b;
$dcol = ImageColorAllocate ($image,$icr,$icg,$icb);
if ($y1 == $y2) imageline ($image,$x1,$y1,$x2,$y1,$dcol);
else if ($x1 == $x2) {
imageline ($image,$x1,$y1,$x1,$y2,$dcol);
} else {
$m = ($y2 - $y1) / ($x2 - $x1);
$b = $y1 - $m * $x1;

if (abs ($m) <2) {

$x = min ($x1,$x2);
$endx = max ($x1,$x2)+1;

while ($x < $endx) {
$y=$m * $x + $b;
$y == floor ($y) ? $ya = 1 : $ya = $y - floor ($y);
$yb = ceil ($y) - $y;

$trgb = ImageColorAt($image,$x,floor($y));
$tcr = ($trgb >> 16) & 0xFF;
$tcg = ($trgb >> 8) & 0xFF;
$tcb = $trgb & 0xFF;
imagesetpixel ($image,$x,floor ($y),imagecolorallocate ($image,($tcr * $ya + $icr * $yb),
($tcg * $ya + $icg * $yb),
($tcb * $ya + $icb * $yb)));

$trgb = ImageColorAt($image,$x,ceil($y));
$tcr = ($trgb >> 16) & 0xFF;
$tcg = ($trgb >> 8) & 0xFF;
$tcb = $trgb & 0xFF;
imagesetpixel ($image,$x,ceil ($y),imagecolorallocate ($image,($tcr * $yb + $icr * $ya),
($tcg * $yb + $icg * $ya),
($tcb * $yb + $icb * $ya)));

$x ++;
} # while_x_end
} # if_end
else { # else_abs_end

$y = min ($y1,$y2);
$endy = max ($y1,$y2)+1;

while ($y < $endy) {
$x=($y - $b) / $m;
$x == floor ($x) ? $xa = 1 : $xa = $x - floor ($x);
$xb = ceil ($x) - $x;

$trgb = ImageColorAt($image,floor($x),$y);
$tcr = ($trgb >> 16) & 0xFF;
$tcg = ($trgb >> 8) & 0xFF;
$tcb = $trgb & 0xFF;
imagesetpixel ($image,floor ($x),$y,imagecolorallocate ($image,($tcr * $xa + $icr * $xb),
($tcg * $xa + $icg * $xb),
($tcb * $xa + $icb * $xb)));

$trgb = ImageColorAt($image,ceil($x),$y);
$tcr = ($trgb >> 16) & 0xFF;
$tcg = ($trgb >> 8) & 0xFF;
$tcb = $trgb & 0xFF;
imagesetpixel ($image,ceil ($x),$y,imagecolorallocate ($image, ($tcr * $xb + $icr * $xa),
($tcg * $xb + $icg * $xa),
($tcb * $xb + $icb * $xa)));

$y ++;
}# while_y_end
}# else_abs_end
}# else_y=y_x=x_end
}# drawOSLine_end
0
code_couturier at graffiti dot net
21 年前
# 使用 TrueType 字型的反鋸齒線條!?
# 是的,它有效 - 但效果不太好 - 但速度比
# 其他例程(約 7 秒)快(低於 3 秒)
# 我在這裡看到的。

# 反鋸齒效果很小,而且只在
# 線條的頂部 - 但是,總比
# 沒有好 ;)

# 這裡是 Logan Gunthorpe 的 drawLine 例程
# (logang at deltatee dot com) 由 nanobot 在 chipx86 dot com 發布
# 在 php.net 上,並由我自行增強/最佳化 :)

function drawSoftLine ($image, $x1, $y1, $x2, $y2, $r,$g,$b) {

$fontfile="arial.ttf"; # 點的字型
$str="?" ; # 點的點字元
$size=12; # 點的點大小

$color = ImageColorAllocate ($image, $r,$g,$b);

if ($x2 == $x1) {
$tmp = $x1; $x1 = $y1; $y1 = $tmp;
$tmp = $x2; $x2 = $y2; $y2 = $tmp;
$swapx = true;
}

$m = (float)(( $y2 - $y1 ) / ( $x2 - $x1 ));
$b = (float)($y1 - $m*$x1);

$strx = min ( $x1 , $x2 );
$endx = max ( $x1 , $x2 );
$x=(int)0;

# 原來的迴圈是以一個 for_loop 為基礎
# 裡面有 if_swap。為了加快這個迴圈的速度
# 我將它加倍,以避免永久的 if_call。

if (!$swapx) {
for ($x = $strx; $x <= $endx; $x++) {
$y = (int)($m*$x + $b);
imagettftext($image, $size, 0, $x, $y,
$color, $fontfile,$str);
}
} else {
for ($x = $strx; $x <= $endx; $x++) {
$y = (int)($m*$x + $b);
imagettftext($image, $size, 0, $y, $x,
$color, $fontfile,$str);
}
}

}
-1
huirong dot jin at gmail dot com
16 年前
繪製李薩如曲線的範例 (http://en.wikipedia.org/wiki/Lissajous_curve)
x = a1 * cos(t/T1);
y = a2 * sin(t/T2);

您可以輕鬆修改程式碼來建立自己的示波器應用程式!

<?php
header
("Content-type: image/png");

$T1 = 20;
$T2 = 30;

$myImage = @imagecreatetruecolor(640, 480)
or die(
"無法初始化新的 GD 影像串流");
$text_color = imagecolorallocate($myImage, 255, 255, 224);
$poly_color = imagecolorallocate($myImage, 124, 120, 224);

//逐點計算 x 軸和 y 軸的值
$points = array();
for (
$i=0; $i<1000; $i=$i+1)
{
//定義曲線函數
$x = 310*cos($i/$T1); //定義 x 軸的值
$y = 230*sin($i/$T2);//定義 y 軸的值

//移動座標,附加點的 x 軸和 y 軸值
$points[] = 320+$x; //x 軸的值
$points[] = 240-$y; //y 軸的值
}

//計算點的數量
$totalPoints = count($points)/2;

//繪製標題
$title = "最終繪圖 ($totalPoints 個點)";
imagestring($myImage, 3, 5, 5, $title, $text_color);

/** 逐一繪製點,請注意如果
* 有 10 個點,我們需要繪製 9 條線:
* 1) 從點 0 到 1;
* 2) 從點 1 到 2;
* ...
* ...
* 9) 從點 8 到 9;
*/
for ($i=0; $i<$totalPoints-1; $i++)
{
imageLine($myImage, $points[2*$i], $points[1+2*$i], $points[2+2*$i], $points[3+2*$i], $poly_color);
}

//最後處理
imagepng($myImage);
imagedestroy($myImage);
?>
-2
allenn at hot dot ee
14 年前
使用中點圓演算法以畫筆繪製線條的功能...,如果覺得太過單調,我同意移除 :)))

<?php
//function drawLine(resource$image,int $x0,int $y0,int $x1,int $y1,int $lineWidth,int $color)
function drawLine($image,$x0, $y0,$x1, $y1,$radius,$color)
{
$f = 1 - $radius;
$ddF_x= 1;
$ddF_y = -2 * $radius;
$x= 0;
$y = $radius;
imageline($image,$x0, $y0 + $radius,$x1, $y1 + $radius,$color);
imageline($image,$x0, $y0 - $radius,$x1, $y1 - $radius,$color);
imageline($image,$x0 + $radius, $y0,$x1 + $radius, $y1,$color);
imageline($image,$x0 - $radius, $y0,$x1 - $radius, $y1,$color);

while(
$x< $y)
{
if(
$f >= 0)
{
$y--;
$ddF_y += 2;
$f += $ddF_y;
}
$x++;
$ddF_x+= 2;
$f += $ddF_x;
imageline($image,$x0 + $x, $y0 + $y,$x1 + $x, $y1+ $y,$color);
imageline($image,$x0 - $x, $y0 + $y,$x1 - $x, $y1 + $y,$color);
imageline($image,$x0 + $x, $y0 - $y,$x1 + $x, $y1 - $y,$color);
imageline($image,$x0 - $x, $y0 - $y,$x1 - $x, $y1 - $y,$color);
imageline($image,$x0 + $y, $y0 + $x,$x1 + $y, $y1 + $x,$color);
imageline($image,$x0 - $y, $y0 + $x,$x1 - $y, $y1 + $x,$color);
imageline($image,$x0 + $y, $y0 - $x,$x1 + $y, $y1 - $x,$color);
imageline($image,$x0 - $y, $y0 - $x,$x1 - $y, $y1 - $x,$color);

}
}
header ('Content-type: image/png');
$img = imagecreatetruecolor(600,600);
$col = imagecolorallocate($img,0,255,252);
//use the function
rasterCircle($img,50, 50,540,540,40,$col);
imagepng($img);
imagedestroy($img);
?>
-2
fatpratmatt at gmail dot com
18 年前
這裡有一個函式,可以繪製在特定點交叉的線條 [可能需要一些調整]

<?php
// Image Cross by Matt Evans
// $im - 影像資源
// $x - 線條交叉的 x 坐標
// $y - 線條交叉的 y 坐標
// $size - 每條線的長度
// $colour - 十字線的顏色

function imagecross($im, $x, $y, $size = 5, $colour) {
imageline($im, $x+$size/2, $y+$size/2, $x-$size/2, $y-$size/2, $colour);
imageline($im, $x-$size/2, $y+$size, $x+$size/2, $y-$size, $colour);
}

// 範例
imagecross($im, 50, 50, 5, $crosscolour);
?>
-4
darren at php4hosting dot com
24 年前
它確實有效(經過一些編輯)
將以下程式碼儲存為 graph.php (您不需要任何目錄)

<?php
Header
("Content-type: image/png");
$picWidth=360*2;
$picHeight=200;
$pic=ImageCreate($picWidth+1,$picHeight+1);
$cWhite=ImageColorAllocate($pic,255,255,255);
ImageFilledRectangle($pic,0,0,$picWidth+1,$picHeight+1,$cWhite);
$cRed=ImageColorAllocate($pic,255,0,0);
$cBlue=ImageColorAllocate($pic,0,0,255);
$curX=0;
$curY=$picHeight;
for(
$pt=0;$pt<$picWidth;$pt++){
$newX=$curX+1;
$newY=($picHeight/2)+(cos(deg2rad($newX))*($picHeight/2));
ImageLine($pic,$curX,$curY,$newX,$newY,$cRed);
$curX=$newX;
$curY=$newY;
}
$curX=0;
$curY=$picHeight/2;
for(
$pt=0;$pt<$picWidth;$pt++){
$newX=$curX+1;
$newY=($picHeight/2)+(sin(deg2rad($newX))*($picHeight/2));
ImageLine($pic,$curX,$curY,$newX,$newY,$cBlue);
$curX=$newX;
$curY=$newY;
}
$cBlack=ImageColorAllocate($pic,0,0,0);
ImageLine($pic,0,0,0,$picHeight,$cBlack);
ImageLine($pic,0,$picHeight/2,$picWidth,$picHeight/2,$cBlack);
ImagePNG($pic);
ImageDestroy($pic);
?>
-3
匿名使用者
19 年前
imageline 的座標變數被記錄為整數 (int),十進位格式的值將會被截斷。

例如,在產生影像時應用非整數的縮放比例時,這可能會很有用。

應注意確保這不會產生影響影像品質的重大錯誤。例如:

<?php
$x
=0.00000000001;$y=100;
imageline($img,0,0,0,$y+$x);
imageline($img,0,0,0,$y-$x);
?>

第一條線會是直線,第二條線會有一個階梯。請在適當的地方使用 round() 函數。
To Top