Dessiner des images avec du codeDrawing images with code
Les badges partageables de djplays sont dessinés par le serveur avec GD, pas exportés d'un outil de design. Trois formats, du texte vectoriel, des polices embarquées, et un cache — parce qu'un badge doit rester juste quand les chiffres changent.The djplays shareable badges are drawn by the server with GD, not exported from a design tool. Three formats, vector text, embedded fonts, and a cache — because a badge has to stay true when the numbers change.
Quand un passage est prouvé, le producteur reçoit une page publique sous un jeton, en /b/, où chaque passage est cliquable et vérifiable : le canal, la date et l’heure, l’audience, la vérification par l’équipe sous 48 heures. Et il reçoit des images à partager, parce qu’une preuve qui ne sort pas de sa page ne sert qu’à moitié.When a play is proven, the producer gets a public page under a token, at /b/, where every play is clickable and verifiable: the channel, the date and time, the audience, verification by the team within 48 hours. And he gets images to share, because proof that never leaves its own page is only half useful.
Ces images ne sortent pas d’un outil de design. Elles sont dessinées par le serveur, en PHP, avec GD. Ce n’est pas un choix esthétique et ce n’est pas de la coquetterie technique : c’est la conséquence de ce qu’un badge doit faire.Those images do not come out of a design tool. They are drawn by the server, in PHP, with GD. That is not an aesthetic choice and it is not technical vanity: it follows from what a badge has to do.
Pourquoi un badge ne peut pas être une image fabriquée une foisWhy a badge cannot be an image made once
Un badge affirme quelque chose qui bouge. Un nouveau passage arrive, et il ne dit plus la même chose. Une image exportée une fois est juste le jour de l’export et fausse ensuite, sans prévenir personne : le fichier ne s’abîme pas, il se contente de rester en arrière.A badge asserts something that moves. A new play comes in, and it no longer says the same thing. An image exported once is correct on the day of export and wrong afterwards, without warning anyone: the file does not decay, it simply stays behind.
Le widget rend cette exigence évidente. C’est une image, un iframe ou un PNG qu’on colle sur un site, un Linktree ou un presskit, et il se met à jour tout seul à chaque nouveau passage. Celui qui l’a collé ne reviendra pas le remplacer. Ce qui veut dire que l’image affichée doit être produite à partir des données au moment où elle est demandée, et pas avant.The widget makes that requirement obvious. It is an image, an iframe or a PNG pasted onto a site, a Linktree or a presskit, and it updates itself at every new play. Whoever pasted it will not come back to replace it. Which means the image displayed has to be produced from the data at the moment it is requested, and not before.
Il y a un second chiffre qui bouge : la note sur cinq étoiles que le DJ donne avec sa réponse. À partir de 4 étoiles, le badge Validé par djplays apparaît. Une image qui porterait cette mention sans qu’elle soit méritée serait un faux ; une image qui ne la porte pas alors qu’elle est méritée prive le producteur de ce qu’il a obtenu. Dans les deux cas, le fichier figé est le problème.There is a second moving figure: the rating out of five stars the DJ gives with his reply. From 4 stars upward, the Validé par djplays badge appears. An image carrying that mention without having earned it would be a forgery; an image not carrying it when it has been earned deprives the producer of what he obtained. In both cases, the frozen file is the problem.
Trois formats, trois cadragesThree formats, three framings
- Story, 1080 par 1920 pixels.Story, 1080 by 1920 pixels.
- Carré, 1080 par 1080.Square, 1080 by 1080.
- Open Graph, 1200 par 630, pour l’aperçu d’un lien partagé.Open Graph, 1200 by 630, for the preview of a shared link.
Trois dessins, et non un seul redimensionné. Un format vertical et un format large ne demandent pas la même composition : ce qui tient sur deux lignes dans un carré en demande davantage dans un rectangle étroit, et un texte qu’on réduit pour le faire entrer devient illisible à la taille où il sera réellement regardé, c’est-à-dire petite. Redimensionner déplace le problème, il ne le règle pas.Three drawings, not one resized. A vertical format and a wide one do not call for the same composition: what fits on two lines in a square needs more in a narrow rectangle, and text shrunk to make it fit becomes unreadable at the size it will actually be looked at, which is small. Resizing moves the problem, it does not solve it.
À côté de ces trois formats, le producteur reçoit aussi le post du badge : un visuel au format 4:5 prêt pour Instagram, et une vidéo montée par le studio pour les Reels et TikTok. Ce sont des livrables de publication, d’une autre nature que les images produites à la demande, et je les cite surtout pour qu’on ne les confonde pas.Alongside those three formats, the producer also gets the badge post: a 4:5 visual ready for Instagram, and a video edited by the studio for Reels and TikTok. Those are publishing deliverables, of a different nature from the images produced on demand, and I mention them mainly so they are not confused with them.
Ce qui est difficile quand on compose une image en codeWhat is hard about composing an image in code
La première difficulté est qu’il faut mesurer le texte avant de le poser. Dans un outil de design, on voit : on attrape un bloc, on le déplace, l’oeil arbitre. En code, on donne des coordonnées à une ligne de base et on ne voit rien avant que l’image ne soit écrite. Chaque position est donc un nombre calculé, et le calcul passe forcément par une mesure du texte à sa taille finale, dans sa police, avant de décider où il commence.The first difficulty is that the text has to be measured before it is placed. In a design tool you can see: you grab a block, you move it, the eye decides. In code you give coordinates to a baseline and you see nothing until the image has been written. Every position is therefore a computed number, and the computation necessarily goes through measuring the text at its final size, in its font, before deciding where it starts.
La deuxième est le retour à la ligne, qui n’existe pas. Rien ne coupe un titre trop long à votre place. Il faut le découper soi-même, mot par mot, en mesurant au fil de l’eau pour savoir où la ligne déborde, puis décider ce qui arrive quand le texte ne tient toujours pas : réduire la taille, couper, ou accepter une ligne de plus et redescendre tout ce qui suit.The second is line wrapping, which does not exist. Nothing breaks an over-long title for you. You have to break it yourself, word by word, measuring as you go to find where the line overflows, then decide what happens when the text still does not fit: reduce the size, truncate, or accept one more line and push everything below it down.
La troisième est qu’il n’y a pas de mise en page. Pas de boîtes, pas de flux, pas de centrage qui se fait tout seul. En CSS, on déclare une relation — centré dans son conteneur, espacé de telle marge — et le navigateur la tient quand le contenu change. Avec GD, on écrit la coordonnée ; si le contenu change, c’est à soi d’avoir prévu que la coordonnée en dépendait.The third is that there is no layout. No boxes, no flow, no centring that happens by itself. In CSS you declare a relation — centred in its container, spaced by such a margin — and the browser keeps it when the content changes. With GD you write the coordinate; if the content changes, it is on you to have anticipated that the coordinate depended on it.
Un badge qui serait une image exportée serait juste le jour de l’export, et faux tous les jours suivants. C’est la seule raison pour laquelle il est dessiné par le serveur : pas pour le plaisir d’écrire le dessin, mais parce qu’une affirmation chiffrée ne supporte pas d’être mise en conserve.A badge that was an exported image would be correct on the day of the export, and wrong every day after. That is the only reason it is drawn by the server: not for the pleasure of writing the drawing, but because a statement made of numbers does not survive being tinned.
Le texte vectoriel et les polices qui voyagentVector text and fonts that travel
Le texte est posé en vectoriel, à partir du contour de la police, à la taille demandée. La différence avec un texte bitmap se voit sur un grand format : les lettres restent nettes sur une image de 1080 pixels de large comme de 1920 de haut, et on peut changer une taille sans rien refabriquer en amont.The text is laid down as vectors, from the font outline, at the size asked for. The difference from bitmap text shows on a large format: the letters stay crisp on an image 1080 pixels wide as on one 1920 high, and a size can be changed without remaking anything upstream.
Deux polices servent : Space Grotesk Bold et Inter Regular. Elles sont embarquées dans le projet, dans un dossier de polices à côté du code. C’est le point que je tiens le plus à expliquer, parce qu’il est contre-intuitif : on n’embarque pas une police pour faire joli, on l’embarque parce qu’on ne peut rien supposer du serveur.Two fonts are used: Space Grotesk Bold and Inter Regular. They are embedded in the project, in a fonts directory next to the code. This is the point I most want to explain, because it is counter-intuitive: you do not embed a font to make things pretty, you embed it because nothing can be assumed about the server.
Une police installée sur ma machine n’est pas une police disponible là où le code tourne, et le comportement par défaut n’est pas élégant : une police absente ne se remplace pas par une police approchante, elle fait échouer le dessin ou produit une image sans texte. En embarquant les fichiers, la police voyage avec le code, et le même code sort le même dessin partout.A font installed on my machine is not a font available where the code runs, and the default behaviour is not graceful: a missing font is not replaced by a near-enough one, it either fails the drawing or produces an image with no text. By embedding the files, the font travels with the code, and the same code produces the same drawing everywhere.
Ce que cela coûte est modeste et réel : des fichiers à transporter, une licence à vérifier avant de les transporter, et la discipline de ne pas en ajouter une troisième sans raison. En échange, le dessin ne dépend plus de l’état du serveur, ce qui est exactement ce qu’on demande à du code qui fabrique une image.What it costs is modest and real: files to carry around, a licence to check before carrying them, and the discipline not to add a third one without a reason. In exchange, the drawing no longer depends on the state of the server, which is exactly what is asked of code that manufactures an image.
Le cache, qui change l'économie du dessinThe cache, which changes the economics of drawing
Les images produites sont mises en cache dans le dossier de données du site. Sans cache, chaque partage, chaque aperçu de lien, chaque passage d’un robot redessinerait l’image. Et dessiner coûte : il faut ouvrir les polices, mesurer, composer, encoder le fichier. Ce n’est pas long une fois ; c’est une facture quand c’est mille fois pour un résultat identique.The images produced are cached in the site’s data directory. Without a cache, every share, every link preview, every crawler visit would redraw the image. And drawing has a cost: the fonts have to be opened, the text measured, the layers composed, the file encoded. It is not slow once; it is a bill when it is a thousand times for an identical result.
La bonne façon de voir un badge est donc celle-ci : ce n’est pas un fichier, c’est le résultat d’un calcul dont les données sont les entrées. Le cache garde ce résultat, et toute la question d’un cache tient dans une phrase : jusqu’à quand ce qui est gardé reste-t-il vrai ? Un nouveau passage change les entrées, donc l’image gardée ne vaut plus — et cette dépendance, il vaut mieux l’avoir en tête en écrivant le cache qu’en la découvrant plus tard.So the right way to see a badge is this: it is not a file, it is the result of a computation whose inputs are the data. The cache keeps that result, and the whole question of a cache fits in one sentence: how long does what is kept stay true? A new play changes the inputs, so the kept image no longer holds — and that dependency is better held in mind while writing the cache than discovered later.
Il y a aussi une raison plus prosaïque de ne pas empiler des images pour rien. Au relevé, le dossier de données du site pèse 112 Mo et les sauvegardes 52 Mo. Tout ce qu’on écrit dans ce dossier, on le sauvegarde ensuite, chaque nuit.There is also a more prosaic reason not to pile up images for nothing. At the time of the survey, the site’s data directory weighs 112 MB and the backups 52 MB. Everything written into that directory then gets backed up, every night.
Le widget, la version qui vit chez les autresThe widget, the version that lives on other people's pages
Le widget est la même machinerie poussée d’un cran. Trois façons de l’intégrer — une image, un iframe, un PNG — parce que les endroits où on le colle n’acceptent pas la même chose : certains prennent n’importe quel code, d’autres seulement une adresse d’image, d’autres encore seulement un fichier qu’on dépose.The widget is the same machinery pushed one notch further. Three ways to embed it — an image, an iframe, a PNG — because the places it gets pasted into do not accept the same thing: some take any markup, others only an image address, others again only a file you upload.
L’intérêt pour le producteur est qu’il colle une fois. La vitrine qu’il met sur son presskit reste vraie sans qu’il y pense, parce qu’elle se met à jour toute seule au passage suivant. L’intérêt pour moi est qu’un contenu posé chez quelqu’un d’autre est précisément celui qu’on ne pourra jamais aller corriger : il n’a pas droit à l’erreur, donc il doit être calculé, pas exporté.The benefit for the producer is that he pastes it once. The showcase he puts on his presskit stays true without his thinking about it, because it updates itself at the next play. The benefit for me is that content placed on someone else’s page is precisely the content you will never be able to go and fix: it has no right to be wrong, so it has to be computed, not exported.
Ce qu'il faut que l'image dise justeWhat the image has to get right
Une image partagée est lue sans son contexte. Personne ne clique avant de se faire une idée. Tout ce qui est écrit dessus doit donc être exact sans la page qui l’entoure, ce qui est une contrainte bien plus forte que pour un texte de page : le lecteur d’une page peut vérifier en descendant, le spectateur d’une image ne vérifie pas.A shared image is read without its context. Nobody clicks before forming an opinion. So everything written on it has to be accurate without the surrounding page, which is a far stronger constraint than for text on a page: the reader of a page can check by scrolling down, the viewer of an image does not check.
D’où la règle des 4 étoiles, qui n’est pas un seuil arbitraire mais la condition d’une affirmation. Le badge Validé par djplays ne s’affiche qu’à partir de 4, et c’est le genre de condition qu’on veut voir dans le code qui dessine, pas seulement dans un document d’intention.Hence the 4-star rule, which is not an arbitrary threshold but the condition attached to a claim. The Validé par djplays badge only shows from 4 upward, and that is the kind of condition you want to see in the code that draws, not only in a statement of intent.
Le même dessin sert aussi de l’autre côté : chaque DJ reçoit un kit promo à son nom — une story, un post, une vidéo — avec ses styles et un QR code vers sa page. C’est la même mécanique, retournée vers l’autre moitié de la place de marché.The same drawing also serves the other side: every DJ gets a promo kit in his own name — a story, a post, a video — with his styles and a QR code to his page. It is the same machinery, turned towards the other half of the marketplace.
Au bilan, dessiner avec du code demande plus de travail le premier jour qu’exporter trois images, et beaucoup moins tous les jours suivants. GD vient avec PHP, donc il n’y a rien à installer et aucune dépendance de plus à suivre — le site n’en a aucune. Et la seule chose qu’il reste à faire pour qu’un badge soit juste, c’est que les données le soient.All told, drawing with code takes more work on the first day than exporting three images, and much less on every day after. GD ships with PHP, so there is nothing to install and no further dependency to track — the site has none at all. And the only thing left to do for a badge to be true is for the data to be true.
Le projet derrière cette noteThe project behind this note
Tout est parti de djplays, la place de marché. La fiche détaille le contexte, ce qui a été construit et ce que le client en a tiré.It all started with djplays, la place de marché. The project page covers the context, what was built and what the client got out of it.
À lire ensuiteRead next
Construire une identité qui ne ressemble à aucune autreBuilding an identity that looks like nobody else’s
Lire la noteRead the note 9 November 20269 November 2026L’animation doit être une option, pas une fatalitéMotion should be an option, not a given
Lire la noteRead the note 8 November 20268 November 2026Faire bouger une page sans la rendre illisibleAdding motion to a page without making it unreadable
Lire la noteRead the noteVoir les projets que j'ai réalisésSee the projects I have built · Comment je travailleHow I work · Ce qu'en disent mes clientsWhat my clients say