Ciao ragazzi e ragazze!
Sto realizzando un sistema di "userbars", ho un piccolo problema: i template possono avere una o più immagini con uno o più testi. Il fatto è che se ci sono per dire più di due immagini, solo l'ultimo "oggetto" per tipo viene messo... per dire, se ci sono due scritte e tre immagini, verranno impresse soltanto la seconda scritta e la terza immagine sull'immagine "originale" di background.
Per questo ho cercato di salvare ad ogni step l'immagine su di un file temporaneo e quindi di riutilizzarlo come background, ma evidentemente c'è qualcosa che non va, perché il risultato è immutato... potreste essere così gentili da dirmi cosa sbaglio?
Grazie 
Codice PHP:
/***********************************/
// World of Warcraft Armory SDK //
// Userbars module //
// Licence: GNU GPLv3 //
// Author: Giacomo 'elegos' Furlan //
// File: index.php //
/***********************************/
require_once("wowasdk/wowasdk.include.php");
function createImageFrom($imageUrl) {
$info = getimagesize($imageUrl);
switch($info["mime"]) {
case "image/gif":
return @imagecreatefromgif($imageUrl);
case "image/jpeg":
return @imagecreatefromjpeg($imageUrl);
case "image/png":
return @imagecreatefrompng($imageUrl);
default:
die("Impossible to create the image ($imageUrl).");
break;
}
}
function saveImage($image,$mime,$name="") {
switch($mime) {
case "image/gif":
if($name == "") imagegif($image);
else imagegif($image,$name);
break;
case "image/jpeg":
if($name == "") imagejpeg($image);
else imagejpeg($image,$name);
break;
case "image/png":
if($name == "") imagepng($image);
else imagepng($image,$name);
break;
}
}
$get = explode("_",$_GET['d']);
$name = $get[0];
$region = $get[1];
$realm = $get[2];
$templ = $_GET['t'];
$i = 0;
do {
$time = (string) time()-$i;
$i++;
} while(file_exists($time));
$f = fopen($time,'w');
fputs($f,'\n');
fclose($f);
if($templ == "" || !file_exists("templates/".$templ)) die("Not a valid template");
switch($region) {
case "EU":
$region = EU;
break;
case "US":
$region = US;
break;
default:
die("No valid region selected. EU/US.");
}
require_once("templates/".$templ.".php");
if(!function_exists("template")) die("Function template() doesn't exist.");
$template = template($name, $region, $realm);
$background = "templates/".$templ."/".$template["vars"]["background"];
$infoBase = getimagesize($background);
$image = createImageFrom($background);
foreach($template["vars"] as $type => $data) {
saveImage($image,$infoBase["mime"],$time); // qui provo a salvare l'immagine...
imagedestroy($image);
$image = createImageFrom($time); // ... e quindi a ricaricarla
switch($type) {
case "image":
$inner_image = createImageFrom("templates/".$templ."/".$data["source"]);
if(!imagecopymerge($image,$inner_image,$data['x'],$data['y'],0,0,$data['width'],$data['height'],$data['opacity']))
die("Unable to apply an image!");
break;
case "text":
$color = imagecolorallocate($image,$data["color"]["red"],$data["color"]["green"],$data["color"]["blue"]);
imagettftext($image,$data["size"],0,$data["x"],$data["y"],$color,"templates/".$templ."/".$data["font"],html_entity_decode($data["content"]));
break;
}
}
// image creation
header("Content type: ".$infoBase["mime"]);
saveImage($image,$infoBase["mime"]);
imagedestroy($image);
// delete temp image
if(file_exists($time)) unlink($time);