打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
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;}//http://my.oschina.net/cart/generateImg ( 'http://1.popular.sinaapp.com/munv/pic.jpg', 'my.oschina.net/cart', 'PHP文字水平居中', '3个字' );exit ();
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
改变网页背景颜色和字体颜色大小的代码
【python】明天情人节,给大家带来一些编程表白小程序,给大家助助兴呀~
鸿蒙智联汽车【1.0】
支持中文字母数字、自定义字体php验证码代码.txt
用python生成验证码图片
?这年头…………
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服