Jump to content

[SOLVED] Gd problem has me stumped


skatermike21988

Recommended Posts

Ok I am having this weird problem, I am using gd to create an xbox live gamercard, the gamercard include the users xbox live avatar. Like so here:

 

semesic.png

 

Now the url to get the avatar is:

 

http://avatar.xboxlive.com/avatar/PERSONS GAMERTAG HERE/avatar-body.png

 

Now in the above image the users gamertag is semesic and doesn't contain any spaces, but if for say my gamertag which is cerebal asassin where used gd returns an error and does so for any gamertag with a space in it. saying that the image is not a valid png, I have tried copying the file to my site but then when I view just the copied image i get:

 

"The image “http://xboxpremiumthemes.com/gamercard/1e242025290787daf9cc9f682b0a11c5.png” cannot be displayed, because it contains errors."

 

but when the same image is viewed on xbox site it's fine. Also I can copy over the avatars that don't have a space with no problems. I don't seem to know why. It's starting to drive me nuts.

 

My gamercard looks like this because it can't get the avatar.

 

Cerebal%20Asassin.png I hope I didn't make any of this super confusing. :/

 

Here is my code:

 

Imagecreate.php:

<?

//THESE FILES GET XBOX LIVE DATA, THIS ALL WORKS FINE
include'gamercard1.php';
//XBOX RETRIEVE SCRIPT
include'cache.php';

mysql_connect("localhost", "evenlame_site", "skater2") or die(mysql_error());
mysql_select_db("evenlame_site") or die(mysql_error());

$query = 'SELECT * FROM `users`';

$result = mysql_query($query) or die('Cannot get data.'.mysql_error());

while ($row = mysql_fetch_assoc($result)) {

$gamertag=$row["gamertag"];
include'xbox.php';

if($xml->State=="Unknown") {
$error="1";
}
if($xbox_service_error=="true") {
$error="1";
}

createthumb('card.png','tn_av.png',$gamertag,$Info,$Zone,$gamerscore,$AccountStatus,$gamerpic,$Games,$online,$error);



}

 

Then here's gamercard1.php

 

<?

function createthumb($name,$filename,$gamertag,$Info,$Zone,$gamerscore,$AccountStatus,$gamerpic,$Games,$online,$error){
if($error!="1") {


$image = imagecreatetruecolor(290, 168);
$image=imagecreatefrompng($name);
imagesetthickness ( $image, 5 );
$Info=wordwrap($Info,25);

$white = imagecolorallocate($image, 255, 255, 255); 

if($AccountStatus=="Gold") {
$gccolor= imagecolorallocate($image, 255, 226, 104); 
}
elseif($AccountStatus=="Silver"){
$gccolor= imagecolorallocate($image, 185, 185, 185); 
}
$gamerscore = number_format($gamerscore);

$font = 'comicbd.ttf'; // Set the TTF font we want to use
// This is just a variable set, which we will later use in the imagettftext funciton

$gamertag_fontsize = "15"; // Set the size of the font we want to use
$fontsize = "8"; // Set the size of the font we want to use
$fontsize2 = "12"; // Set the size of the font we want to use
// This again is just a variable like above. 


list($width, $height) = getimagesize($name);

  
  $percent = 0.6;
$new_width = $width * 1;
$new_height = $height * 1;

/////////////////////////////////
////////////////////////////////
//THIS PART HERE COMES UP WITH ERRORS ONLY FOR GAMERTAGS WITH A SPACE, I HAVE TRIED ADDING %20 IN PLACE OF THE SPACE WITH NO LUCK 
////////////////////////////////


//add the avatar
$avatar_url = "http://avatar.xboxlive.com/avatar/$gamertag/avatar-body.png";


$avatar = ImageCreateFromPNG($avatarurl);

imagecolortransparent($avatar, imagecolorallocate($avatar, 0, 0, 0));
imagecopyresampled($image,$avatar, 170, 0, 0, 0, $new_width, $new_height, $width, $height);




////////////////////
///////////////////
//EVERYTHING ELSE BELOW WORKS LIKE IT IS SUPPOSED TO

//add the gamerpic
$gamerpic = ImageCreateFromPNG($gamerpic);
imagecolortransparent($gamerpic, imagecolorallocate($gamerpic, 0, 0, 0));
imagecopyresampled($image,$gamerpic, 10, 9, 0, 0, 64, 64, 64, 64);

//make gamerpic apper 3d'ish
$gamerpictop = ImageCreateFromPNG('gamertagcover.png');
imagecolortransparent($gamerpictop, imagecolorallocate($gamerpictop, 0, 0, 0));
imagecopyresampled($image,$gamerpictop, 10, 9, 0, 0, 64, 64, 64, 64);

$gamesy=10;
//DO THE MATH FOR THE GAMES:
$numgames=count($Games);
if($numgames<=4){
$numgames=$numgames-1;
} else {
$numgames="4";
}

for($i=0; $i<=$numgames; $i++){
$gameimage=$Games[$i]->Game->Image32Url;
$gameimage = ImageCreateFromJPEG($gameimage);
imagecolortransparent($gameimage, imagecolorallocate($gameimage, 0, 0, 0));
$gameimagecover = ImageCreateFromPNG('gamecover.png');
imagecolortransparent($gameimagecover, imagecolorallocate($gameimagecover, 0, 0, 0));
if($i!=0){
$gamesy=$gamesy+38;
}
imagecopyresampled($image,$gameimage, $gamesy, 105, 0, 0, 32, 32, 32, 32);
imagecopyresampled($image,$gameimagecover, $gamesy, 105, 0, 0, 32, 32, 32, 32);
}
if($online=="true") {
$online = ImageCreateFromPNG('online.png');
imagecolortransparent($online, imagecolorallocate($online, 0, 0, 0));
imagecopyresampled($image,$online, 282, 13, 0, 0, 4, 25, 4, 25);
}
else
{
$offline= ImageCreateFromPNG('offline.png');
imagecolortransparent($offline, imagecolorallocate($offline, 0, 0, 0));
imagecopyresampled($image,$offline, 285, 13, 0, 0, 4, 25, 4, 25);
}
$membertype="$AccountStatus Member";
//ADDS THE TEXT TO THE IMAGE
imagefttext($image, $gamertag_fontsize, 0, 78, 25, $gccolor, $font, $gamertag); 
imagefttext($image, $fontsize, 0, 78, 40, $white, $font, $Info); 
imagefttext($image, $fontsize, 0, 115, 90, $white, $font, $Zone); 
imagefttext($image, $fontsize, 0, 25, 90, $white, $font, $gamerscore); 
imagefttext($image, $fontsize2, 0, 45, 155, $gccolor, $font, $membertype); 






$filename="gamercardimages/$gamertag.png";

imagepng($image,$filename); 
imagedestroy($image); 
}
}

