Vai al contenuto

[GUIDA]Creare un'immagine countdown in PHP


Messaggi raccomandati

Ciao a tutti, visto che ad alcuni di voi interessa, ho deciso di creare questa guida che vi permetterà  di creare la vostra personalissima immagini countdown col linguaggio PHP...

 

Occorrente:

Uno sfondo in formato .png di qualsiasi dimensione.

Un editor di testo (il blocco note va bene, ma è meglio Notepad++ (Googleate!)

 

Bene, prima di tutto creiamo un nuovo file di testo e salviamolo in estensione PHP (con Np++ sarà  tutto molto più semplice, vi raccomando però di non salvarlo come SCRIPT.php.txt, ma come SCRIPT.php - fate attenzione!).

Iniziamo lo script come inizia un qualsiasi script PHP:

<span class="syntaxdefault"></span><span class="syntaxkeyword"><?</span><span class="syntaxdefault">php</span>[/code:1xzr8oh7]

Bene, lo script è iniziato, ora inseriamo un paio di funzioni che ci serviranno più tardi. La funzione imageoutlinedstring() che ho assemblato io ci permetterà  di creare un testo circondato da una linea esterna che renderà  l'effetto migliore, aggiungiamola e lo script diventerà  così:

[code=PHP:1xzr8oh7]<span class="syntaxdefault">

</span><span class="syntaxkeyword"><?</span><span class="syntaxdefault">php

function imageoutlinedstring</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$image</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$font</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$x</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$y</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$string</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$incolor</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$outcolor</span><span class="syntaxkeyword">){

</span><span class="syntaxdefault">    imagestring</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$image</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$font</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$x</span><span class="syntaxkeyword">-</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$y</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$string</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$outcolor</span><span class="syntaxkeyword">);

</span><span class="syntaxdefault">    imagestring</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$image</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$font</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$x</span><span class="syntaxkeyword">+</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$y</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$string</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$outcolor</span><span class="syntaxkeyword">);

</span><span class="syntaxdefault">    imagestring</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$image</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$font</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$x</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$y</span><span class="syntaxkeyword">-</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$string</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$outcolor</span><span class="syntaxkeyword">);

</span><span class="syntaxdefault">    imagestring</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$image</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$font</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$x</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$y</span><span class="syntaxkeyword">+</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$string</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$outcolor</span><span class="syntaxkeyword">);

</span><span class="syntaxdefault">    imagestring</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$image</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$font</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$x</span><span class="syntaxkeyword">-</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$y</span><span class="syntaxkeyword">-</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$string</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$outcolor</span><span class="syntaxkeyword">);

</span><span class="syntaxdefault">    imagestring</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$image</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$font</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$x</span><span class="syntaxkeyword">+</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$y</span><span class="syntaxkeyword">-</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$string</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$outcolor</span><span class="syntaxkeyword">);

</span><span class="syntaxdefault">    imagestring</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$image</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$font</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$x</span><span class="syntaxkeyword">-</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$y</span><span class="syntaxkeyword">+</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$string</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$outcolor</span><span class="syntaxkeyword">);

</span><span class="syntaxdefault">    imagestring</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$image</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$font</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$x</span><span class="syntaxkeyword">+</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$y</span><span class="syntaxkeyword">+</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$string</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$outcolor</span><span class="syntaxkeyword">);

</span><span class="syntaxdefault">    imagestring</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$image</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$font</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$x</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$y</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$string</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$incolor</span><span class="syntaxkeyword">);

}</span><span class="syntaxdefault"> </span>[/code:1xzr8oh7]

Ora ci serve una funzione per calcolare i giorni mancanti, per la quale vi serve sapere esattamente QUANTI GIORNI dall'inizio dell'anno ci sono prima dell'evento attesto. A questo punto base usare la funzione date("z"); per ottenere i giorni passati dall'inizio dell'anno e ottenere quelli mancanti con una semplice differenza.

[code=PHP:1xzr8oh7]<span class="syntaxdefault">

</span><span class="syntaxkeyword"><?</span><span class="syntaxdefault">php

function imageoutlinedstring</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$image</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$font</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$x</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$y</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$string</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$incolor</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$outcolor</span><span class="syntaxkeyword">){

</span><span class="syntaxdefault">    imagestring</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$image</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$font</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$x</span><span class="syntaxkeyword">-</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$y</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$string</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$outcolor</span><span class="syntaxkeyword">);

</span><span class="syntaxdefault">    imagestring</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$image</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$font</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$x</span><span class="syntaxkeyword">+</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$y</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$string</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$outcolor</span><span class="syntaxkeyword">);

</span><span class="syntaxdefault">    imagestring</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$image</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$font</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$x</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$y</span><span class="syntaxkeyword">-</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$string</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$outcolor</span><span class="syntaxkeyword">);

</span><span class="syntaxdefault">    imagestring</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$image</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$font</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$x</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$y</span><span class="syntaxkeyword">+</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$string</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$outcolor</span><span class="syntaxkeyword">);

</span><span class="syntaxdefault">    imagestring</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$image</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$font</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$x</span><span class="syntaxkeyword">-</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$y</span><span class="syntaxkeyword">-</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$string</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$outcolor</span><span class="syntaxkeyword">);

</span><span class="syntaxdefault">    imagestring</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$image</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$font</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$x</span><span class="syntaxkeyword">+</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$y</span><span class="syntaxkeyword">-</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$string</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$outcolor</span><span class="syntaxkeyword">);

</span><span class="syntaxdefault">    imagestring</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$image</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$font</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$x</span><span class="syntaxkeyword">-</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$y</span><span class="syntaxkeyword">+</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$string</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$outcolor</span><span class="syntaxkeyword">);

</span><span class="syntaxdefault">    imagestring</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$image</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$font</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$x</span><span class="syntaxkeyword">+</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$y</span><span class="syntaxkeyword">+</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$string</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$outcolor</span><span class="syntaxkeyword">);

</span><span class="syntaxdefault">    imagestring</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$image</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$font</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$x</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$y</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$string</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$incolor</span><span class="syntaxkeyword">);

}

</span><span class="syntaxdefault">function calculatedays</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$dayone</span><span class="syntaxkeyword">){

</span><span class="syntaxdefault">    $today </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> date</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"z"</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">+</span><span class="syntaxdefault"> 1</span><span class="syntaxkeyword">;

</span><span class="syntaxdefault">    $rmn </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$dayone </span><span class="syntaxkeyword">-</span><span class="syntaxdefault"> $today</span><span class="syntaxkeyword">);

</span><span class="syntaxdefault">    return $rmn</span><span class="syntaxkeyword">;

}</span><span class="syntaxdefault"> </span>[/code:1xzr8oh7]

Fatto, tutte le funzioni personalizzate sono pronte. Ora iniziamo a "creare l'immagine".

In questa seconda parte di codice metterò dei commenti al codice di fianco alle righe per farvi capire meglio.

[code=PHP:1xzr8oh7]<span class="syntaxdefault">

$im </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> imagecreatefrompng</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"LAMIAIMMAGINE.png"</span><span class="syntaxkeyword">);</span><span class="syntaxdefault"> </span><span class="syntaxcomment">// mette l'immagine di sfondo in una variabile

</span><span class="syntaxdefault">$white </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> imagecolorallocate</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$im</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 255</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 255</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 255</span><span class="syntaxkeyword">);</span><span class="syntaxdefault"> </span><span class="syntaxcomment">// alloca nell'immagine il colore bianco, in modo che possa essere usato più tardi

</span><span class="syntaxdefault">$black </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> imagecolorallocate</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$im</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 0</span><span class="syntaxkeyword">);</span><span class="syntaxdefault"> </span><span class="syntaxcomment">// idem col colore nero

</span><span class="syntaxdefault">header</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Content-type: image/png"</span><span class="syntaxkeyword">);</span><span class="syntaxdefault"> </span><span class="syntaxcomment">// dichiara l'header della pagina, di modo che il browser sappia di cosa si tratta

