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); ?>
?