Visualizzazione risultati 1 fino 7 di 7

Discussione: Inserire simbolo grado in immagine GD

  1. #1
    L'avatar di miki92
    miki92 non è connesso AlterGuru 2500
    Data registrazione
    21-04-2007
    Residenza
    Procida (NA)
    Messaggi
    4,226

    Predefinito Inserire simbolo grado in immagine GD

    Buongiorno.
    Sto utilizzando la funzione imagettftext per scrivere del testo con GD su un'immagine ma quando devo inserire il simbolo del grado mi compare un quadrato e non mi mostra il simbolo.

    Ho provato anche con htmlentities e html_entity_decode ma nulla.

    Qualche consiglio?
    Apprezzi l'aiuto? Offrimi un caffè!

  2. #2
    mzanella non è connesso AlterGuru
    Data registrazione
    29-12-2015
    Messaggi
    1,954

    Predefinito

    È possibile che il font che cerchi di utilizzare non supporti quel carattere? La documentazione riporta:
    If a character is used in the string which is not supported by the font, a hollow rectangle will replace the character.
    In questo caso l'unica alternativa temo sia utilizzare un font diverso o ricorrere ad espedienti come disegnare "a mano" il simbolo.

  3. #3
    L'avatar di miki92
    miki92 non è connesso AlterGuru 2500
    Data registrazione
    21-04-2007
    Residenza
    Procida (NA)
    Messaggi
    4,226

    Predefinito

    Il carattere lo supporta il simbolo del grado perchè in photoshop l'ho inserito.
    Apprezzi l'aiuto? Offrimi un caffè!

  4. #4
    mzanella non è connesso AlterGuru
    Data registrazione
    29-12-2015
    Messaggi
    1,954

    Predefinito

    Mh, ho provato con questo codice nel mio spazio e sembra funzionare (esempio):
    Codice PHP:
    <?php
    // Set the content-type
    header('Content-Type: image/png');

    // Create the image
    $im = imagecreatetruecolor(450, 35);
    $white = imagecolorallocate($im, 255, 255, 255);
    $black = imagecolorallocate($im, 0, 0, 0);
    imagefilledrectangle($im, 0, 0, 450, 35, $white);

    // Text and font
    $text = 'Testing... ° à#';
    $font = './Pacifico.ttf';

    // Write it!
    imagettftext($im, 20, 0, 10, 25, $black, $font, $text);

    imagepng($im);
    imagedestroy($im);
    ?>
    quindi inserire il simbolo direttamente nel sorgente è sufficiente, a patto che questo abbia codifica UTF-8. Se vuoi provare a tua volta, il font è Pacifico.ttf.

    Anche se il fatto che su Photoshop vada e con imagettftext no suggerisce il contrario, continuo a credere che dipenda dal font. Puoi indicarne il nome o fornirne un link?

  5. #5
    L'avatar di miki92
    miki92 non è connesso AlterGuru 2500
    Data registrazione
    21-04-2007
    Residenza
    Procida (NA)
    Messaggi
    4,226

    Predefinito

    A me continua a non essere visualizzato anche con la tua font:

    Codice PHP:
    imagettftext($bg, 20, 0, 210, 170, $blu, "res/font/pacifico.ttf", html_entity_decode('&deg;'));
    Apprezzi l'aiuto? Offrimi un caffè!

  6. #6
    mzanella non è connesso AlterGuru
    Data registrazione
    29-12-2015
    Messaggi
    1,954

    Predefinito

    Se con lo stesso font e lo stesso codice il risultato è diverso, può dipendere dalla versione di PHP GD.
    Nel mio spazio ho la versione 2.1.0. La versione di FreeType 2.4.11.

    Se il motivo non è nemmeno questo, temo di aver esaurito le idee .

  7. #7
    darbula non è connesso AlterGuru 2500
    Data registrazione
    24-04-2011
    Messaggi
    2,894

    Predefinito

    Per ottenere un UTF-8 valido in php si deve considerare sorgente (html,php,javascript,text),header(html,php,javasci pt,text) e nonchè le funzioni php che operano con le stringhe.. image.php
    Codice PHP:
    <?php
    // Set the content-type
    header('Content-Type: image/png');

    // Create the image
    $im = imagecreatetruecolor(400, 30);

    // Create some colors
    $white = imagecolorallocate($im, 255, 255, 255);
    $grey = imagecolorallocate($im, 128, 128, 128);
    $black = imagecolorallocate($im, 0, 0, 0);
    imagefilledrectangle($im, 0, 0, 399, 29, $white);

    // The text to draw
    $text = 'Testing...1&deg;';
    // Replace path by your own font path
    $font = './Pacifico.ttf';

    // Add some shadow to the text
    // html_entity_decode() for < php 5.6
    imagettftext($im, 20, 0, 11, 21, $grey, $font, html_entity_decode($text, ENT_COMPAT, 'UTF-8').html_entity_decode($text));

    // Add the text
    // html_entity_decode() for < php 5.6
    imagettftext($im, 20, 0, 10, 20, $black, $font, html_entity_decode($text, ENT_COMPAT, 'UTF-8').html_entity_decode($text));

    // Using imagepng() results in clearer text compared with imagejpeg()
    imagepng($im);
    imagedestroy($im);
    ?>
    script.php
    Codice PHP:
    <?php
    header
    ('Content-type: text/html; charset=utf-8');
    $word = 'ciao 1&deg;';
    $text =
    html_entity_decode($word, ENT_COMPAT, 'UTF-8');
    $text .= html_entity_decode($word);
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    </head>
    <body>
    <p>Ecco la mia prima pagina in html destinata al web <?php print_r($text); ?></p>
    <img src="image.php">
    </body>
    </html>
    http://www.fonts2u.com/pacifico-regular.font
    Nel caso dei font (tipo di carattere) si deve considerare anche il sistema operativo in uso... cmq. a me il simbolo grado decodificato da un'entita html si vede (ISO-8859-1 o UTF-8).
    Tre esempi di esadecimali per il simbolo grado.
    Codice:
    unicode 2.0  00B0
    utf-8        C2B0
    iso-8859-1   B0
    Ultima modifica di darbula : 22-09-2016 alle ore 22.01.20

Regole di scrittura

  • Non puoi creare nuove discussioni
  • Non puoi rispondere ai messaggi
  • Non puoi inserire allegati.
  • Non puoi modificare i tuoi messaggi
  •