close
♣梅問題‧教學網【Minwt】♣ |
《PHP-imagettftext》線上照片旁白產生器語法大公開 Posted: 19 Jan 2015 04:00 PM PST
上上星期正好是好友阿湯與硬大聯合舉辦了TBC的部落客活動,來了上百位的各路好手,而這一回正好梅干有空閒,就前來當義工,幫大家拍拍照,而每次在拍攝過程中,總有一些趣味搞笑的照片,再配上一些旁白,整個照片就更具趣味性,這時不禁讓梅干想到,每次只要有些時事或是最近正夯的話題,就會有人製作線上旁白的產生器,只要使幅者輸入文字,立即就會將文字壓在圖片上,就可分享到FB中,相當的好玩,所以梅干就稍稍研究了一下PHP的GD函式庫,裡面的imagettftext就可作出如此的效果,經梅干一番的苦戰後,總算完成了中文旁白的字幕功能,而梅干也整理並分享了一下程式碼,有需要的朋友就參考看看囉!最後也感謝好友LEO犧牲色像啦!
imagettftext: 旁白完整PHP程式碼: <?
$img = image(); echo '<img src="data:image/png;base64,' . $img . '" />'; function image() { $width = 650; $height = 400; $x = 30; $y = 450; $im = imagecreatetruecolor($width, $height); $im = imagecreatefromjpeg("leo.jpg"); $text_color = imagecolorallocate($im, 240, 223, 25); $word = "來~來~來~哩來!哩來!"; $font_size = 36; imagettftext($im, $font_size, 0, $x, $y, $text_color, "wqy-zenhei.ttc", $word); ob_start(); imagepng($im); $output = base64_encode(ob_get_clean()); imagedestroy($im); return $output; } ?> [範例預覽] |
You are subscribed to email updates from ♣梅問題‧教學網【Minwt】♣
To stop receiving these emails, you may unsubscribe now. |
Email delivery powered by Google |
Google Inc., 1600 Amphitheatre Parkway, Mountain View, CA 94043, United States |
全站熱搜
留言列表