</span><span class="syntaxdefault">imageoutlinedstring</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$im</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">FONT </span><span class="syntaxkeyword">(</span><span class="syntaxdefault">NUMERO A CASO DA 1 A 5</span><span class="syntaxkeyword">),</span><span class="syntaxdefault">COORDINATA X DEL TESTO QUI</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">COORDINATA Y DEL TESTO QUI</span><span class="syntaxkeyword">,</span><span class="syntaxstring">"-"</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">.</span><span class="syntaxdefault"> calculatedays</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">GIORNOATTESOINNUMERODALL</span><span class="syntaxstring">'INIZIODELL'</span><span class="syntaxdefault">ANNO</span><span class="syntaxkeyword">),</span><span class="syntaxdefault">$white</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$black</span><span class="syntaxkeyword">);</span><span class="syntaxdefault"> </span><span class="syntaxcomment">// scrive i giorni mancanti sull'immagine, qui dovete impostare le cose in maiuscolo. per la font consiglio 3, per x e y dipende dalla vostra immagine

</span><span class="syntaxdefault">imagepng</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$im</span><span class="syntaxkeyword">);</span><span class="syntaxdefault"> </span><span class="syntaxcomment">// finalmente, mostra l'immagine

</span><span class="syntaxdefault">imagedestroy</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$im</span><span class="syntaxkeyword">);</span><span class="syntaxdefault"> </span><span class="syntaxcomment">// distrugge l'immagine in modo da liberare la memoria

</span><span class="syntaxdefault"> </span>[/code:1xzr8oh7]

Ecco, il codice è completo, fatti i dovuti aggiustamenti (rileggetevelo e usate un po' di senso logico, ci arriverete).

[code=PHP:1xzr8oh7]<span class="syntaxhtml">

<span class="syntaxdefault"><?php

function imageoutlinedstring</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$image</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$font</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$x</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$y</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$string</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$incolor</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$outcolor</span><span class="syntaxkeyword">){

</span><span class="syntaxdefault">    imagestring</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$image</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$font</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$x</span><span class="syntaxkeyword">-</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$y</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$string</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$outcolor</span><span class="syntaxkeyword">);

</span><span class="syntaxdefault">    imagestring</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$image</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$font</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$x</span><span class="syntaxkeyword">+</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$y</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$string</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$outcolor</span><span class="syntaxkeyword">);

</span><span class="syntaxdefault">    imagestring</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$image</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$font</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$x</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$y</span><span class="syntaxkeyword">-</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$string</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$outcolor</span><span class="syntaxkeyword">);

</span><span class="syntaxdefault">    imagestring</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$image</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$font</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$x</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$y</span><span class="syntaxkeyword">+</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$string</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$outcolor</span><span class="syntaxkeyword">);

</span><span class="syntaxdefault">    imagestring</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$image</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$font</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$x</span><span class="syntaxkeyword">-</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$y</span><span class="syntaxkeyword">-</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$string</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$outcolor</span><span class="syntaxkeyword">);

</span><span class="syntaxdefault">    imagestring</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$image</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$font</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$x</span><span class="syntaxkeyword">+</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$y</span><span class="syntaxkeyword">-</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$string</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$outcolor</span><span class="syntaxkeyword">);

</span><span class="syntaxdefault">    imagestring</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$image</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$font</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$x</span><span class="syntaxkeyword">-</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$y</span><span class="syntaxkeyword">+</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$string</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$outcolor</span><span class="syntaxkeyword">);

</span><span class="syntaxdefault">    imagestring</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$image</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$font</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$x</span><span class="syntaxkeyword">+</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$y</span><span class="syntaxkeyword">+</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$string</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$outcolor</span><span class="syntaxkeyword">);

</span><span class="syntaxdefault">    imagestring</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$image</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$font</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$x</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$y</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$string</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$incolor</span><span class="syntaxkeyword">);

}

