Skip to content

Instantly share code, notes, and snippets.

@phamquocbuu
Created October 5, 2013 01:46
Show Gist options
  • Save phamquocbuu/6835612 to your computer and use it in GitHub Desktop.
Save phamquocbuu/6835612 to your computer and use it in GitHub Desktop.
PHP Add text to image
//Set the Content Type
header('Content-type: image/jpeg');
// Create Image From Existing File
$jpg_image = imagecreatefromjpeg('1.jpg');
// Allocate A Color For The Text
$white = imagecolorallocate($jpg_image, 255, 255, 255);
// Set Path to Font File
$font_path = 'font.TTF';
// Set Text to Be Printed On Image
$text = "Trường trung học cơ sở!";
// Print Text On Image
imagettftext($jpg_image, 55, 0, 100, 100, $white, $font_path, $text);
// Send Image to Browser
imagejpeg($jpg_image, "out.jpg");
// Clear Memory
imagedestroy($jpg_image);
@sanjeevchoudhary1004
Copy link

out.jpg image is created but ,Text will not be added into new image ..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment