Can You Load An Image In PHP Imagestring?

Obsidian Age

New member
Heya, just wondering if it is somehow possible to load an image into an imagestring. It's for an API that returns basic details about players in Halo: Reach. The code is:

<?php
$image = imagecreatefrompng("black.png");
$text_color = imagecolorallocate($image, 255, 255, 255);
$apiKey = '**************************************';
if(!empty($_POST['gamertag']))
$playerGamertag = $_POST['gamertag'];
$url = 'http://www.bungie.net/api/reach/reachapijson.svc/player/details/nostats/' . rawurlencode($apiKey) . '/' . rawurlencode($playerGamertag);
$output = file_get_contents($url);
$obj = json_decode($output);
$data = json_decode($output,true);
if(!$obj->Player)
die("\nPlayer not found...");
imagestring($image,5,1,1, $playerGamertag, $text_color); // Size, X, Y
imagestring($image,5,1,15, sprintf("Service Tag: %s", $obj->Player->service_tag), $text_color);
imagestring($image,5,1,30, sprintf("Total Games Played: %d", $obj->Player->games_total), $text_color);
imagestring($image,5,1,45, sprintf("Campaign Progress (Single Player): %s", $obj->Player->CampaignProgressSp), $text_color);
imagestring($image,5,1,60, sprintf("Campaign Progress (Co-Op): %s", $obj->Player->CampaignProgressCoop), $text_color);
imagestring($image,5,1,75, sprintf("Armory Progress: %2d%%", $obj->Player->armor_completion_percentage), $text_color);
imagestring($image,5,1,90, sprintf("Commendation Progress: %2d%%", $obj->Player->commendation_completion_percentage), $text_color);
imagestring($image,5,1,105, sprintf("Daily Challnges Completed: %d", $obj->Player->daily_challenges_completed), $text_color);
imagestring($image,5,1,120, sprintf("Weekly Challenges Completed: %d", $obj->Player->weekly_challenges_completed), $text_color);

//NOT WORKING
imagestring($image,5,1,135, $obj->PlayerModelUrl, $text_color);

header("Content-type: image/png");
imagepng($image);
?>

Bonus points if you can tell me why my two percentage fields aren't outputting correctly! (%2d%%)
 
Back
Top