Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8627461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:17:11+00:00 2026-06-12T08:17:11+00:00

I’ve created my own custom Spider Chart generator using PHP and the GD Library.

  • 0

I’ve created my own custom Spider Chart generator using PHP and the GD Library. Basically, the user answers a series of questions, and a Spider Chart is generated based on the answers to the questions.

Overall, everything works great. The chart that’s generated is mathematically accurate (though, the quiz needs to be reworded entirely), and it seems to work quickly enough. However, what I’ve noticed is that when I go and try to save the image from Firefox (version 15.0.1 on Snowleopard), the image itself cannot be opened. Saving the image from any other browser yields a working image that can be opened in any image editor.

What I find particularly interesting is WHEN it breaks. I’ll see if I can explain this accurately.

The full working version is [no longer here], and here’s all the relevant bits of code involved in the processing and generation of the Chart itself:

chart.php (process POST data)

$r = 300; //Radius
//Processing of information passed from the previous form yields an array $cargs
//$cargs contains key value pairs. Values are of type float with a range 0-$r

$chart = new Chart($r); //Generates Canvas and Circle
$chart->generate($cargs); //Generates Polygon based on $cargs

header("Content-type: image/png");
imagesavealpha($chart->image, true);
imagepng($chart->image);
imagedestroy($chart->image);
?>

SS_Chart.php (Chart Object)

class Chart
{
    public $radius;
    public $diameter;
    public $image;

    private $_labels;
    private $_values;
    private $_n;

    public function Chart($r=300)
    {
        $this->radius = $r;
        $this->diameter = 2*$r;
        $this->image = $this->_get_transparent_canvas($this->diameter, $this->diameter);
        $this->_draw_circle();
    }
    public function generate($arr)
    {
        if(count($arr)>2)
        {
            $red = imagecolorallocate($this->image, 255, 0, 0);
            $this->_n = count($arr);
            $this->_labels = array_keys($arr);
            $this->_values = array_values($arr);

            $coors = array();
            for($i=0;$i<$this->_n;$i++)
            {
                //Generate coordinates....
            }
            imagefilledpolygon($this->image, $coors, $this->_n, $red);
        }
        else
            trigger_error('Number of $key=>$value pairs in arguments must be 3 or greater', E_USER_ERROR);
    }
    private function _get_transparent_canvas($w, $h)
    {
        $canvas = imagecreatetruecolor($w, $h);
        imagealphablending($canvas, true);
        $transparent = imagecolorallocatealpha($canvas, 0, 0, 0, 127);
        imagefill($canvas, 0, 0, $transparent);

        return $canvas;
    }
    private function _draw_circle()
    {
        $white = imagecolorallocate($this->image, 255, 255, 255);
        imagearc($this->image, $this->radius, $this->radius, $this->diameter, $this->diameter,  0, 360, $white);
    }
}

Here’s where it gets interesting: When commenting out $chart->generate($cargs); in chart.php, Firefox will yield a working and editable Transparent png according to the dimensions, as well as a white circle.

However, if I comment out everything within public function generate in SS_Chart.php and leave $chart->generate($cargs); uncommented (basically resulting in a method that runs, but doesn’t actually do anything), the resulting png can no longer be opened.

How is that possible??

I haven’t found much on this issue apart from the odd forum here and there describing some difficulties in getting Firefox to jive with the GD Library, but this is the first time I’ve ever encountered anything like this.

  • If it were a problem with my code, wouldn’t the issue be prevalent across all browsers?
  • Does this have more to do with Scoping, and the fact that the main GD functions are utilized within an Object?
  • Moreover, does this issue happen for anybody else?
  • Has anybody run into a problem like this before?
  • Is this even a known problem?

This is actually more of a curiosity than it is a real “problem”, but any insight into the matter would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:17:12+00:00Added an answer on June 12, 2026 at 8:17 am

    Look into the source of that SAVED image

    <br />
    <b>Fatal error</b>:  Number of $key=>$value pairs in arguments must be 3 or greater in <b>/home/mattmaio/public_html/dev/assets/classes/SS_Chart.php</b> on line <b>38</b><br />
    

    When you save it in Firefox, fireox doesn’t save what you see. What it does is – it makes an another GET request on save.

    GET http://dev.mattmaiorano.com/chart.php HTTP/1.1
    Host: dev.mattmaiorano.com
    User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0.1
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Language: en-gb,en;q=0.5
    Accept-Encoding: gzip, deflate
    Connection: keep-alive
    Referer: http://dev.mattmaiorano.com/chart.php
    

    Obviously all POST data is lost hence the error. I’m not sure about your commenting out thing but I guess that’s what it is.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I am reading a book about Javascript and jQuery and using one of the
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.