How to turn a text string into an image

Ceci est une ARCHIVE, peut-être périmée. Vérifiez bien les compatibilités !

Offers writers to change the font of some parts of their text.

A model, as spip means it, designed to transform a text string into an image is one of the many features we needed to release our template EVA 3 last september. It has been designed and developped thanks to the helpfull people on spip IRC chanel. As a Spip global feature, this is not specifically linked to our templates and that’s why we feel free to explain it here, out of it’s initial context.

Warning ! After a little more than three years of good and faithful service and almost 30000 visits this tutorial retires. Long life to its substitute

What is the purpose ?

Sometimes a writer may need to use a different font for one part of his text and in the meantime he doesn’t want this change to occur on all or on any other texts.

For the needs of EVA 3 we had to find a way to use hand writting fonts for such partial texts.

What is the problem ?

A Spip feature aldready allows to turn a single text string into an image, wich easily increases creativity. It’s the typographical image filter.

[(#TITRE|image_typo)] turns a text string into an image .

[(#TITRE|image_typo{police=my_font.ttf})] turns a text string into an image using the specified font.

This is exactely what we need ; although it can’t work with #TEXT unless we want to turn all the text into an image .

Here is the solution

It comes from spip’s models. As a matter of fact spip comes with the features we need.

<imagetypo|texte=my partial text>

This code lets us change font in a partial text, actually returning an image img of the writtings, and that’s exactly what we need.

Setting up

Since we only need a part of text to be processed by imagetypo we are going to let spip do the work elsewhere _that will be a task for ecriture.html_ and then return the final img.

Let’s begin by specifying exactly what we want. If we mean to change only the first sentence of a text, then we need to write the following code in our body text :

<ecriture1|texte=My first sentence|police=my_font.ttf|left>

[(#ENV{texte}|image_typo{police=#ENV**{police}})]

Technically speaking

You will need to place the file ecriture.html in the /modeles directory of your templates folder : /modeles/ecriture.html

Then of course, make sure you’ll add the fonts you need in your template’s fonts directory [1] at the root of your site : /polices/my_font.ttf, or in the templates directory : /your_templates/polices/my_font.ttf

Make sure to create those directories if they do not already exist.

Notes

[1Warning : unless you protect the folder (with an htaccess for example), anyone will be able to download your font files. If you use commercial fonts, beware you do not inadvertently distribute them without any authorisation.

Discussion

Aucune discussion

Ajouter un commentaire

Avant de faire part d’un problème sur un plugin X, merci de lire ce qui suit :

  • Désactiver tous les plugins que vous ne voulez pas tester afin de vous assurer que le bug vient bien du plugin X. Cela vous évitera d’écrire sur le forum d’une contribution qui n’est finalement pas en cause.
  • Cherchez et notez les numéros de version de tout ce qui est en place au moment du test :
    • version de SPIP, en bas de la partie privée
    • version du plugin testé et des éventuels plugins nécessités
    • version de PHP (exec=info en partie privée)
    • version de MySQL / SQLite
  • Si votre problème concerne la partie publique de votre site, donnez une URL où le bug est visible, pour que les gens puissent voir par eux-mêmes.
  • En cas de page blanche, merci d’activer l’affichage des erreurs, et d’indiquer ensuite l’erreur qui apparaît.

Merci d’avance pour les personnes qui vous aideront !

Par ailleurs, n’oubliez pas que les contributeurs et contributrices ont une vie en dehors de SPIP.

Qui êtes-vous ?
[Se connecter]

Pour afficher votre trombine avec votre message, enregistrez-la d’abord sur gravatar.com (gratuit et indolore) et n’oubliez pas d’indiquer votre adresse e-mail ici.

Ajoutez votre commentaire ici

Ce champ accepte les raccourcis SPIP {{gras}} {italique} -*liste [texte->url] <quote> <code> et le code HTML <q> <del> <ins>. Pour créer des paragraphes, laissez simplement des lignes vides.

Ajouter un document

Suivre les commentaires : RSS 2.0 | Atom