php在圖片上增加矩形框並加入浮水印

來源:互聯網
上載者:User
php在圖片下增加矩形框並加入浮水印
0x80) $i++; $length++; } return $length; } //待添加浮水印圖片 $imagefile = "3.jpg"; //待添加文字 $str = "照片由戈多上傳於".date("Y年m月d日H時i分s秒"); //由於摻雜漢字,原生函數無法統計真實字元數,造成浮水印文字無法置中 //所以自己寫了個函數統計,如果有mbstring庫支援,換用mb_strlen也可以 $len = str_len($str); //如果來源程式基於utf-8編碼,不需要做字元轉換,刪除此行 $str = iconv('gb2312','utf-8',$str); //擷取原圖大小 $size = getimagesize($imagefile); //底邊矩形高度 $bottom_height = 20; //字型大小 $font_size = 10; $im = imagecreatetruecolor($size[0], $size[1]+$bottom_height); //底邊矩形背景色,修改最後三個RGB參數改變顏色 $bgcolor = imagecolorallocate($im,100,120,100); //字型顏色 $ftcolor = imagecolorallocate($im,255,255,255); imagefill($im,0,0,$bgcolor); //預設從jpeg建立,如從其他圖片建立,可根據副檔名選擇函數 $jpeg = imagecreatefromjpeg($imagefile); imagecopy($im,$jpeg,0,0,0,0,$size[0],$size[1]); $start_x = ($size[0]-$len*$font_size)/2; $start_x = ($start_x>0?$start_x:0); $start_y = $size[1]+$font_size+($bottom_height-$font_size)/2; //C:/windows/fonts/SIMHEI.TTF為ttf字型檔檔案,此處為黑體 imagettftext($im,$font_size,0,$start_x,$start_y,$ftcolor,"C:/windows/fonts/SIMHEI.TTF",$str); header("Content-type: image/jpeg"); imagejpeg($im); imageclose($im); imageclose($jpeg); ?> 

?

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.