Link to comment
Share on other sites

First if you use full <?php insteadof short <? tags it'll be better for you for server compatability and easier for us beause <?php color codes the script. That's just like looking at plain text and nothing stands out.

 

Which line actually links to the avatar image and tries to download it?

Link to comment
Share on other sites

sorry about the tags, but um right now i don't have it using the part to actually d/l it but the line

 

<?php
$avatar_url = "http://avatar.xboxlive.com/avatar/$gamertag/avatar-body.png";


$avatar = ImageCreateFromPNG($avatarurl);

imagecolortransparent($avatar, imagecolorallocate($avatar, 0, 0, 0));
imagecopyresampled($image,$avatar, 170, 0, 0, 0, $new_width, $new_height, $width, $height);
?>

 

is where the errors at, now the code I was using to download is:

 

<?php
// this must be done somehow how you want
$avgamer= md5($gamertag);
$filename = "$avgamer.png";

if(!@copy("http://avatar.xboxlive.com/avatar/$gamertag/avatar-body.png",$filename))
{
    $errors= error_get_last();
    echo "COPY ERROR: ".$errors['type'];
    echo "<br />\n".$errors['message'];
} else {
    echo "File copied from remote!";
}
?>

and is located in xbox.php

 

this here is of a image without a space copied: http://xboxpremiumthemes.com/gamercard/0a33a2f1a7fd4eaeff8528050057dc68.png

 

and this is of one with a space copied: http://xboxpremiumthemes.com/gamercard/542346437efbf663b5bcc5d2e669fa2f.png

 

sorry if its still confusing, I just got home from work and am tired, just that this has been driving me batty for weeks :(

Link to comment
Share on other sites

Ok i tried the urlencode but still getting the same errors:

 

Warning: imagecreatefrompng(http://avatar.xboxlive.com/avatar/Cerebal+Asassin/avatar-body.png) [function.imagecreatefrompng]: failed to open stream: HTTP request failed! HTTP/1.0 500 Internal Server Error in /home/evenlame/public_html/xboxpremiumthemes.com/gamercard/gamercard1.php on line 45

 

 

Link to comment
Share on other sites

You're using the GD library functions without checking them for values returned. A lot of the function will return a boolean true or false and it doesn't seem like you're checking to see if anything has failed.

 

actually as far as the avatar goes i do have it check, if it fails it'll show a blank avatar, but i removed that to actually see why it's failing, the code i have to check it is:

 

<?php
if(!$avatar = ImageCreateFromPNG($avatarurl);
) {
$avatar = ImageCreateFromPNG("unknown.png");
}
?>

 

Link to comment
Share on other sites

Okay, then replace any spaces with %20 instead:

 

<?php
$gamertag = str_replace(' ', '%20', $gamertag);
?>

You are awesome, that worked perfect! thank you so much, I finnally have it working! Thank you again. I could have sworn I tried that before, but I guess not. :/

 

You can see the final output in my original post.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.