How to Convert Medium Text to JPG in PHP

The PHP language includes a function that makes images from text. You convert the text to a JPG image using the imagejpeg function. The function lets you set the size and color of the text to fit a specified height and width. You use this function when you want to create automated images from a user's input on a Web page.

Instructions

    • 1

      Right-click the PHP file you want to edit. Click "Open With" and select your preferred PHP editing program.

    • 2

      Set up the medium-sized text. The image function supports small, medium and large text, but you must specify the size with your image setup function. The following code creates the text "Hello World":

      $im = imagecreatetruecolor(120, 20);
      $color = imagecolorallocate($im, 233, 14, 91);
      imagestring($im, 1, 5, 5, 'Hello World', $color);

      In this example, the image is set up with red text, and the size is 120 pixels in width by 20 pixels in height.

    • 3

      Output the image to the user's screen and convert the image to JPG format. The following code uses the Hello World text to create the JPG:

      header('Content-Type: image/jpeg');
      imagejpeg($im);

Related Searches:

References

Comments

Related Ads

Featured