第一部分:圖片處理
第一:圖片縮放
圖片等比例縮放、沒處理透明色
代碼如下:
function thumn($background, $width, $height, $newfile) { list($s_w, $s_h)=getimagesize($background);//獲取原圖片高度、寬度 if ($width ($s_w $s_h)) { $width = ($height / $s_h) * $s_w; } else { $height = ($width / $s_w) * $s_h; $new=imagecreatetruecolor($width, $height); $img=imagecreatefromjpeg($background); imagecopyresampled($new, $img, 0, 0, 0, 0, $width, $height, $s_w, $s_h); imagejpeg($new, $newfile); imagedestroy($new); imagedestroy($img); thumn( images/hee.jpg , 200, 200, ./images/hee3.jpg
第二:圖片加水印
圖片添加文字水印
function mark_text($background, $text, $x, $y){ $back=imagecreatefromjpeg($background); $color=imagecolorallocate($back, 0, 255, 0); imagettftext($back, 20, 0, $x, $y, $color, simkai.ttf , $text); imagejpeg($back, ./images/hee7.jpg imagedestroy($back); mark_text( ./images/hee.jpg , 細(xì)說PHP , 150, 250);
第二部分:可變變量
1、可變變量
2、可變函數(shù)
$a= function $a teststr() return adfasd $b= teststr echo $b();
3、可變類
$a= b $$a= c echo $b;
第三部分:文件操作(PHP 操作文件)
一:readfile() 函數(shù)
實例一:
?php echo readfile( webdictionary.txt ?
二:fopen() ;打開文件
(一). fopen(1,2);
1.文件名
2.打開模式
模式 描述
r 打開文件為只讀。文件指針在文件的開頭開始。
w 打開文件為只寫。刪除文件的內(nèi)容或創(chuàng)建一個新的文件,如果它不存在。文件指針在文件的開頭開始。
a 打開文件為只寫。文件中的現(xiàn)有數(shù)據(jù)會被保留。文件指針在文件結(jié)尾開始。創(chuàng)建新的文件,如果文件不存在。
x 創(chuàng)建新文件為只寫。返回 FALSE 和錯誤,如果文件已存在。
r+ 打開文件為讀/寫、文件指針在文件開頭開始。
w+ 打開文件為讀/寫。刪除文件內(nèi)容或創(chuàng)建新文件,如果它不存在。文件指針在文件開頭開始。
a+ 打開文件為讀/寫。文件中已有的數(shù)據(jù)會被保留。文件指針在文件結(jié)尾開始。創(chuàng)建新文件,如果它不存在。
x+ 創(chuàng)建新文件為讀/寫。返回 FALSE 和錯誤,如果文件已存在。
die
exit
(二).fread()讀取文件
fread(1,2)
1.文件的指針
2.讀取文件的大小
(三). filesize() 獲取文件大小
filesize(1);
1.文件名
(四).fclose(1)關(guān)閉文件指針
fclose(1)
1.文件指針
實例二:
?php$myfile = fopen( webdictionary.txt , r ) or die( Unable to open file! echo fread($myfile,filesize( webdictionary.txt ));fclose($myfile);?
(五) fgets(1)讀取一行數(shù)據(jù)
1.文件指針
實例三:
?php$myfile = fopen( webdictionary.txt , r ) or die( Unable to open file! echo fgets($myfile);fclose($myfile);?
實例四: feof(1) 檢測文件是否到了結(jié)尾
?php$myfile = fopen( webdictionary.txt , r ) or die( Unable to open file! // 輸出單行直到 end-of-filewhile(!feof($myfile)) { echo fgets($myfile) . br fclose($myfile);?
(六) fgetc(1)讀取一個字符
(七)fwrite()寫入文件中
實例五:
?php$myfile = fopen( newfile.txt , w ) or die( Unable to open file! $txt = Bill Gates/n fwrite($myfile, $txt);fclose($myfile);?
相關(guān)推薦:
PHP圖片操作 php 圖片處理 p圖片的軟件下載 php 上傳圖
用php和imagemagick來處理圖片文件的上傳和縮放處理
以上就是php中圖片處理和文件操作的方法小結(jié)(附代碼)的詳細(xì)內(nèi)容,PHP教程
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。
新聞熱點
疑難解答
圖片精選