Last active
November 12, 2015 08:46
-
-
Save microdesign/e1b8d74806fdb2f1a4c1 to your computer and use it in GitHub Desktop.
Draw text to existing image and save it into new one - PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ts = gmdate("D, d M Y H:i:s") . " GMT"; | |
header("Expires: $ts"); | |
header("Last-Modified: $ts"); | |
header("Pragma: no-cache"); | |
header("Cache-Control: no-cache, must-revalidate"); | |
$imgPath = \URL::to( 'exiting_images/exiting.jpg' ); | |
$save_image = 'user_images/test.jpg'; | |
$save_to = public_path($save_image); | |
$image = imagecreatefromjpeg($imgPath); | |
$color = imagecolorallocate($image, 247, 178, 84); | |
list($width, $height) = getimagesize($imgPath); | |
$font_file = public_path('fonts/nautilus-webfont.ttf'); | |
$font_width = ImageFontWidth(23); | |
$font_height = ImageFontHeight(23); | |
$text_width = $font_width * strlen($user_name); | |
$position_center = ceil(($width - $text_width) / 2) - 40; | |
imagefttext($image, 23, 0, $position_center, 140, $color, $font_file, $user_name); | |
imagejpeg($image, $save_to); | |
imagedestroy( $image ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment