如何使用php在img中绘制一个圆圈?

far*_*oft 6 php gd

如何使用php在img中绘制一个圆圈(100px顶部和100px左侧)?

图片网址: image.jpg

我想加载img然后在它的原始内容上绘制一个圆圈

之前:

替代文字

之后:

替代文字

Car*_*rlG 23

看看imagefilledellipse

// Create a image from file.
$image = imagecreatefromjpeg('imgname.jpg');

// choose a color for the ellipse
$ellipseColor = imagecolorallocate($image, 0, 0, 255);

// draw the blue ellipse
imagefilledellipse($image, 100, 100, 10, 10, $ellipseColor);

// Output the image.
header("Content-type: image/jpeg");
imagejpeg($image);
Run Code Online (Sandbox Code Playgroud)

  • +1只是因为你在新年前夕在午夜回答了这个事实! (5认同)

小智 5

首先加载图像,此功能将完全取决于您的源图像,但现在我猜它是一个jpeg:

$img = imagecreatefromjpeg('image.jpg');
Run Code Online (Sandbox Code Playgroud)

然后只需在图像上创建圆圈:

imagefilledellipse($img, 100, 100, 20, 20, 0x0000FF);
Run Code Online (Sandbox Code Playgroud)

我不确定你想如何返回它,但要将它输出到浏览器,只需使用以下内容:

imagejpeg($img);
Run Code Online (Sandbox Code Playgroud)