CrazeD Posted December 29, 2007 Share Posted December 29, 2007 I'm working on my game-server monitor and would like to include map images above all of it. I can't run the script directly on my webhost, so I have it running on my dedicated game-server box, generated by an image. So, I need to know how to generate two images and put one over the other...if that makes sense. Here's my existing code for the image with the regular text details: $image = imagecreate (220,$size); $background = imagecolorallocate($image, 0, 0, 0); $fontColor = imagecolorallocate($image, 255, 255, 255); imagestring($image, 3, 10, 5, $hostname, $fontColor); imagestring($image, 3, 10, 20, $ip, $fontColor); imagestring($image, 3, 10, 35, $game, $fontColor); imagestring($image, 3, 10, 50, $map, $fontColor); imagestring($image, 3, 10, 65, $numplayers, $fontColor); imagestring($image, 3, 10, 80, $gametype, $fontColor); imagestring($image, 3, 10, 95, $version, $fontColor); imagestring($image, 3, 10, 120, 'PLAYERLIST', $fontColor); if ($player[1]['name'] == '') { imagestring($image, 3, 10, 135, 'Server is empty', $fontColor); } else { imagestring($image, 3, 10, 135, 'Name', $fontColor); imagestring($image, 3, 123, 135, 'Score', $fontColor); imagestring($image, 3, 178, 135, 'Ping', $fontColor); $pos = 150; for ($i = 1; $i <= $playerCount; $i++) { $pos = $pos+15; imagestring($image, 3, 10, $pos, $player[$i]['name'], $fontColor); imagestring($image, 3, 123, $pos, $player[$i]['score'], $fontColor); imagestring($image, 3, 178, $pos, $player[$i]['ping'], $fontColor); } } Header("Content-type: image/png"); imagepng($image); imagedestroy($image); I just need to know how to generate another image (using imagecreatefrompng ()) and then place it "over" (on) my other image. Sorry if that's confusing, but I really need some help with this. I tried to Google it, but for lack of a better search term I didn't really find anything. Thanks. Link to comment https://forums.phpfreaks.com/topic/83641-solved-image-help-need-to-place-an-image-over-an-image/ Share on other sites More sharing options...
Barand Posted December 29, 2007 Share Posted December 29, 2007 have a look at www.php.net.imagecopymerge Link to comment https://forums.phpfreaks.com/topic/83641-solved-image-help-need-to-place-an-image-over-an-image/#findComment-425551 Share on other sites More sharing options...
CrazeD Posted December 30, 2007 Author Share Posted December 30, 2007 I looked over that and was a little confused, and couldn't make it work. $image = imagecreate (220,$size); $image2 = imagecreatefrompng ('images/maps/overgrown.png'); $background = imagecolorallocate($image, 0, 0, 0); $fontColor = imagecolorallocate($image, 255, 255, 255); imagestring($image, 3, 10, 5, $hostname, $fontColor); /*imagestring($image, 3, 10, 20, $ip, $fontColor); imagestring($image, 3, 10, 35, $game, $fontColor); imagestring($image, 3, 10, 50, $map, $fontColor); imagestring($image, 3, 10, 65, $numplayers, $fontColor); imagestring($image, 3, 10, 80, $gametype, $fontColor); imagestring($image, 3, 10, 95, $version, $fontColor); imagestring($image, 3, 10, 120, 'PLAYERLIST', $fontColor);*/ imagecopymerge ($image, $image2, 0, 0, 0, 0, 180, 180); /*if ($player[1]['name'] == '') { imagestring($image, 3, 10, 135, 'Server is empty', $fontColor); } else { imagestring($image, 3, 10, 135, 'Name', $fontColor); imagestring($image, 3, 123, 135, 'Score', $fontColor); imagestring($image, 3, 178, 135, 'Ping', $fontColor); $pos = 150; for ($i = 1; $i <= $playerCount; $i++) { $pos = $pos+15; imagestring($image, 3, 10, $pos, $player[$i]['name'], $fontColor); imagestring($image, 3, 123, $pos, $player[$i]['score'], $fontColor); imagestring($image, 3, 178, $pos, $player[$i]['ping'], $fontColor); } }*/ Header("Content-type: image/png"); imagepng($image); imagedestroy($image); Don't mind the commented out stuff, I'm just trying to make this work before that stuff comes into play. What am I doing wrong? Thanks. Link to comment https://forums.phpfreaks.com/topic/83641-solved-image-help-need-to-place-an-image-over-an-image/#findComment-425588 Share on other sites More sharing options...
CrazeD Posted December 30, 2007 Author Share Posted December 30, 2007 Ok I got it to work...kind of. It's heavily distorting the second image. I Googled that for a bit and it seems a lot of people have problems with that but no answers. Can somebody help me with this? The images are all in png, and I tried gif and jpeg as well. http://72.37.226.250/test_monitor.php?ip=72.37.226.250:28960 Original image: http://72.37.226.250/images/maps/shipment.png Code: $get_map_image = explode ('_', $data['mapname']); $get_map_image = $get_map_image[1]; if (file_exists ('images/maps/'.$get_map_image.'.png')) { $map_image = imagecreatefrompng ('images/maps/'.$get_map_image.'.png'); } else { $map_image = imagecreatefrompng ('images/maps/'.$map_image.'.png'); } $image = imagecreate (220,$size); $background = imagecolorallocate($image, 0, 0, 0); $fontColor = imagecolorallocate($image, 255, 255, 255); imagestring($image, 3, 70, 175, $map, $fontColor); imagestring($image, 3, 10, 200, $hostname, $fontColor); imagestring($image, 3, 10, 215, $ip, $fontColor); imagestring($image, 3, 10, 230, $game, $fontColor); imagestring($image, 3, 10, 245, $numplayers, $fontColor); imagestring($image, 3, 10, 260, $gametype, $fontColor); imagestring($image, 3, 10, 275, $version, $fontColor); imagestring($image, 3, 10, 300, 'PLAYERLIST', $fontColor); imagecopymerge ($image, $map_image, 35, 20, 0, 0, 150, 150, 100); if ($player[1]['name'] == '') { imagestring($image, 3, 10, 320, 'Server is empty', $fontColor); } else { imagestring($image, 3, 10, 320, 'Name', $fontColor); imagestring($image, 3, 123, 320, 'Score', $fontColor); imagestring($image, 3, 178, 320, 'Ping', $fontColor); $pos = 335; for ($i = 1; $i <= $playerCount; $i++) { $pos = $pos+15; imagestring($image, 3, 10, $pos, $player[$i]['name'], $fontColor); imagestring($image, 3, 123, $pos, $player[$i]['score'], $fontColor); imagestring($image, 3, 178, $pos, $player[$i]['ping'], $fontColor); } } Header("Content-type: image/png"); imagepng($image); imagedestroy($image); I'd really appreciate some help, I'd like to get this done soon. Thanks! Link to comment https://forums.phpfreaks.com/topic/83641-solved-image-help-need-to-place-an-image-over-an-image/#findComment-425840 Share on other sites More sharing options...
Barand Posted December 30, 2007 Share Posted December 30, 2007 Does it improve with $image = imagecreatetruecolor (220,$size); BTW, don't forget imagedestroy($map_image) too. Link to comment https://forums.phpfreaks.com/topic/83641-solved-image-help-need-to-place-an-image-over-an-image/#findComment-425888 Share on other sites More sharing options...
CrazeD Posted December 30, 2007 Author Share Posted December 30, 2007 Does it improve with $image = imagecreatetruecolor (220,$size); BTW, don't forget imagedestroy($map_image) too. imagecreatetruecolor worked! Thanks a bunch! Link to comment https://forums.phpfreaks.com/topic/83641-solved-image-help-need-to-place-an-image-over-an-image/#findComment-425893 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.