GD in my own function

Discussion in 'PHP' started by bdtushar, Feb 25, 2009.

  1. #1
    my code is below which is not working

    <?php
    $recwidth=550;
    $recheight=300;
    $canvas = imagecreate($recwidth, $recheight);
    $white = imagecolorallocate($canvas, 255, 255, 255);
    $black = imagecolorallocate($canvas, 0, 0, 0);
    function rec($startx,$starty,$endx,$endy){
    imagerectangle($canvas, $startx, $starty, $endx, $endy, $black);
    }
    rec(20,100,200,200);
    // Output and free from memory
    header('Content-Type: image/jpeg');

    imagejpeg($canvas);
    imagedestroy($canvas);
    ?>


    Please Help me someone
     
    bdtushar, Feb 25, 2009 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    whats your question?
     
    bartolay13, Feb 25, 2009 IP
  3. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #3
    function rec($startx,$starty,$endx,$endy){
    global $canvas; // <-------- here
    imagerectangle($canvas, $startx, $starty, $endx, $endy, $black);
    }
     
    gapz101, Feb 25, 2009 IP
  4. bdtushar

    bdtushar Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thank u so much gapz101

    It was finally solved by u. This will help me to finalize my thesis. But little correction with u.

    function rec($startx,$starty,$endx,$endy){
    global $canvas; // <-------- here
    lobal $black; // <-------- new here
    imagerectangle($canvas, $startx, $starty, $endx, $endy, $black);
    }

    Would u please tell me when and why we use global. Advantages and Disadvantages
     
    bdtushar, Feb 26, 2009 IP