• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

php字符串生成图片实例详解

php 搞代码 4年前 (2022-01-22) 15次浏览 已收录 0个评论

本文主要和大家分享php字符串生成图片实例详解,希望能帮助到大家。

function generateImg($source, $text1, $text2, $text3, $font = './msyhbd.ttf') {    $date = '' . date ( 'Ymd' ) . '/';    $img = $date . md5 ( $source . $text1 . $text2 . $text3 ) . '.jpg';    if (file_exists ( './' <i>本文@来#源gaodai$ma#com搞$$代**码网</i><strong>搞代gaodaima码</strong>. $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字符串生成图片实例详解的详细内容,更多请关注搞代码gaodaima其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php字符串生成图片实例详解
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址