</span><span class="syntaxdefault">function calculatedays</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$dayone</span><span class="syntaxkeyword">){

</span><span class="syntaxdefault">    $today </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> date</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"z"</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">+</span><span class="syntaxdefault"> 1</span><span class="syntaxkeyword">;

</span><span class="syntaxdefault">    $rmn </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$dayone </span><span class="syntaxkeyword">-</span><span class="syntaxdefault"> $today</span><span class="syntaxkeyword">);

</span><span class="syntaxdefault">    return $rmn</span><span class="syntaxkeyword">;

}

</span><span class="syntaxdefault">$im </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> imagecreatefrompng</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"LAMIAIMMAGINE.png"</span><span class="syntaxkeyword">);</span><span class="syntaxdefault"> </span><span class="syntaxcomment">// mette l'immagine di sfondo in una variabile

</span><span class="syntaxdefault">$white </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> imagecolorallocate</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$im</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 255</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 255</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 255</span><span class="syntaxkeyword">);</span><span class="syntaxdefault"> </span><span class="syntaxcomment">// alloca nell'immagine il colore bianco, in modo che possa essere usato più tardi

</span><span class="syntaxdefault">$black </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> imagecolorallocate</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$im</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 0</span><span class="syntaxkeyword">);</span><span class="syntaxdefault"> </span><span class="syntaxcomment">// idem col colore nero

</span><span class="syntaxdefault">header</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Content-type: image/png"</span><span class="syntaxkeyword">);</span><span class="syntaxdefault"> </span><span class="syntaxcomment">// dichiara l'header della pagina, di modo che il browser sappia di cosa si tratta

</span><span class="syntaxdefault">imageoutlinedstring</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$im</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">FONT </span><span class="syntaxkeyword">(</span><span class="syntaxdefault">NUMERO A CASO DA 1 A 5</span><span class="syntaxkeyword">),</span><span class="syntaxdefault">COORDINATA X DEL TESTO QUI</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">COORDINATA Y DEL TESTO QUI</span><span class="syntaxkeyword">,</span><span class="syntaxstring">"-"</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">.</span><span class="syntaxdefault"> calculatedays</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">GIORNOATTESOINNUMERODALL</span><span class="syntaxstring">'INIZIODELL'</span><span class="syntaxdefault">ANNO</span><span class="syntaxkeyword">),</span><span class="syntaxdefault">$white</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$black</span><span class="syntaxkeyword">);</span><span class="syntaxdefault"> </span><span class="syntaxcomment">// scrive i giorni mancanti sull'immagine, qui dovete impostare le cose in maiuscolo. per la font consiglio 3, per x e y dipende dalla vostra immagine

</span><span class="syntaxdefault">imagepng</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$im</span><span class="syntaxkeyword">);</span><span class="syntaxdefault"> </span><span class="syntaxcomment">// finalmente, mostra l'immagine

</span><span class="syntaxdefault">imagedestroy</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$im</span><span class="syntaxkeyword">);</span><span class="syntaxdefault"> </span><span class="syntaxcomment">// distrugge l'immagine in modo da liberare la memoria

</span><span class="syntaxdefault">?></span></span>[/code:1xzr8oh7]

 

Il codice completo è qui sopra. Se vi servono chiarimenti chiedete pure.

Link al commento
Condividi su altri siti

jack mi puoi controllare il codice ?

