Writing text in a jpeg image using php

by guruprasad 2014-06-27 10:41:37

To write a text in a sample image using php:
 
  header('Content-type: image/jpeg');

  $text = "sample text!";       //sample text to be used in a jpeg picture.

  $font = 'ambient.ttf';  //font style

  $image = imagecreatefromjpeg('test.jpg');  //sample image where the text to be used.

  $text_col= imagecolorallocate($image, 255, 255, 255);  //color of the text.

  imagettftext($image, 125, 0, 975, 220, $text_col, $font, $text);  // using text in a image.

 /*
  Parameter usage in imagettftext function:
 
    1.the first parameter represents the image to be used.(i.e., $image).       
    2.the second parameter represents the font size.(i.e., 125).
    3.the third parameter represents the angle of the text to be displayed.(i.e., 0).
    4.the fourth parameter represents the x position.(i.e., 975).
    5.the fifth parameter represents the y position.(i.e., 220).
    6.the sixth parameter represents the text color.
    7.the seventh parameter represents the font file.
    8. the eighth parameter represents the text to be used in image.
*/
                  

  imagejpeg($image);

  imagedestroy($image);

output:
 
1120
like
0
dislike
0
mail
flag

You must LOGIN to add comments