Ecrire des nombres dans une images, sans police

  Information

Fonction qui affiche des nombres en dessinant point par point les numéros.
Param :
$im : renvoyer par ImageCreate
$x, $y : coordonnées du text
$n : le nombre sous forme de texte
$color : la couleur renvoyé par ImageColorAllocate

Auteur : Jay More
  code source classé dans  Images - Graphisme

 
 01    
 02    
 03    
 04    
 05    
 06    
 07    
 08    
 09    
 10    
 11    
 12    
 13    
 14    
 15    
 16    
 17    
 18    
 19    
 20    
 21    
 22    
 23    
 24    
 25    
 26    
 27    
 28    
 29    
 30    
 31    
 32    
 33    
 34    
 35    
 36    
 37    
 38    
 39    
 40    
 41    
 42    
 43    
 44    
 45    
 46    
 47    
 48    
 49    
 50    
 51    
 52    
 53    
 54    
 55    
 56    
 57    
 58    
 59    
 60    
 61    
 62    
 63    
 64    
 65    
 66    
 67    
 68    
 69    
 70    
 71    
 72    
 73    
 74    
 75    
 76    
 77    
 78    
 79    
 80    
 81    
 82    
 83    
 84    
 85    
 86    
 87    
 88    
 89    
 90    
 91    
 92    
 93    
 94    
 95    
 96    
 97    
 98    
 99    
 100    
 101    
 102    
 103    
 104    
 105    
 106    
 107    
 108    
 109    
 110    
 111    
 112    
 113    
 114    
 115    
 116    
 117    
 118    
 119    
 120    
 121    
 122    
 123    
 124    
 125    
 126    
 127    
 128    
 129    
 130    
 131    
 132    
 133    
 134    
 135    
 136    
 137    
 138    
 139    
 140    
 141    
 142    
 143    
 144    
 145    
 146    
 147    
 148    
 149    
 150    
 151    
 152    
 153    
 154    
 155    
 156    
 157    
 158    
                               
/*---------------------------------------------------------------*/
/*
Titre : Ecrire des nombres dans une images, sans police

URL : https://phpsources.net/code_s.php?id=979
Date édition : 15 Fev 2019
*/
/*---------------------------------------------------------------*/