<?php
function imageoutlinedstring($image,$font,$x,$y,$string,$incolor,$outcolor){
   imagestring($image,$font,$x-1,$y,$string,$outcolor);
   imagestring($image,$font,$x+1,$y,$string,$outcolor);
   imagestring($image,$font,$x,$y-1,$string,$outcolor);
   imagestring($image,$font,$x,$y+1,$string,$outcolor);
   imagestring($image,$font,$x-1,$y-1,$string,$outcolor);
   imagestring($image,$font,$x+1,$y-1,$string,$outcolor);
   imagestring($image,$font,$x-1,$y+1,$string,$outcolor);
   imagestring($image,$font,$x+1,$y+1,$string,$outcolor);
   imagestring($image,$font,$x,$y,$string,$incolor);
}
function calculatedays($dayone){
   $today = date("z") + 1;
   $rmn = ($dayone - $today);
   return $rmn;
}
$im = imagecreatefrompng("contoallarovescia.png"); 
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);	\
header("Content-
type: image/png");
imageoutlinedstring($im,FONT (4) x5,y5,
,$black);
imagepng($im);
imagedestroy($im);
?>

naturalmente rep +

Link al commento
Condividi su altri siti

Si devi registrarti.

Comunque ho fatto una modifica alla fine dello script, guardaci.

I tag img non vanno su fb.

Il codice che hai postato non va bene, devi solo copiare lo script in fondo al post e cambiare le parti in maiuscolo. Quella del giorno dall'inizio dell'anno funziona come ad esempio il 15 marzo è 73 (31 + 28 + 15).

La rep+ comunque non la vedo... vabbe'

Link al commento
Condividi su altri siti

jack ho aggiustato il codice cosi è giusto?

<?php
function imageoutlinedstring($image,$font,$x,$y,$string,$incolor,$outcolor){
   imagestring($image,$font,$x-1,$y,$string,$outcolor);
   imagestring($image,$font,$x+1,$y,$string,$outcolor);
   imagestring($image,$font,$x,$y-1,$string,$outcolor);
   imagestring($image,$font,$x,$y+1,$string,$outcolor);
   imagestring($image,$font,$x-1,$y-1,$string,$outcolor);
   imagestring($image,$font,$x+1,$y-1,$string,$outcolor);
   imagestring($image,$font,$x-1,$y+1,$string,$outcolor);
   imagestring($image,$font,$x+1,$y+1,$string,$outcolor);
   imagestring($image,$font,$x,$y,$string,$incolor);
}
function calculatedays($dayone){
   $today = date("z") + 1;
   $rmn = ($dayone - $today);
   return $rmn;
}
$im = imagecreatefrompng("contoallarovescia.png"); 
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);	\
header("Content-
type: image/png");
imageoutlinedstring($im,FONT (5),x5,y5,
"-
" . calculatedays(109),$white,$black);
imagepng($im);
imagedestroy($im);
?>

quando lo osto su altervista devo hostare lo script e anche l'immagine o solo l'immagine? :3

Link al commento
Condividi su altri siti

<?php
function imageoutlinedstring($image,$font,$x,$y,$string,$incolor,$outcolor){
   imagestring($image,$font,$x-1,$y,$string,$outcolor);
   imagestring($image,$font,$x+1,$y,$string,$outcolor);
   imagestring($image,$font,$x,$y-1,$string,$outcolor);
   imagestring($image,$font,$x,$y+1,$string,$outcolor);
   imagestring($image,$font,$x-1,$y-1,$string,$outcolor);
   imagestring($image,$font,$x+1,$y-1,$string,$outcolor);
   imagestring($image,$font,$x-1,$y+1,$string,$outcolor);
   imagestring($image,$font,$x+1,$y+1,$string,$outcolor);
   imagestring($image,$font,$x,$y,$string,$incolor);
}
function calculatedays($dayone){
   $today = date("z");
   $rmn = ($dayone - $today - 1);
   if ($rmn > 0) {
       return $rmn;
  } else {
  return "";
  }
}
$im = imagecreatefrompng("contoallarovescia.png");
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
header("Content-type: image/png");
imageoutlinedstring($im,5,5,5,calculatedays(109),$white,$black);
imagepng($im);
imagedestroy($im);
?>

Ho corretto lo script. Il modo per vederlo in anteprima sarebbe troppo incasinato ad ogni modo.

Link al commento
Condividi su altri siti

  • 1 mese dopo...
  • 2 anni dopo...

Crea un account o accedi per lasciare un commento

Devi essere un membro per lasciare un commento

Crea un account

Iscriviti per un nuovo account nella nostra community. È facile!

Registra un nuovo account

Accedi

Sei già registrato? Accedi qui.

Accedi Ora

Giochi in Uscita



×
×
  • Crea Nuovo...