首页 / PHP / php字符串生成图片实例详解
php字符串生成图片实例详解
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php字符串生成图片实例详解,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2199字,纯文字阅读大概需要4分钟。
内容图文
本文主要和大家分享php字符串生成图片实例详解,希望能帮助到大家。function generateImg($source, $text1, $text2, $text3, $font = './msyhbd.ttf') { $date = '' . date ( 'Ymd' ) . '/'; $img = $date . md5 ( $source . $text1 . $text2 . $text3 ) . '.jpg'; if (file_exists ( './' . $img )) { return $img; } $main = imagecreatefromjpeg ( $source ); $width = imagesx ( $main ); $height = imagesy ( $main ); $target = imagecreatetruecolor ( $width, $height ); $white = imagecolorallocate ( $target, 255, 255, 255 ); imagefill ( $target, 0, 0, $white ); imagecopyresampled ( $target, $main, 0, 0, 0, 0, $width, $height, $width, $height ); $fontSize = 18;//像素字体 $fontColor = imagecolorallocate ( $target, 255, 0, 0 );//字的RGB颜色 $fontBox = imagettfbbox($fontSize, 0, $font, $text1);//文字水平居中实质 imagettftext ( $target, $fontSize, 0, ceil(($width - $fontBox[2]) / 2), 190, $fontColor, $font, $text1 ); $fontBox = imagettfbbox($fontSize, 0, $font, $text2); imagettftext ( $target, $fontSize, 0, ceil(($width - $fontBox[2]) / 2), 370, $fontColor, $font, $text2 ); $fontBox = imagettfbbox($fontSize, 0, $font, $text3); imagettftext ( $target, $fontSize, 0, ceil(($width - $fontBox[2]) / 2), 560, $fontColor, $font, $text3 ); //imageantialias($target, true);//抗锯齿,有些PHP版本有问题,谨慎使用 imagefilledpolygon ( $target, array (10 + 0, 0 + 142, 0, 12 + 142, 20 + 0, 12 + 142), 3, $fontColor );//画三角形 imageline($target, 100, 200, 20, 142, $fontColor);//画线 imagefilledrectangle ( $target, 50, 100, 250, 150, $fontColor );//画矩形 //bof of 合成图片 $child1 = imagecreatefromjpeg ( 'http://gtms01.alicdn.com/tps/i1/T1N0pxFEhaXXXxK1nM-357-88.jpg' ); imagecopymerge ( $target, $child1, 0, 400, 0, 0, imagesx ( $child1 ), imagesy ( $child1 ), 100 ); //eof of 合成图片 @mkdir ( './' . $date ); imagejpeg ( $target, './' . $img, 95 ); imagedestroy ( $main ); imagedestroy ( $target ); imagedestroy ( $child1 ); return $img; }generateImg ( 'https://ssl.picture.qingger.com/Fi8zMItS5c_Uvm7WueZ5z_0VsDg_', 'aaaaa', 'PHP文字水平居中', '3个字' );exit ();
相关推荐:
PHP实现生成图片缩略图函数
node实现文字生成图片代码分享
利用php 内置函数生成图片的方法实例详解
以上就是php字符串生成图片实例详解的详细内容,更多请关注Gxl网其它相关文章!
内容总结
以上是互联网集市为您收集整理的php字符串生成图片实例详解全部内容,希望文章能够帮你解决php字符串生成图片实例详解所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。