function WriteNumber($im , $x , $y , $n , $color){
global $RatioTextX;
global $RatioTextY;
$RatioTextX = 3; // hauteur des nombres
$RatioTextY = 3;

function Write0($im, $x, $y, $color)
{
global $RatioTextX;
global $RatioTextY;
imageline($im, $x, $y, $x+$RatioTextX, $y, $color);
imageline($im, $x+$RatioTextX, $y, $x+$RatioTextX, $y+(2*$RatioTextY), $color)
;
imageline($im, $x+$RatioTextX, $y+(2*$RatioTextY), $x, $y+(2*$RatioTextY),
$color);
imageline($im, $x, $y+(2*$RatioTextY), $x, $y, $color);
}

function Write1($im, $x, $y, $color)
{
global $RatioTextX;
global $RatioTextY;
imageline($im, $x+$RatioTextX, $y, $x+$RatioTextX, $y+(2*$RatioTextY), $color)
;
}

function Write2($im, $x, $y, $color)
{
global $RatioTextX;
global $RatioTextY;
imageline($im, $x, $y, $x+$RatioTextX, $y, $color);
imageline($im, $x+$RatioTextX, $y, $x+$RatioTextX, $y+$RatioTextY, $color);
imageline($im, $x+$RatioTextX, $y+$RatioTextY, $x, $y+$RatioTextY, $color);
imageline($im, $x, $y+$RatioTextY, $x, $y+(2*$RatioTextY), $color);
imageline($im, $x, $y+(2*$RatioTextY), $x+$RatioTextY, $y+(2*$RatioTextY),
$color);
}

function Write3($im, $x, $y, $color)
{
global $RatioTextX;
global $RatioTextY;
imageline($im, $x, $y, $x+$RatioTextX, $y, $color);
imageline($im, $x+$RatioTextX, $y, $x+$RatioTextX, $y+(2*$RatioTextY), $color)
;
imageline($im, $x+$RatioTextX, $y+(2*$RatioTextY), $x, $y+(2*$RatioTextY),
$color);
imageline($im, $x+$RatioTextX, $y+$RatioTextY, $x, $y+$RatioTextY, $color);
}

function Write4($im, $x, $y, $color)
{
global $RatioTextX;
global $RatioTextY;
imageline($im, $x, $y, $x, $y+$RatioTextY, $color);
imageline($im, $x, $y+$RatioTextY, $x+$RatioTextX, $y + $RatioTextY, $color);
imageline($im, $x+$RatioTextX, $y, $x+$RatioTextX, $y+(2*$RatioTextY), $color)
;
}

function Write5($im, $x, $y, $color)
{
global $RatioTextX;
global $RatioTextY;
imageline($im, $x+$RatioTextX, $y, $x, $y, $color);
imageline($im, $x, $y, $x, $y+$RatioTextY, $color);
imageline($im, $x, $y+$RatioTextY, $x+$RatioTextX, $y+$RatioTextY, $color);
imageline($im, $x+$RatioTextX, $y+$RatioTextY, $x+$RatioTextX, $y+(2*
$RatioTextY), $color);
imageline($im, $x+$RatioTextX, $y+(2*$RatioTextY), $x, $y+(2*$RatioTextY),
$color);
}

function Write6($im, $x, $y, $color)
{
global $RatioTextX;
global $RatioTextY;
imageline($im, $x+$RatioTextX, $y, $x, $y, $color);
imageline($im, $x, $y, $x, $y+(2*$RatioTextY), $color);
imageline($im, $x, $y+(2*$RatioTextY), $x+$RatioTextX, $y+(2*$RatioTextY),
$color);
imageline($im, $x+$RatioTextX, $y+(2*$RatioTextY), $x+$RatioTextX, $y+
$RatioTextY, $color);
imageline($im, $x+$RatioTextX, $y+$RatioTextY, $x, $y+$RatioTextY, $color);
}

function Write7($im, $x, $y, $color)
{
global $RatioTextX;
global $RatioTextY;
imageline($im, $x, $y, $x+$RatioTextX, $y, $color);
imageline($im, $x+$RatioTextX, $y, $x+$RatioTextX, $y+(2*$RatioTextY), $color)
;
}

function Write8($im, $x, $y, $color)
{
global $RatioTextX;
global $RatioTextY;
imageline($im, $x, $y, $x+$RatioTextX, $y, $color);
imageline($im, $x+$RatioTextX, $y, $x+$RatioTextX, $y+(2*$RatioTextY), $color)
;
imageline($im, $x+$RatioTextX, $y+(2*$RatioTextY), $x, $y+(2*$RatioTextY),
$color);
imageline($im, $x, $y+(2*$RatioTextY), $x, $y, $color);
imageline($im, $x, $y+$RatioTextY, $x+$RatioTextY, $y+$RatioTextY, $color);
}

function Write9($im, $x, $y, $color)
{
global $RatioTextX;
global $RatioTextY;
imageline($im, $x+$RatioTextX, $y+$RatioTextY, $x, $y+$RatioTextY, $color);
imageline($im, $x, $y+$RatioTextY, $x, $y, $color);
imageline($im, $x, $y, $x+$RatioTextX, $y, $color);
imageline($im, $x+$RatioTextX, $y, $x+$RatioTextX, $y+(2*$RatioTextY), $color)
;
imageline($im, $x+$RatioTextX, $y+(2*$RatioTextY), $x , $y+(2*$RatioTextY),
$color);
}

function WriteOneNumber($im, $x, $y, $n, $color)
{
switch($n)
{
case 0 : Write0($im, $x, $y, $color); break;
case 1 : Write1($im, $x, $y, $color); break;
case 2 : Write2($im, $x, $y, $color); break;
case 3 : Write3($im, $x, $y, $color); break;
case 4 : Write4($im, $x, $y, $color); break;
case 5 : Write5($im, $x, $y, $color); break;
case 6 : Write6($im, $x, $y, $color); break;
case 7 : Write7($im, $x, $y, $color); break;
case 8 : Write8($im, $x, $y, $color); break;
case 9 : Write9($im, $x, $y, $color); break;
}
}

// PRINCIPAL

$s = strval($n);
for($i=0; $i < strlen($s); $i++)
{
WriteOneNumber($im, $x+($i*$RatioTextX*2), $y, $s[$i], $color);
}

}

