imagefilledrectangle

Can someone tell me what’s wrong with th code ? why i don’t get the same image ?

here’s the image at this url: http://www.tuxradar.com/practicalphp/11/2/3

[php]<?php
$image = imagecreate(400,300);
$gold = imagecolorallocate($image, 255, 240, 00);
$white = imagecolorallocate($image, 255, 255, 255);
$colour = $white;

for ($i = 400, $j = 300; $i > 0; $i -= 4, $j -= 3) {
    if ($colour == $white) {
        $colour = $gold;
    } else {
        $colour = $white;
    }

    imagefilledrectangle($image, 400 - $i, 300 - $j, $i, $j, $colour);
}

imagepng($image);
imagedestroy($image);

?>[/php]

I don’t get the same image either in IE…

Just a box with yellow border.

Same as me…tried in Firefox, Chrome, Maxthon but nothing…don’t know why so please if someone can help to solve this mystery

The issue is the code redraws over it self and that’s why you only see the last outer border is code… Whoever posted this didn’t think it through or test it…

Notice I’m adding an if statement below to stop it the halfway point so it doesn’t draw over itself.

Normally, you wouldn’t do an if statement like I’m doing, because it’s retarded to do a loop an extra 200 times for nothing. But I’m doing it this way so you can see what’s happening.

All I did was plot it out on a piece of paper to understand what it was doing and the it made complete sense.

[php]<?php
$image = imagecreate(400,300);
$gold = imagecolorallocate($image, 255, 240, 00);
$white = imagecolorallocate($image, 255, 255, 255);
$colour = $white;

  for ($i = 400, $j = 300; $i > 0; $i -= 4, $j -= 3) {
      if ($colour == $white) {
          $colour = $gold;
     } else {
         $colour = $white;
     }

     if ($i > 200)
  {
      imagefilledrectangle($image, 400 - $i, 300 - $j, $i, $j, $colour);
     }
 }

 imagepng($image);
 imagedestroy($image);

?>[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service