PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, October 11, 2022

[FIXED] Why do I see this weird line in my GD pie graph?

 October 11, 2022     gd, php     No comments   

Issue

Why do I see this weird line in my GD pie graph?

pie graph

Here's the PHP:

<?php
$ratio = $_GET['ratio'];
$height = intval(isset($_GET['size']) ? $_GET['size'] : 200);
$width = intval(isset($_GET['size']) ? $_GET['size'] : 200);
$startDegree = 270;
$ratiodeg = $ratio * 360;
$image = imagecreatetruecolor($width,$height);
imagealphablending($image,false);
imagesavealpha($image,true);
$color = imagecolorallocate($image,127,26,40);
$grey = imagecolorallocate($image,200,200,200);
$transparent = imagecolorallocatealpha($image,255,255,255,127);
imagefilledrectangle($image,0,0,$width,$height,$transparent);
if($ratio > 0){
    if($ratio < 1){
        imagefilledarc($image,$width / 2,$height / 2,$width,$height,$ratiodeg + $startDegree,$startDegree,$grey,IMG_ARC_PIE);
    }
    imagefilledarc($image,$width / 2,$height / 2,$width,$height,$startDegree,$ratiodeg + $startDegree,$color,IMG_ARC_PIE);
}
else{
    imagefilledarc($image,$width / 2,$height / 2,$width,$height,$startDegree,360 + $startDegree,$grey,IMG_ARC_PIE);
}
imagefilledellipse($image,$width / 2,$height / 2,$width * 0.95,$height * 0.95,$transparent);
header("Content-type: image/png");
imagepng($image);
imagedestroy($image);
?>

Solution

My output

I ran your code and got this image..

Here are my PHP details

Version: 5.4.3

GD: bundled (2.0.34 compatible)

What ratio are you passing? I used 1, 4, 4.65 (which made a circle with a bit missing) but I never got that line!



Answered By - Dale
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing