title: GD using wrong color if the image is bigger
body: <p>I'm trying to generate an image by reading characters from a file and setting pixels accordingly. Everything works fine if I input data that represents e.g. a 50 by 50 px image. But if I enter something bigger e.g. 200 x 200 it's using the wrong color to fill the land!</p>
  
  <p>Small example:<br>
  <a href="http://pastebin.com/M5pdvDrE" rel="nofollow noreferrer">50x50 Data pastebin</a><br>
  <a href="https://i.stack.imgur.com/rq4kK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rq4kK.png" alt="enter image description here"></a><br>
  Big Example:
  <a href="http://pastebin.com/bcr0SX30" rel="nofollow noreferrer">200x200 Data pastebin</a><br>
  <a href="https://i.stack.imgur.com/QAuRv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QAuRv.png" alt="enter image description here"></a></p>
  
  <p>and the code:</p>
  
  <pre><code>&lt;?php
  
  $scale=2;
  $file = file_get_contents('data');
  $rows = explode("\n", $file);
  
  $land = "x"; $water="o";
  
  $width=0;
  $height=count($rows);
  
  $index=0;
  foreach($rows as $row){
      $rows[$index] = preg_split('//', $rows[$index]);
      $index++;
      $width=$index;
  }
  
  $img = imagecreatetruecolor($width,$height);
  $color1 = imagecolorallocate($img, 139,69,19);
  $color2 = imagecolorallocate($img, 10,25,255);
  
  
  for($i=0;$i&lt;count($rows);$i++){
      $x=-1;
      $y=$i;
      foreach($rows[$i] as $key =&gt; $char){
          $landMultiplier = 1;
          $waterMultiplier=1;
          switch ($char){
              case $land:
                  if($rows[$i][$key-1]==$water || $rows[$i][$key+1]==$water || $rows[$i-1][$key]==$water ){
                      $landMultiplier = -20;
                  }elseif($rows[$i][$key-2]==$water || $rows[$i][$key+2]==$water || $rows[$i-2][$key]==$water ){
                      $landMultiplier = -10;
                  }
                  $r = max(0,min(255,rand(130,139) + $landMultiplier));
                  $g = max(0,min(255,rand(60,69) + $landMultiplier));
                  $b = max(0,min(255,rand(10,19) + $landMultiplier));
                  $color1 = imagecolorallocate($img,$r ,$g,$b);
                  imagesetpixel($img,$x,$y,$color1);
                  break;
              case $water: 
                  $color2 = imagecolorallocate($img, rand(0,10),rand(0,25),255);
                  imagesetpixel($img,$x,$y,$color2);
                  break;
          }
          $x++;
      }
  }
  $new_img = imagecreate($scale * $width,$scale * $height);
  imagecopyresized($new_img,$img,0,0,0,0,$scale * $width,$scale * $height,$width,$height);
  
  header('Content-Type: image/png');
  imagepng($new_img);
  ?&gt;
  </code></pre>