給圖片添加文字(支援中文) // PHP函數

來源:互聯網
上載者:User
<?php
// **************************************** //
// 功能:給圖片添加文字
// 參數: $img 圖片檔案名稱
// $new_img 另存圖片檔案名稱,如果為空白表示不另存圖片
// $text 字串內容
// text_size 字串大小
// text_angle 字型串輸出角度
// text_x 字串輸出 x 座標
// text_y 字串輸出 y 座標
// $text_font 字型檔案名稱
// $r,$g,$b 字串顏色RGB值
// **************************************** //
function img_text($img, $new_img, $text, $text_size, $text_angle, $text_x, $text_y, $text_font, $r, $g, $b){

$text=iconv("gb2312","UTF-8",$text);
Header("Content-type: image/gif");
$im = @imagecreatefromstring(file_get_contents($img)) or die ("開啟圖片失敗!");
$color = ImageColorAllocate($im, $r,$g,$b);

//ImageTTFText(int im, int size, int angle, int x, int y, int col, string fontfile, string text):
//本函數將 TTF (TrueType Fonts) 字型文字寫入圖片。
//參數: size 為字形的尺寸;
// angle 為字型的角度,順時針計算,0 度為水平(由左到右),90 度則為由下到上的文字;
// x,y 二參數為文字的座標值 (原點為左上方);
// col 為字的顏色;
// fontfile 為字型檔案名稱;
// text 是字串內容。
ImageTTFText($im, $text_size, $text_angle, $text_x, $text_y, $color, $text_font, $text);

if ($new_img==""):
ImageGif($im); // 不儲存圖片,只顯示
else:
ImageGif($im,$new_img); // 儲存圖片,但不顯示
endif;

ImageDestroy($im); //結束圖形,釋放記憶體空間


?>

聯繫我們

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