?>

      Fonctions du code - Doc officielle PHP

Détail    php.net  
Description
Versions PHP
   imageline
Dessine une ligne
PHP 4, 5, 7 et 8
   strlen
Calcule la taille d'une chaîne
PHP 4, 5, 7 et 8
   strval
Retourne la valeur de la variable, au format chaîne
PHP 4, 5, 7 et 8

   Un petit merci aux auteurs pour leur travail, ça ne coûte rien et ça fait toujours plaisir wink

 Autres snippets qui pourraient vous intéressez

Écrire un texte dans une image PNG avec PHP

Compatibilité : PHP 5, PHP 7, PHP 8

Images PHP- Choisir le texte et le placer ou vous voulez sur l'image - Choisir la couleur de fond de l'image et choisir la dimension de l'image en pixel

Ecrire un texte dans une image avec retour à la ligne automatique - PHP Sources

Compatibilité : PHP 5, PHP 7, PHP 8

Cette fonction vous permettra d'intégrer du texte sur une image avec un retour à la ligne automatique au bout d'une longueur de texte définie

Calcule la somme de nombres dans des tableaux multidimensionnels

Compatibilité : PHP 5, PHP 7, PHP 8

Cette opération se fait en utilisant la fonction  array_sum  qui calcule la somme des valeurs d'un tableau.

Insérer du texte sans erreur dans une table MySQL

Compatibilité : PHP 4, PHP 5

Insérer du texte sans erreur dans une table MySQL. Avec la fonction mysql_real_escape_string(), vous éviterez ainsi l'échec de l'insertion dans vos tables.

Trouve les URLs dans une chaine sans les protocoles et les ajoute

Compatibilité : PHP 5, PHP 7, PHP 8

Trouve les URLs dans un texte qui ne commencent pas correctement par les protocoles http:// ou https://

* Requêtes exécutées avec Recherche Contextuelle

  15 Fév 2019

1 481 Vues
Compatibilité du code
PHP 5, 7 et 8+
54 codes

Catégorie :  Images - Graphisme

Ajoute à votre image un cadre noir 3D
Ajouter un logo en filigrane (watermark) sur ses images
Composantes d'une image
concaténation d'images pour faire des sprites CSS
Connaitre la taille d'une image et son format
Créer une vignette avec GD en se basant sur le type d'image
Création d'images miniatures
Création d'images miniatures carrés
Crée des titres sympa
Créer des images fractales
Creer un camembert 2D facilement
Crop d'une image JPEG
Dessine un polygone régulier
Dessine un polygone regulier plein
Donne la couleur opposée d'une couleur
Ecrire des nombres dans une images, sans police
Ecrire un texte dans une image avec retour à la ligne automatique
Ecrire un texte dans une image PNG
Ecrire un texte sur une image - Code de base
Effet miroir sur des images
Effet solarisation
Egalisation des couleurs d'une image
Explorer et visionner des images dans un répertoire
Extrait un canal de couleur d'une image
Fabrication d'une vignette et sauvegarde de la vignette
Fonction hexadécimal vers RVB (RGB)
Fonctions imagecreatefrombmp et imagebmp
Générer une image aléatoire
GD/Graphiques
Homothétie d'une image
Image aléatoire
Image en noir et blanc
Image transparente
Images Miniatures
Ligne diagonale
Modifications des composantes
Photo du jour choisi de manière aléatoire à partir d'un répertoire
Redimensionne des images JPG et PNG
Redimensionner image en gardant les proportions
Redimensionner une image
Redimensionner une image sans distorsion
Regarde si l'image est présente sur le serveur
Représentation graphique
Rotation de triangle
Rotation image
Sélectionne et affiche la dernière image mise à jour
Sépia aspect ancien
Symétrie horizontale
Taille image maximum en pixels
Texte multi-lignes sur une image avec une police PostScript Type1
Texte ombré en police TrueType
Transparence simple sur une image
Un masque sur une image
Une galerie de photos automatique depuis un répertoire