php index.php
PHP 支援八種基本型態 (primitive type)
這八種分別是
- 布林 (boolean)
- 整數 (integer)
- 浮點數 (floating point number)
- 字串 (string)
- 陣列 (array)
- 物件 (object)
- 資源 (resource)
- NULL
$b = True; // 布林型態$i = 1234; // 整數型態$f = 12.3; // 浮點數型態$s = "12"; // 字串型態陣列就比較複雜一點,因為陣列分成兩部份,第一部分為索引,第二部份則是資料,兩者可以是上面四者型態任一,資料還可以是其他的陣列,例如
$a1 = array(10, 20, 30, 40);$a2 = array( False => True, 33 => "Tony", "A" => 33.06, 6.32 => array(1, 2),); |
echo $a1[0];echo $a1[1];echo $a1[2];echo $a1[3]; |
來個 imagettftext 的例子....
由於他需要 PHP GD2 library
sudo apt-get install php5-gd
<?php// Set the content-typeheader('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 textimagettftext($im, 20, 0, 11, 21, $grey, $font, $text);// Add the textimagettftext($im, 20, 0, 10, 20, $black, $font, $text);// Using imagepng() results in clearer text compared with imagejpeg()imagepng($im);imagedestroy($im);?>
改一下例子....
<?php
header('Content-Type: image/png');
$im = imagecreatetruecolor(400, 400);
// 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, 399, $white);
// The text to draw
//$text = 'Testing...';
$text = '紀富中';
// Replace path by your own font path
//$font = '/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf';
$font1 = '/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc';
$font2 = '/usr/share/fonts/truetype/wqy/wqy-microhei.ttc';
// Add some shadow to the text
//imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
imagettftext($im, 30, 0, 40, 40, $black, $font1, $text);
imagettftext($im, 30, 0, 80, 80, $black, $font2, $text);
imagepng($im);
imagedestroy($im);
?>
執行結果如下 :
一些字型下載的網址
http://fonts.mobanwang.com/
沒有留言:
張貼留言