php字串產生圖片執行個體詳解

來源:互聯網
上載者:User
本文主要和大家分享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 ();

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.