GD picture construction

I’m trying to run a simple script to compile a composite png from a group of individuals.

Viewing each tile individually ( here ) correctly shows the tiles individually colored/discolored depending on state in the database.

However, when compiling them together, I come up with this. An orange-ish wash over the whole image.

$res exists and has the correct information.


$col = 0;
$srow = 0;
$out = imagecreate(512,(64*ceil($res->num_rows/8)));
while($row = $res->fetch_array()) {
 if(!file_exists('gametiles/'.$row['id'].'.jpg')) {
    copy("http://tiles.xbox.com/tiles/".$row['tile'].".jpg",'gametiles/'.$row['id'].'.jpg');
 }
 $source = imagecreatefromjpeg('gametiles/'.$row['id'].'.jpg');
  imagecopymergegray($source,$source,0,0,0,0,64,64,(100*$row['achieved']));
imagecopy($out,$source,(64*$col),(64*$srow),0,0,64,64); 
 $col++;
 if ($col == 8) { 
   $col = 0;
   $srow++;
 }
}
imagepng($out);

What am i missing?

The muting is the idea.
The images are all colored. The idea is that if the achieved field is 0, it will reduce the color factor to 0 (greyscale), otherwise leave it at 100 (color).

Switching to createtruecolor however did the trick. Thanks!

Also, you could try using imagecopymerge instead of imagecopymergegray.
I’ve never used imagecopymergegray, but the name suggests it may be responsible for muting the colours in your images.

Instead of imagecreate(), try imagecreatetruecolor().