PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Tue Nov 13, 2018 12:46 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed Jan 04, 2006 10:42 am 
Offline
Forum Newbie

Joined: Wed Jan 04, 2006 10:37 am
Posts: 2
feyd | Please use
Syntax: [ Download ] [ Hide ]
and
Syntax: [ Download ] [ Hide ]
tags where appropriate when posting code. Read:  <a href="http://forums.devnetwork.net/viewtopic.php?t=21171" class="postlink">Posting Code in the Forums</a></span>





Hi guys,



I use this code to create images from database stats. When i use it on the testing server it works perfectly, but only it doesn't draw the filled rectangle. can anyone help me out on this one.. i've gone mad, looking at this code for hours.



Greets



Daniel
Syntax: [ Download ] [ Hide ]
function create_image($ar_hits,$amount,$name)   {

       

        $xax = 550;

        $yax = 301;

       

        // Create image



        $im = imagecreate($xax,$yax);

       

        // color allocation

       

        $white = imagecolorallocate($im,255,255,255);

        $gray = imagecolorallocate($im,200,200,200);

        $black = imagecolorallocate($im,0,0,0);

        $yellow = imagecolorallocate($im,250,210,119);

       

        // make image white

       

        imagefill($im,0,0,$white);

       

        // Zoek grootste kolom

       

        foreach($ar_hits as $b)         {

                if($b > $highest)       {

                        $highest = $b;

                        }

                }      

               

        if($highest == "")      {

                $highest = 1;

                }

               

        // Stel kolom multiplier in

       

        $deler = 300 / $highest;

        $multi = 0.98 * round($deler,3);

       

        // isotopen

       

        for($i=0;$i<=250;$i=$i+50)      {

                $high = 300 - $i;

                $txt_place = $high - 10;

                imageline($im,0,$high,$xax,$high,$gray);

                $value = floor($i / $multi);

                imagestring($im,1,3,$txt_place,$value,$black);

        }



        // ---------------------------------------------------KOLOM--------------------------------



        // Column 1 coordinates

       

        $usable_space = $xax - 21;

        $width = floor($usable_space/ $amount);

        $start_y = 300;

        $start_x = 20;

        $start_x2 = $start_x + $width;



        // text coordinates



        $start_ys = 285;

        $start_xs = (($start_x + $start_x2)-6) / 2;



        for($i=1;$i<=$amount;$i++)      {

       

                // Setting empty columns at zero setting minus ten will make sure nothing is being drawn.

       

                if($ar_hits[$i]=="")    {



                        imagestring($im,2,$start_xs,$start_ys,$i,$black);

                        $start_xs = $start_xs + $width;

                        $start_x = $start_x + $width;

                        $start_x2 = $start_x2 + $width;

               

                        }

                else    {

                       

                        // Get column Higth.

         

                        $hight = 300 - $ar_hits[$i] * $multi;

               

                        // draw columns & date

                 

                        imagefilledrectangle($im,$start_x,$start_y,$start_x2,$hight,$yellow);

                        imagerectangle($im,$start_x,$start_y,$start_x2,$hight,$black);

                        imagestring($im,2,$start_xs,$start_ys,$i,$black);

               

                        // Update coordinates for next column

               

                        $start_xs = $start_xs + $width;

                        $start_x = $start_x + $width;

                        $start_x2 = $start_x2 + $width;  

                }

        }

         

        // Axes

       

        imageline($im,0,300,$xax,300,$black);

        imageline($im,0,300,0,0,$black);

       

        // Save image

       

        $docname = "./images/";

        $docname .= $name;

        $docname .= ".jpg";

       

        imagejpeg($im,$docname);

}



feyd | Please use
Syntax: [ Download ] [ Hide ]
and
Syntax: [ Download ] [ Hide ]
tags where appropriate when posting code. Read:  <a href="http://forums.devnetwork.net/viewtopic.php?t=21171" class="postlink">Posting Code in the Forums</a></span>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 04, 2006 12:07 pm 
Offline
Jedi Mod
User avatar

Joined: Tue Dec 21, 2004 6:03 pm
Posts: 5263
Location: usrlab.com
This is one of those annoying issues with PHP/GD that's only obvious if you know about it. imagerectangle() will work if you specify bottom-left, top-right .. but imagefilledrectangle() won't. You need to change it to be top-left, bottom-right.

Syntax: [ Download ] [ Hide ]
imagefilledrectangle($im,$start_x,$hight,$start_x2,$start_y,$yellow);

To highlight the difference, change your imagefilledrectangle() function to imageline().


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 05, 2006 8:05 am 
Offline
Forum Newbie

Joined: Wed Jan 04, 2006 10:37 am
Posts: 2
Well thanks for the support anywayz, but I still find it very strange that it does work on my testing server.. but doesn't online.. :S:S

gr Daniel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 05, 2006 8:55 am 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
talking outta my ass here, but could it be that you're using imagejpeg() with imagecreate() and not imagecreatetruecolor() ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 05, 2006 11:48 am 
Offline
Jedi Mod
User avatar

Joined: Tue Dec 21, 2004 6:03 pm
Posts: 5263
Location: usrlab.com
The option to have the variable order as bottom-left,top-right is something that changed in a relatively recent version of GD. I imagine there must be a couple of minor versions difference between your test server and production server. Or something. I definitely get the same problem, and tweaking the order definitely fixes it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group