㈠ php 圖象處理函數 imagestring 函數的運用
可以用imagettftext來生成,支持truetype字體
array imagettftext ( resource image, float size, float angle, int x, int y, int color, string fontfile, string text )
image
圖像資源。見 imagecreatetruecolor()。
size
字體大小。根據 GD 版本不同,應該以像素大小指定(GD1)或點大小(GD2)。
angle
角度製表示的角度,0 度為從左向右讀的文本。更高數值表示逆時針旋轉。例如 90 度表示從下向上讀的文本。
x
由 x,y 所表示的坐標定義了第一個字元的基本點(大概是字元的左下角)。這和 imagestring() 不同,其 x,y 定義了第一個字元的左上角。例如 "top left" 為 0, 0。
y
Y 坐標。它設定了字體基線的位置,不是字元的最底端。
color
顏色索引。使用負的顏色索引值具有關閉防鋸齒的效果。見 imagecolorallocate()。
fontfile
是想要使用的 TrueType 字體的路徑。
根據 PHP 所使用的 GD 庫的不同,當 fontfile 沒有以 / 開頭時則 .ttf 將被加到文件名之後並且會在庫定義字體路徑中嘗試搜索該文件名。
當使用的 GD 庫版本低於 2.0.18 時,一個空格字元 而不是分號將被用來作為不同字體文件的「路徑分隔符」。不小心使用了此特性將會導致一條警告信息:Warning: Could not find/open font。對受影響的版本來說唯一解決方案就是將字體移動到不包含空格的路徑中去。
很多情況下字體都放在腳本的同一個目錄下。下面的小技巧可以減輕包含的問題。 <?php
// Set the enviroment variable for GD
putenv('GDFONTPATH=' . realpath('.'));
// Name the font to be used (note the lack of the .ttf extension)
$font = 'SomeFont';
?>
text
文本字元串。
可以包含十進制數字化字元表示(形式為:€)來訪問字體中超過位置 127 的字元。UTF-8 編碼的字元串可以直接傳遞。
如果字元串中使用的某個字元不被字體支持,一個空心矩形將替換該字元。
imagettftext() 返回一個含有 8 個單元的數組表示了文本外框的四個角,順序為坐下角,右下角,右上角,左上角。這些點是相對於文本的而和角度無關,因此「左上角」指的是以水平方向看文字時其左上角。
例子 1. imagettftext() 例子
本例中的腳本將生成一個白色的 400x30 像素 PNG 圖像,其中有黑色(帶灰色陰影)Arial 字體寫的「Testing...」。
<?php
// Set the content-type
header("Content-type: image/png");
// Create the image
$im = imagecreatetruecolor(400, 30);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = 'arial.ttf';
// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>
㈡ php圖像生成函數imagecreatetruecolor和imagecreate的區別
1、如果你用過smarty模板引擎、MVC類似框架如tp,那麼你自己寫一個框架噢! 2、你要對php的繼承實現以及其中的小知識點熟知; 3、先列出你的框架目錄,什麼地方放什麼,然後寫你的配置文件 4、用到的高頻函數有:require 、 require_once 、 file_exites等! 如:sybase_connect連上資料庫。 語法: int sybase_connect(string [servername], string [username], string [password]); 返回值: 整數函數種類: 資料庫功能 本函數用來打開與 Sybase 資料庫的連接。 參數 servername 為欲連上的資料庫伺服器名稱。 參數 username 及 password 可省略,分別為連接使用的帳號及密碼。 使用本函數需注意早點關閉資料庫,以減少系統的負擔。 連接成功則返回資料庫的連接代號,失敗返回 false 值。
㈢ PHP圖像處理函數有哪些
php圖像處理函數大全
php圖片處理代碼分享,包括縮放、剪裁、縮放、翻轉、旋轉、透明、銳化等。需要的朋友可以參考下
一、創建圖片資源
imagecreatetruecolor(width,height);
imagecreatefromgif(圖片名稱);
imagecreatefrompng(圖片名稱);
imagecreatefromjpeg(圖片名稱);畫出各種圖像
imagegif(圖片資源,保存路徑);
imagepng()
imagejpeg();
二、獲取圖片屬性
imagesx(res//寬度
imagesy(res//高度
getimagesize(文件路徑)
返回一個具有四個單元的數組。索引
0 包含圖像寬度的像素值,索引 1 包含圖像高度的像素值。索引 2 是圖像類型的標記:1 = GIF,2 = JPG,3 = PNG,4 = SWF,5 =
PSD,6 = BMP,7 = TIFF(intel byte order),8 = TIFF(motorola byte order),9 = JPC,10
= JP2,11 = JPX,12 = JB2,13 = SWC,14 = IFF,15 = WBMP,16 = XBM。這些標記與 PHP 4.3.0 新加的
IMAGETYPE 常量對應。索引 3 是文本字元串,內容為「height="yyy" width="xxx"」,可直接用於 IMG
標記。
銷毀圖像資源
imagedestroy(圖片資源);
三、透明處理
PNG、jpeg透明色都正常,只有gif不正常
imagecolortransparent(resource
image [,int
color])//將某個顏色設置成透明色
imagecolorstotal()
imagecolorforindex();
四、圖片的裁剪
imageresized()
imageresampled();
五、加水印(文字、圖片)
字元串編碼轉換string iconv ( string $in_charset ,
string $out_charset , string $str )
六、圖片旋轉
imagerotate();//制定角度的圖片翻轉
七、圖片的翻轉
沿X軸 沿Y軸翻轉
八、銳化
imagecolorsforindex()
imagecolorat()
㈣ 在php中圖像處理新建一個畫布用什麼函數
$newImage=imagecreatetruecolor($xSize,$ySize);
//增加一個白色的底,不然新建的畫布是黑色的
$white=imagecolorallocate($newImage,255,255,255);
imagefill($newImage,0,0,$white);
圖像處理也經常使用到imagemerge、getimagesize、imagecreatefromjpeg等函數,建議你看下這個鏈接,全是圖像處理的函數http://php.net/manual/zh/ref.image.php
㈤ 關於php函數中的imageinterlace($image,int bit);
imageinterlace -- 激活或禁止隔行掃描
說明
int imageinterlace ( resource image [, int interlace] )
imageinterlace() 打開或關閉隔行掃描的比特標記。如果 interlace 為 1 則圖像為隔行掃描的,如果 interlace 為 0 則圖像為非隔行掃描的。
如果設定了隔行掃描比特標記而圖像使用 JPEG 格式,則圖像被創建為漸進式 JPEG。
本函數返回圖像中是否設定了隔行掃描比特標記。
㈥ php圖像生成函數imagecreatetruecolor和imagecreate的區別
resource imagecreatetruecolor ( int $x_size , int $y_size )
返回一個圖像標識符,代表了一幅大小為 x_size 和 y_size 的黑色圖像。
resource imagecreate ( int $x_size , int $y_size )
返回一個圖像標識符,代表了一幅大小為
兩者在改變背景顏色時有些區別:
imagecreatetruecolor需要用imagefill()來填充顏色
imagecreate()需要用imagecolorAllocate()添加背景色
php案例如下:
<?php$img = imagecreatetruecolor(100,100); //創建真彩圖像資源$color = imagecolorAllocate($img,200,200,200); //分配一個灰色imagefill($img,0,0,$color); // 從左上角開始填充灰色header('content-type:image/jpeg'); //jpg格式imagejpeg($img); //顯示灰色的方塊?>
<?php$img = imagecreate(100,100);imagecolorallocate($img,200,200,200);header('content-type:image/jpeg'); imagejpeg($img); ?>
http://www.phpddt.com/php/imagecreate.html
㈦ php函數繪圖顯示圖像後就不能return了嗎
沒具體測試過,不過道理上應該是可以return的。仔細檢查一下代碼唄,或者你貼上來大家幫你看看。
imagepng只是把內容輸出了,並沒有退出php進程,再說imagepng函數本身也會返回true/false。
補充一點,一般來說繪圖函數就是負責繪圖,生成隨機字元的函數負責生成,不應該將這兩個功能放到一個函數里。從流程上,應該先調用隨機字元函數獲取字元串,然後將字元串傳遞給繪圖函數要求它繪制。
㈧ php圖像生成函數imagecreatetruecolor和imagecreate的區別
用imagecreatetruecolor(int x,int y)建立的是一幅大小為 x和 y的黑色圖像(默認為黑色),如想改變背景顏色則需要用填充顏色函數imagefill($img,0,0,$color);
imagecreate 新建一個空白圖像資源,用imagecolorAllocate()添加背景色
上面兩個函數只不過是一個功能的兩種方法
具體用法見以下兩種方法:
<?php
$img = imagecreatetruecolor(100,100); //創建真彩圖像資源
$color = imagecolorAllocate($img,200,200,200); //分配一個灰色
imagefill($img,0,0,$color); // 從左上角開始填充灰色
header('content-type:image/jpeg'); //jpg格式
imagejpeg($img); //顯示灰色的方塊
?>
<?php
$img = imagecreate(100,100);
$color = imagecolorallocate($img,200,200,200);
header('content-type:image/jpeg'); //jpg格式
imagejpeg($img); //顯示灰色的方塊
?>
㈨ PHP圖像函數的請教GD庫
move_uploaded_file() 函數將上傳的文件移動到新位置。
注釋:本函數僅用於通過 HTTP POST 上傳的文件。
你使用imageresampled創建的文件不能使用move_uploaded_file()
建議使用fwrite寫入。