I'm currently writing a code for a dynami image generating script to return XBox Live gamercards. I've got everything working almost perfectly apart from imagecreatefromjpeg (which I am using to return the thumbnail images of recently played games). My code is below along with a sample image for you to see what I mean;

<?php

/**
 * XBL gamercard
 *
 * Website: http://www.360elites.net
 * Created by euantor
 */


Header ("Content-type: image/png");


#pulling XBL info using the Duncan Mckenzi XBL API.

$name = $_GET["gamertag"];
$name = str_replace(" ", "+", $name);



$url = "http://xboxapi.duncanmackenzie.net/gamertag.ashx?GamerTag=".$name;

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 4);

$data = curl_exec($ch);
curl_close($ch);

$xml = new SimpleXmlElement($data, LIBXML_NOCDATA);



$gamertag = $xml->Gamertag;
$status = "Status:  ".$xml->PresenceInfo->StatusText;
$gamerscore = "Gamerscore:  ".$xml->GamerScore;
$gamerpic = $xml->TileUrl;
$gamerpic = imageCreateFromPNG($gamerpic);
$country = $xml->Country;
$zone = "Zone:  ".$xml->Zone;


$game1 = $xml->RecentGames->XboxUserGameInfo[0]->Game->Image32Url;
$game1 = imageCreateFromjpeg($game1);

$game2 = $xml->RecentGames->XboxUserGameInfo[1]->Game->Image32Url;
$game2 = imageCreateFromjpeg($game2);

$game3 = $xml->RecentGames->XboxUserGameInfo[2]->Game->Image32Url;
$game3 = imageCreateFromjpeg($game3);

$game4 = $xml->RecentGames->XboxUserGameInfo[3]->Game->Image32Url;
$game4 = imageCreateFromjpeg($game4);

$img_handle = imageCreateFromPNG("./images/card.png");
$imgcolor = ImageColorAllocate ($img_handle, 153, 153, 153);
$imgcolorhead = ImageColorAllocate ($img_handle, 255, 255, 255);
$black = imagecolorallocate($img_handle, 0, 0, 0);
$grey = imagecolorallocate($img_handle, 56, 51, 49);
$font = 'arial.ttf';
$fontitalic = 'ariali.ttf';
$fontbold = 'ariblk.ttf';


#Gamertag
imagettftext($img_handle, 11, 0, 4, 15, $black, $fontbold, $name);

#Gamerpic
imagecopymerge($img_handle, $gamerpic, 4, 25, 0, 0, 64, 64, 100);

#Status
imagettftext($img_handle, 9, 0, 75, 40, $grey, $font, $status);

#Gamerscore
imagettftext($img_handle, 9, 0, 75, 55, $grey, $font, $gamerscore);

#Zone
imagettftext($img_handle, 9, 0, 75, 70, $grey, $font, $zone);




imagecopymerge($img_handle, $game1, 4, 95, 0, 0, 32, 32, 100);
imagecopymerge($img_handle, $game2, 39, 95, 0, 0, 32, 32, 100);
imagecopymerge($img_handle, $game3, 73, 95, 0, 0, 32, 32, 100);
imagecopymerge($img_handle, $game4, 108, 95, 0, 0, 32, 32, 100);


ImagePng ($img_handle);
ImageDestroy ($gamerpic);
ImageDestroy ($game1);
ImageDestroy ($img_handle);

?>

Example image: http://www.360elites.net/gamercard/index.php?gamertag=etorano

As you can see, the images at the bottom are of really poor quality whilst the rest of it is perfectly sharp.

I'd love some advice on what I'm doing wrong and/or what I should do to combat the quality problems.

Thanks in advance,
euantor

No ideas anybody? I tried replacing

imagecopymerged()

with

imagecopyresampled()

but to no avail.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.