- Home
- Categorie
- Coding e Sistemistica
- PHP
- scipt per generare banner
-
scipt per generare banner
ho un problema con uno script modello banner maker trovato in rete, il problema consiste nel file generato che viene fuoti come un bitmap mentre sarebbe molto meglio avere una png o una gif
questo è il file banner.php che raccoglie gli imput dell'index
[PHP]<?php
header("Content-Type: image/gif");
$fontpath = "fonts/";
$titlefont = "$fontpath/$titlef";
$tagfont = "$fontpath/$tagf";
if ((isset($titletext) || $titletext > "")
and (isset($tagtext) || $tagtext > "")) {
$titlecolor = substr($titlecolor, -6);
$r1 = hexdec(substr($titlecolor, 0, 2));
$g1 = hexdec(substr($titlecolor, 2, 2));
$b1 = hexdec(substr($titlecolor, 4, 2));
$tagcolor = substr($tagcolor, -6);
$r2 = hexdec(substr($tagcolor, 0, 2));
$g2 = hexdec(substr($tagcolor, 2, 2));
$b2 = hexdec(substr($tagcolor, 4, 2));
$titletext2 = stripslashes($titletext);
$tagtext2 = stripslashes($tagtext);
$image = imagecreatefrompng("banner/$select_banner");
$titlecolor = imagecolorallocate($image, $r1, $g1, $b1);
$tagcolor = imagecolorallocate($image, $r2, $g2, $b2);
$shadow = imagecolorallocate($image, 153, 153, 153);
if ($titleshadow == "yes"){
ImageTTFText($image, $titlesize, 0, $titlex+1, $titley+1, $shadow, $titlefont, $titletext2);
}
if ($tagshadow == "yes"){
ImageTTFText($image, $tagsize, 0, $tagx+1, $tagy+1, $shadow, $tagfont, $tagtext2);
}
ImageTTFText($image, $titlesize, 0, $titlex, $titley, $titlecolor, $titlefont, $titletext2);
ImageTTFText($image, $tagsize, 0, $tagx, $tagy, $tagcolor, $tagfont, $tagtext2);
ImageGIF($image);
}
$fp = fopen("gencount.txt","r+");
$gen = fread ($fp,7);
$gen++;
rewind($fp);
fputs($fp, $gen, 7);
fclose($fp);
?>
[/PHP]qualcuno sa dove mettere le mani ?
-
Che errore ti dà?
-
dicevo che il file generato su IE è un bitmap senza nome, mentre con firefox andrebbe quasi bene visto che genera un file banner.php.gif
ho provato a fare queste modifiche
aggiungo la variabile nuovo banner all'inizio
[PHP] $newbanner = 'banners/' . tuobanner . '.gif';
[/PHP]la stessa l'aggiungo sulla funzione ImageGIF
[PHP]ImageGIF($image, $newbanner);[/PHP]
e aggiungo il seguente echo
[PHP]echo "<img src="$newbanner" width="468" height="60" alt="Your Generated Banner" border="0">\n";
echo "\n\n";[/PHP]il codice diventa così
[PHP]<?php
header("Content-Type: image/gif");
$fontpath = "fonts/";
$titlefont = "$fontpath/$titlef";
$tagfont = "$fontpath/$tagf";
$newbanner = 'banners/' . tuobanner . '.gif';
if ((isset($titletext) || $titletext > "")
and (isset($tagtext) || $tagtext > "")) {
$titlecolor = substr($titlecolor, -6);
$r1 = hexdec(substr($titlecolor, 0, 2));
$g1 = hexdec(substr($titlecolor, 2, 2));
$b1 = hexdec(substr($titlecolor, 4, 2));
$tagcolor = substr($tagcolor, -6);
$r2 = hexdec(substr($tagcolor, 0, 2));
$g2 = hexdec(substr($tagcolor, 2, 2));
$b2 = hexdec(substr($tagcolor, 4, 2));
$titletext2 = stripslashes($titletext);
$tagtext2 = stripslashes($tagtext);
$image = imagecreatefrompng("banner/$select_banner");
$titlecolor = imagecolorallocate($image, $r1, $g1, $b1);
$tagcolor = imagecolorallocate($image, $r2, $g2, $b2);
$shadow = imagecolorallocate($image, 153, 153, 153);
if ($titleshadow == "yes"){
ImageTTFText($image, $titlesize, 0, $titlex+1, $titley+1, $shadow, $titlefont, $titletext2);
}
if ($tagshadow == "yes"){
ImageTTFText($image, $tagsize, 0, $tagx+1, $tagy+1, $shadow, $tagfont, $tagtext2);
}
ImageTTFText($image, $titlesize, 0, $titlex, $titley, $titlecolor, $titlefont, $titletext2);
ImageTTFText($image, $tagsize, 0, $tagx, $tagy, $tagcolor, $tagfont, $tagtext2);
ImageGIF($image, $newbanner);
}
echo "<img src="$newbanner" width="468" height="60" alt="Your Generated Banner" border="0">\n";
$fp = fopen("gencount.txt","r+");
$gen = fread ($fp,7);
$gen++;
rewind($fp);
fputs($fp, $gen, 7);
fclose($fp);
?>[/PHP]adesso con IE funziona perfettamente, il file generato ha l'estensione .gif mentre firefox mi dice ciò
l'immagine "miourl/bannermaker/banner.php non può essere visualizzata perchè la pagina contiene degli errori
-
Fia tasto destro visulizza sorgente sull'immagine con firefox in mezzo ai simboli vedi gli errori, e puoi correggerli
-
interessante, non sapevo che firefox mostrasse gli errori sulla sorgente della pagina.
purtroppo il server elabora il codice php e restituisce al client un puro e semplice html.
edit : ho risolto, firefox è molto pignolo :p... eliminato
[PHP]header("Content-Type: image/gif");[/PHP]funziona perfettamente, ora con photoshop qualche sfondo carino e poi online