php 圖片浮水印中文亂碼解決方案_PHP教程

來源:互聯網
上載者:User
php 圖片浮水印中文亂碼解決方案是要轉入一款中文字型摩洛哥 以了,如果你在產生浮水印有中文時,又沒載入相關的字型的話,那中文肯定會是亂碼的,如果是英語字母那載不載入都沒關係哦。

php教程 圖片浮水印中文亂碼解決方案是要轉入一款中文字型摩洛哥 以了,如果你在產生浮水印有中文時,又沒載入相關的字型的話,那中文肯定會是亂碼的,如果是英語字母那載不載入都沒關係哦。

$name = iconv("gb2312","utf-8",www.bKjia.c0m 一聚教程網);
$font = 'simhei.ttf';//浮水印字型
$im = imagecreatefromjpeg("test.jpg");//載入圖片
$black = imagecolorallocate($im, 0, 0, 0);//設定顏色
imagettftext($im, 12, 0, 320, 84, $black, $font, $name);//列印浮水印
imagepng($im);//輸出圖片,如果要儲存加個儲存路徑和檔案名稱,如imagepng($im,'test1.jpg');
imagedestroy($im);//清空緩衝


下面來看一款產生浮水印文字函數

function str2pic ($string,$source,$destination="",$f,$fontsize=10,$shadowcolor="#ffffff",$f,$x=10,$y=10) {
//header('content-type:image/png');
$pi=pathinfo($source);
$pie=$pi[extension];#擷取副檔名
if(eregi("jpg|jpeg",$pie))$im=@imagecreatefromjpeg($source);
if(eregi("gif",$pie))$im=@imagecreatefromgif($source);
if(eregi("png",$pie))$im=@imagecreatefrompng($source);
$col1=hex2dec($shadowcolor);#陰影顏色
$col2=hex2dec($fontcolor);#字型顏色
$col1=imagecolorallocate($im,$col1[0],$col1[1],$col1[2]);
$col2=imagecolorallocate($im,$col2[0],$col2[1],$col2[2]);
imagettftext($im,$fontsize,0,$y+1,$x+1,$col1,$fonturl,$string);
imagettftext($im,$fontsize,0,$y,$x,$col2,$fonturl,$string);
imagejpeg($im);
if($destination)imagejpeg($im,$destination);
imagedestroy($im);
}

function hex2dec($hexcolror) {#十六進位色彩轉換成10進位顏色
preg_match_all("/([0-f]){2,2}/i",$hexcolror,$matches);
if(count($matches[0])==3){
$rr=hexdec($matches[0][0]);
$gg=hexdec($matches[0][1]);
$bb=hexdec($matches[0][2]);
}
return array($rr,$gg,$bb);
}
?>
str2pic("[url=http://www.zhutiai.com]www.bKjia.c0m","winter.jpg","winter2.jpg","simhei.ttf",10,"ffffff","330099",10,10[/url]);
?>

http://www.bkjia.com/PHPjc/633028.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/633028.htmlTechArticlephp 圖片浮水印中文亂碼解決方案是要轉入一款中文字型摩洛哥 以了,如果你在產生浮水印有中文時,又沒載入相關的字型的話,那中文肯定會是...

  • 聯繫我們

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