I am trying to make a blackjack game that teaches card counting. The visual component is important so I have a mock up of a deck of cards and some code that copies each dealt card’s png file into a larger image to display the player and dealer’s hands. Unfortunately, every once in a while, my imagecopy is copying just a couple png’s without color (in grayscale). Here is the code for image creation, the rest of the code seems to be behaving flawlessly:
$cards = imagecreate( 360, 600 );
imagecopy( $cards, drawCard($dealershand[0]), 10, 10, 0, 0, 171, 254 );
imagecopy( $cards, @imagecreatefrompng("deckback.png"), 190, 10, 0, 0, 171, 254 );
imagecopy( $cards, drawCard($playershand[0]), 10, 336, 0, 0, 171, 254 );
imagecopy( $cards, drawCard($playershand[1]), 190, 336, 0, 0, 171, 254 );
If you need more code, just let me know and I can supply it but basically “drawCard” contains basically an if statement for red or black card and then a switch for the face value and outputs the @imagecreatefrompng( carddealt ), with card dealt file name generated inside as mocked up. $dealershand and $playershand are just arrays of two cards, each with a face and suit value.
Thanks and sorry if this is already answered.
Try using imagecreatetruecolor instead of imagecreate.