Maison  >  Article  >  développement back-end  >  Comment dessiner une image de chaîne de texte horizontalement à l'aide de la fonction imagestring() en PHP ?

Comment dessiner une image de chaîne de texte horizontalement à l'aide de la fonction imagestring() en PHP ?

王林
王林avant
2023-09-05 09:33:041179parcourir

imagestring() est une fonction intégrée à PHP qui dessine une chaîne horizontalement.

Syntaxe

bool imagestring($image, $font, $x, $y, $string, $color)

Parameters

imagestring() accepte six paramètres différents − $image, $font, $x, $y, $string et $ couleur.

  • $image − Le paramètre $image utilise la fonction imagecreatetruecolor() pour créer un espace vide Une image dans une taille donnée.

  • $font − Le paramètre $font est utilisé pour définir la valeur de la taille de la police sur 1, 2, 3, 4 et 5

    Pour les polices intégrées.

  • $x - Maintient la position de la police sur l'axe X horizontal, dans le coin supérieur gauche.

  • $y - Maintient la position de la police sur l'axe Y vertical, en haut.

  • $string - Le paramètre $string contient la chaîne à écrire.

  • $color - Ce paramètre contient la couleur de l'image.

Valeur de retour

imagestring() Renvoie True en cas de succès et False en cas d'échec.

Exemple 1

<?php
   // Create the size and image by using imagecreate() function.
   $img = imagecreate(700, 300);

   // Set the background color of the image
   $background_color = imagecolorallocate($img, 0, 0, 255);

   // Set the text color of the image
   $text_color = imagecolorallocate($img, 255, 255, 255);

   // Function to create an image that contains the string.
   imagestring($img, 50, 180, 150, "Tutorialspoint", $text_color);
   imagestring($img, 30, 160, 120, "Simply Easy Learning", $text_color);
   header("Content-Type: image/png");
   imagepng($img);
   imagedestroy($img);
?>

Sortie

Comment dessiner une image de chaîne de texte horizontalement à laide de la fonction imagestring() en PHP ?

Exemple 2

<?php
   // Create the size of the image or blank image
   $img = imagecreate(700, 300);

   // Set the background color of the image
   $background_color = imagecolorallocate($img, 122, 122, 122);

   // Set the text color of the image
   $text_color = imagecolorallocate($img, 255, 255, 0);

   // Function to create an image that contains a string.
   imagestring($img, 10, 30, 60,"Tutorialspoint:Simply Easy Learning", $text_color);
   header("Content-Type: image/png");
   imagepng($img);
   imagedestroy($img);
?>

Sortie

Comment dessiner une image de chaîne de texte horizontalement à laide de la fonction imagestring() en PHP ?

Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

Déclaration:
Cet article est reproduit dans:. en cas de violation, veuillez contacter admin@php.cn Supprimer