<?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); //結束圖形,釋放記憶體空間 } ?> |