Subversion Repositories php-qbpwcf

Rev

Rev 173 | Rev 200 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php

/*

        QBPWCF, Quick Build PHP website Component base on Fedora Linux.
    Copyright (C) 2015~2024 Min-Jhin,Chen

    This file is part of QBPWCF.

    QBPWCF is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    QBPWCF is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.

*/
namespace qbpwcf;

/*
類別說明:
跟圖片處理有關的類別/
備註:
無.
*/
class img{

        /*
        #函式說明:
        #當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
        #回傳結果:
        #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
        #$reuslt["error"],執行不正常結束的錯訊息陣列.
        #$result["function"],當前執行的函式名稱.
        #必填參數:
        #$method,物件,為物件實體或類別名稱,會自動置入該參數.
        #$arguments,陣列,為呼叫方法時所用的參數.
        #參考資料:
        #__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
        */
        public function __call($method,$arguments){
                
                #取得當前執行的函式
                $result["function"]=__FUNCTION__;
                
                #設置執行不正常
                $result["status"]="false";
                
                #設置執行錯誤
                $result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
                
                #設置所丟入的參數
                $result["error"][]=$arguments;
                
                #回傳結果
                return $result;
                
                }#function __call end
                
        /*
        #函式說明:
        #當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
        #回傳結果:
        #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
        #$reuslt["error"],執行不正常結束的錯訊息陣列.
        #$result["function"],當前執行的函式名稱.
        #必填參數:
        #$method,物件,為物件實體或類別名稱,會自動置入該參數.
        #$arguments,陣列,為呼叫方法時所用的參數.
        #參考資料:
        #__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
        */
        public static function __callStatic($method,$arguments){
                
                #取得當前執行的函式
                $result["function"]=__FUNCTION__;
                
                #設置執行不正常
                $result["status"]="false";
                
                #設置執行錯誤
                $result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
                
                #設置所丟入的參數
                $result["error"][]=$arguments;
                
                #回傳結果
                return $result;
                
                }#function __callStatic end

        /*
        #函式說明:
        #放置可以套用css樣式的圖片
        #回傳結果:
        #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
        #$result["error"],錯誤訊息陣列
        #$result["function"],當前函數執行的名稱
        #$result["content"],印出圖片的語法。            
        #必填參數:
        $conf["position"]="";#圖片位置
        #可省略參數:
        #$conf["id"]="";#圖片的id,沒有就不設定.
        #$conf["alt"]="";#若沒有圖片要用什麼文字顯示。
        #$conf["class"]="";#要套用的css樣式類別名稱。
        #參考資料:
        #無.
        #備註:
        #無.
        */      
        public static function show(&$conf){

                #初始化要回傳的變數
                $result=array();
                
                #記錄當前執行的函數名稱
                $result["function"]=__FUNCTION__;
                
                #如果 $conf 不為陣列
                if(gettype($conf)!="array"){
                        
                        #設置執行失敗
                        $result["status"]="false";
                        
                        #設置執行錯誤訊息
                        $result["error"][]="\$conf變數須為陣列形態";

                        #如果傳入的參數為 null
                        if($conf==null){
                                
                                #設置執行錯誤訊息
                                $result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
                                
                                }#if end

                        #回傳結果
                        return $result;
                        
                        }#if end
                        
                #檢查參數
                #函式說明:
                #檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
                #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                #$reuslt["error"],執行不正常結束的錯訊息陣列.
                #$result["function"],當前執行的函式名稱.
                #$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
                #$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
                #$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
                #$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
                #$result["argu"],字串陣列,目前輸入的參數名稱陣列.
                #$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
                #$result["notNeedVar"],字串陣列,多餘的參數名稱.
                #必填寫的參數:
                #$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
                $conf["variableCheck::checkArguments"]["varInput"]=&$conf;
                #$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
                $conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("position");
                #$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double"); 
                $conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
                #$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
                $conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
                #可以省略的參數:
                #$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
                $conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
                #$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
                $conf["variableCheck::checkArguments"]["skipableVariableName"]=array("id","alt","class");
                #$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
                $conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
                #$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
                $conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"","");
                #$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
                #$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
                #參考資料來源:
                #array_keys=>http://php.net/manual/en/function.array-keys.php
                $checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
                unset($conf["variableCheck::checkArguments"]);

                #如果檢查失敗
                if($checkResult["status"]=="false"){
                        
                        #設置錯誤狀態
                        $result["status"]="false";
                        
                        #設置錯誤提示
                        $result["error"]=$checkResult;
                        
                        #回傳結果
                        return $result;
                        
                        }#if end

                #如果檢查不通過
                if($checkResult["passed"]=="false"){
                        
                        #設置錯誤狀態
                        $result["status"]="false";
                        
                        #設置錯誤提示
                        $result["error"]=$checkResult;
                        
                        #回傳結果
                        return $result;
                        
                        }#if end
                
                #如果$conf["class"]不為""
                if($conf["class"]!=""){

                        #則套用css樣式。
                        $conf["class"] = "class = \"".$conf["class"]."\"";

                        }#if end

                #如果$conf["alt"]不為""
                if($conf["alt"]!=""){

                        $conf["alt"]="alt=\"".$conf["alt"]."\"";

                        }#else end

                #初始化 id 的內容
                $id="";

                #如果有設定 id
                if(isset($conf["id"])){

                        #設置id.
                        $id="id='".$conf["id"]."'";

                        }#if end

                #回傳放置圖片的語法
                $result["content"]="<img src = \"".$conf["position"]."\" ".$conf["alt"]." ".$conf["class"]." ".$id.">";
                
                #設置執行正常
                $result["status"]="true";
                
                #回傳結果
                return $result;
                
                }#function showClassImg end

        /*
        #函式說明:
        #使用在用戶端的圖片插入到網頁裡面,用戶端要有提供類似apache的功能,這樣才能存取用戶端的圖片。
        #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
        #$result["error"],錯誤訊息陣列
        #$result["function"],當前函數執行的名稱
        #$result["content"],印出圖片的語法。            
        #必填參數:
        $conf["AbsoluteFilePosition"]="";#去掉開頭(127.0.0.1或localhost)的檔案在本機的絕對位置。
        #可省略參數:
        #$conf["method"]="";#通訊協定名稱,預設爲"http"
        #$conf["port"]="";#存取用戶端檔案時的port
        #$conf["width"]="";#圖片的顯示寬度
        #$conf["height"]="";#圖片的顯示高度
        #$conf["alt"]="";#若圖片無法顯現則用 $alt 文字替代
        #參考資料:
        #無.
        #備註:
        #無.
        */
        public static function showLocal($conf){

                #初始化要回傳的變數
                $result=array();
                
                #記錄當前執行的函數名稱
                $result["function"]=__FUNCTION__;
                
                #如果 $conf 不為陣列
                if(gettype($conf)!="array"){
                        
                        #設置執行失敗
                        $result["status"]="false";
                        
                        #設置執行錯誤訊息
                        $result["error"][]="\$conf變數須為陣列形態";

                        #如果傳入的參數為 null
                        if($conf==null){
                                
                                #設置執行錯誤訊息
                                $result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
                                
                                }#if end

                        #回傳結果
                        return $result;
                        
                        }#if end

                #如果 $conf["AbsoluteFilePosition"] 沒有設定
                if(!isset($conf["AbsoluteFilePosition"])){

                        #設置執行失敗
                        $result["status"]="false";
                        
                        #設置執行錯誤訊息
                        $result["error"][]="\$conf[\"AbsoluteFilePosition\"]參數沒有設定!";

                        #回傳結果
                        return $result;

                        }#if end

                #如果 $conf["method"] 沒有設定
                if(!isset($conf["method"])){

                        $conf["method"]="http";

                        }#if end

                #如果$conf["port"]沒設定
                if(!isset($conf["port"])){

                        #則設爲"80"
                        $conf["port"]="";
                        
                        }#if end

                #反之有設定
                else{

                        #加上指定連接口的符號
                        $conf["port"]=":".$conf["port"];

                        }#if end
        
                #如果$conf["width"]沒設定
                if(!isset($conf["width"])){

                        #則$conf["width"]爲空
                        $conf["width"]="";
                        
                        }#if end

                #如果$conf["width"]有設定
                else{

                        #則按照設定值
                        $conf["width"]=" width=".$conf["width"];
                        
                        }#else end

                #如果$conf["height"]沒設定
                if(!isset($conf["height"])){

                        #則$conf["height"]爲空
                        $conf["height"]="";
                        
                        }#if end

                #如果$conf["height"]有設定
                else{
                        
                        #則按照設定值
                        $conf["height"]=" height=".$conf["height"];
                        
                        }#else end

                #如果$conf["alt"]沒設定
                if(!isset($conf["alt"])){

                        #則$conf["alt"]爲空
                        $conf["alt"]="";
                        
                        }#if end

                #如果$conf["alt"]有設定
                else{

                        #就按照設定值
                        $conf["alt"]=" alt=".$conf["alt"];

                        }#else end

                #將客戶端IP放到 $LocalIP 變數裡面
                $LocalIP = $_SERVER['REMOTE_ADDR'];
        
                #放置圖片的語法
                $result["content"]="<img src =".$conf["method"]."://".$LocalIP.$conf["port"]."/".$conf["AbsoluteFilePosition"]." ".$conf["width"]." ".$conf["height"]." ".$conf["alt"].">";
        
                #設置執行正常
                $result["status"]="true";
        
                #印出圖片
                return $result;

                }#function showLocalImgWithPort end

        /*
        #函式說明:
        #建立含有文字的png圖檔
        #回傳結果:
        #$result["status"],執行是否正常,"true"為正常,"false"為不正常.
        #$result["error"],錯誤訊息陣列
        #$result["function"],當前執行的函數名稱
        #$result["content"],圖片的位置與檔案名稱
        #必填參數:
        #$conf["imgWidth"],整數,圖片的寬度.
        $conf["imgWidth"]=0;
        #$conf["imgHeight"],整數,圖片的高度.
        $conf["imgHeight"]=0;
        #$conf["imgStoreAddAndName"],字串,圖片要儲存到的地方以及其名稱.
        $conf["imgStoreAddAndName"]="";
        #$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
        $conf["fileArgu"]=__FILE__;
        #可省略參數:
        #$conf["bgRedNum"]=0;#圖片的紅色底色數值0~255,預設爲0
        #$conf["bgGreenNum"]=0;#圖片的綠色底色數值0~255,預設爲0
        #$conf["bgBlueNum"]=0;#圖片的藍色底色數值0~255,預設爲0
        #$conf["strOnImg"]="";#要出現在圖片上的文字,預設為""
        #$conf["textRedNum"]=255;#文字顏色的紅色數值0~255,預設爲255
        #$conf["textGreenNum"]=255;#文字顏色的綠色數值0~255,預設爲255
        #$conf["textBlueNum"]=255;#文字顏色的藍色數值0~255,預設爲255
        #$conf["drawLine"]=array("");#可以畫多條線,參數格式爲「0,0,200,100,50,100,150 」,每個參數依序代表x0、y0爲線條的起始點;x1、y1爲線條的終點;red、green、blue爲線條的顏色數值(0~255)
        #$conf["replaceOriImg"]="false";#如果遇到相同名字會將之刪除,flase爲不要刪除,預設為"false".
        #參考資料:
        #imagecreate=>http://php.net/manual/en/function.imagecreate.php
        #imagecolorallocate=>http://php.net/manual/en/function.imagecolorallocate.php
        #imagestring=>http://php.net/manual/en/function.imagestring.php
        #imageline=>http://php.net/manual/en/function.imageline.php
        #imagepng=>http://php.net/manual/en/function.imagepng.php
        #imagedestroy=>http://php.net/manual/en/function.imagedestroy.php
        #備註:
        #無.
        */
        public static function create(&$conf){

                #初始化要回傳的變數
                $result=array();
                
                #記錄當前執行的函數名稱
                $result["function"]=__FUNCTION__;
                
                #如果 $conf 不為陣列
                if(gettype($conf)!="array"){
                        
                        #設置執行失敗
                        $result["status"]="false";
                        
                        #設置執行錯誤訊息
                        $result["error"][]="\$conf變數須為陣列形態";

                        #如果傳入的參數為 null
                        if($conf==null){
                                
                                #設置執行錯誤訊息
                                $result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
                                
                                }#if end

                        #回傳結果
                        return $result;
                        
                        }#if end

                #檢查參數
                #函式說明:
                #檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
                #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                #$reuslt["error"],執行不正常結束的錯訊息陣列.
                #$result["function"],當前執行的函式名稱.
                #$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
                #$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
                #$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
                #$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
                #$result["argu"],字串陣列,目前輸入的參數名稱陣列.
                #$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
                #$result["notNeedVar"],字串陣列,多餘的參數名稱.
                #必填寫的參數:
                #$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
                $conf["variableCheck::checkArguments"]["varInput"]=&$conf;
                #$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
                $conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","imgWidth","imgHeight","imgStoreAddAndName");
                #$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double"); 
                $conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","integer","integer","string");
                #$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
                $conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
                #可以省略的參數:
                #$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
                $conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
                #$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
                $conf["variableCheck::checkArguments"]["skipableVariableName"]=array("bgRedNum","bgGreenNum","bgBlueNum","strOnImg","textRedNum","textGreenNum","textBlueNum","drawLine","replaceOriImg");
                #$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
                $conf["variableCheck::checkArguments"]["skipableVariableType"]=array("integer","integer","integer","string","integer","integer","integer","array","string");
                #$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
                $conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(0,0,0,"",255,255,255,null,"false");
                #$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
                #$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
                #參考資料來源:
                #array_keys=>http://php.net/manual/en/function.array-keys.php
                $checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
                unset($conf["variableCheck::checkArguments"]);

                #如果檢查失敗
                if($checkResult["status"]=="false"){
                        
                        #設置錯誤狀態
                        $result["status"]="false";
                        
                        #設置錯誤提示
                        $result["error"]=$checkResult;
                        
                        #回傳結果
                        return $result;
                        
                        }#if end

                #如果檢查不通過
                if($checkResult["passed"]=="false"){
                        
                        #設置錯誤狀態
                        $result["status"]="false";
                        
                        #設置錯誤提示
                        $result["error"]=$checkResult;
                        
                        #回傳結果
                        return $result;
                        
                        }#if end

                #如果有設置 $conf["replaceOriImg"] 變數
                if(isset($conf["replaceOriImg"])){

                        #如果要移除相同檔名的檔案
                        if($conf["replaceOriImg"] != "false"){

                                #函式說明:檢查多個檔案與資料夾是否存在
                                #回傳的結果:
                                #$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
                                #$result["error"],錯誤訊息陣列.
                                #$resutl["function"],當前執行的涵式名稱.
                                #$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
                                #$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
                                #$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
                                #必填的參數:
                                $conf["fileAccess"]["checkMutiFileExist"]["fileArray"]=array($conf["imgStoreAddAndName"].".png");#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
                                #$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
                                $conf["fileAccess"]["checkMutiFileExist"]["fileArgu"]=$conf["fileArgu"];
                                #可省略參數
                                #$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,預設為"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在.
                                $conf["fileAccess"]["checkMutiFileExist"]["disableWebSearch"]="true";
                                #參考資料來源:
                                #http:#php.net/manual/en/function.file-exists.php
                                #http:#php.net/manual/en/control-structures.foreach.php
                                $fileExist=fileAccess::checkMultiFileExist($conf["fileAccess"]["checkMutiFileExist"]);
                                unset($conf["fileAccess"]["checkMutiFileExist"]);
                                
                                #如果檢查圖片檔案存在失敗
                                if($fileExist["status"]=="false"){
                                        
                                        #設置錯誤狀態
                                        $result["status"]="false";
                                        
                                        #設置錯誤提示
                                        $result["error"]=$fileExist;
                                        
                                        #回傳結果
                                        return $result;
                                        
                                        }#if end

                                #如果目標檔案存在
                                if($fileExist["varExist"][0]=="true"){

                                        #移除目標檔案
                                        #函式說明:
                                        #移除檔案
                                        #回傳結果:
                                        #$result["status"],"true"代表移除成功,"false"代表移除失敗.
                                        #$result["error"],錯誤訊息陣列
                                        #$result["warning"],警告訊息陣列
                                        #$result["function"],當前執行的函數名稱
                                        #必填參數:
                                        $conf["fileAccess::delFile"]["fileAddress"]=$conf["imgStoreAddAndName"].".png";#要移除檔案的位置
                                        #$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
                                        $conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
                                        $delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
                                        unset($conf["fileAccess::delFile"]);
        
                                        #如果移除檔案失敗
                                        if($delFile["status"]=="false"){
                                                
                                                #設置錯誤狀態
                                                $result["status"]="false";
                                                
                                                #設置錯誤提示
                                                $result["error"]=$delFile;
                                                
                                                #回傳結果
                                                return $result;
                                                
                                                }#if end

                                        }#if end

                                }#if end

                        }#if end

                #目前認爲不太好用,所以取消了。
                #建立填滿的黑色圖片寬爲200、高爲100
                #$im = imagecreatetruecolor(200, 100);

                #建立背景是空白的圖片,若使用失敗,則顯示錯誤訊息
                #若後面有設定供此圖片可以使用的顏色則第一個顏色會被作爲背景的顏色
                #參數1是寬度
                #參數2是高度
                #參考資料來源:http://php.net/manual/en/function.imagecreate.php
                $im = \imagecreate($conf["imgWidth"],$conf["imgHeight"]);

                #如果 $im 為 FALSE
                if($im==FALSE){
                        
                        #設置執行失敗
                        $result["status"]="false";
                        
                        #設置執行錯誤訊息
                        $result["error"][]="建立底層為空白的圖片失敗";
                        
                        #回傳結果
                        return $result;
                        
                        }#if end

                #設定接下來給$im那張圖用的顏色,必須爲函式 imagecreate 製造的圖片才行
                #參數1爲設定好的圖片要給那張圖使用
                #參數2爲紅色的用量0~255
                #參數3爲綠色的用量0~255
                #參數4爲藍色的用量0~255
                $bgColor = imagecolorallocate($im,$conf["bgRedNum"],$conf["bgGreenNum"], $conf["bgBlueNum"]);

                #如果設定背景顏色失敗
                if($bgColor===FALSE){
                        
                        #設置執行失敗
                        $result["status"]="false";
                        
                        #設置執行錯誤訊息
                        $result["error"][]="設定背景顏色失敗";
                        
                        #回傳結果
                        return $result;
                        
                        }#if end

                #設定接下來給文字使用的顏色,必須爲函式 imagecreate 製造的圖片才行
                #參數1爲設定好的圖片要給那張圖使用
                #參數2爲紅色的用量0~255
                #參數3爲綠色的用量0~255
                #參數4爲藍色的用量0~255
                $textColor = imagecolorallocate($im,$conf["textRedNum"],$conf["textGreenNum"], $conf["textBlueNum"]);

                #如果設定給文字使用的顏色失敗
                if($textColor===FALSE){
                        
                        #設置執行失敗
                        $result["status"]="false";
                        
                        #設置執行錯誤訊息
                        $result["error"][]="設定給文字使用的顏色失敗";
                        
                        #回傳結果
                        return $result;
                        
                        }#if end

                #建立文字放在圖片上面
                #參數1爲要給哪張圖片使用,必須爲函式 imagecreate 製造的圖片才行
                #參數2爲字型的大小,可用的值爲1~5
                #參數3爲要從圖片左上角的x軸值開始
                #參數4爲要從圖片最上將的y軸值開始
                #參數5爲要放置的字串內容
                #參數6爲文字的顏色,必須使用函式 imagecolorallocate 產生的顏色才行
                #參考資料來源:http://php.net/manual/en/function.imagestring.php
                $imagestring=imagestring($im, 5 , 5 , 5 ,$conf["strOnImg"],$textColor);

                #如果在圖片上放置文字失敗
                if($imagestring==FALSE){
                        
                        #設置執行失敗
                        $result["status"]="false";
                        
                        #設置執行錯誤訊息
                        $result["error"][]="在圖片上放置文字失敗";
                        
                        #回傳結果
                        return $result;
                        
                        }#if end

                #如果有設定畫線
                if(isset($conf["drawLine"])){

                        #有幾條線就執行幾次
                        foreach($conf["drawLine"] as $lineInfo){

                                #解析線的資訊
                                #範例格式: 
                                #0,0,200,100,50,100,150;

                                #分割字串(以,分開)
                                #函式說明:
                                #將固定格式的字串分開,並回傳分開的結果。
                                #回傳的參數:
                                #$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
                                #$result["dataCounts"],爲總共分成幾段
                                #必填參數:
                                $conf["stringProcess"]["spiltString"]["stringIn"]=$lineInfo;#要處理的字串。
                                $conf["stringProcess"]["spiltString"]["spiltSymbol"]=",";#爲以哪個符號作爲分割
                                $spiltedStr1=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
                                unset($conf["stringProcess"]["spiltString"]);

                                #如果分割字串失敗
                                if($spiltedStr1["status"]=="false"){
                                        
                                        #設置執行失敗
                                        $result["status"]="false";
                                        
                                        #設置執行錯誤訊息
                                        $result["error"]=$spiltedStr1;
                                        
                                        #回傳結果
                                        return $result;
                                        
                                        }#if end

                                #建立線條的顏色
                                #設定接下來給$im那張圖上線條用的顏色,必須爲函式 imagecreate 製造的圖片才行
                                #參數1爲設定好的圖片要給那張圖使用
                                #參數2爲紅色的用量0~255
                                #參數3爲綠色的用量0~255
                                #參數4爲藍色的用量0~255
                                $lineColor=imagecolorallocate($im,(int)$spiltedStr1["dataArray"][4],(int)$spiltedStr1["dataArray"][5],(int)$spiltedStr1["dataArray"][6]);

                                #如果設定給線條使用的顏色失敗
                                if($lineColor===FALSE){
                        
                                        #設置執行失敗
                                        $result["status"]="false";
                                        
                                        #設置執行錯誤訊息
                                        $result["error"][]="設定給線條使用的顏色失敗";
                                        
                                        #回傳結果
                                        return $result;
                                        
                                        }#if end

                                #劃綫
                                #參數1爲要畫在那張圖片上面,必須爲函式 imagecreate 製造的圖片才行
                                #參數2爲綫的x軸起點
                                #參數3爲綫的y軸起點
                                #參數4爲線的x軸終點
                                #參數5爲綫的y軸終點
                                #參數6爲線的顏色樣式,必須使用函式 imagecolorallocate 產生的顏色才行
                                $imageline=imageline($im,(int)$spiltedStr1["dataArray"][0],(int)$spiltedStr1["dataArray"][1],(int)$spiltedStr1["dataArray"][2],$spiltedStr1["dataArray"][3],$lineColor);

                                #如果劃線失敗
                                if($imageline==FALSE){
                                        
                                        #設置執行失敗
                                        $result["status"]="false";
                                        
                                        #設置執行錯誤訊息
                                        $result["error"][]="劃線失敗";
                                        
                                        #回傳結果
                                        return $result;
                                        
                                        }#if end

                                }#foreach end

                        }#if end

                #建立圖片並存到伺服端上
                #參數1爲圖片的內容變數,必須爲函式 imagecreate 製造的圖片才行 
                #參數2爲圖片要存在伺服端的位置與名稱
                #參考資料來源:http://php.net/manual/en/function.imagepng.php
                $imagepng=imagepng($im,$conf["imgStoreAddAndName"].".png");

                #如果將圖片輸出成檔案失敗
                if($imagepng==FALSE){
                        
                        #設置執行失敗
                        $result["status"]="false";
                        
                        #設置執行錯誤訊息
                        $result["error"][]="將圖片輸出到「".$conf["imgStoreAddAndName"].".png」"."失敗";
                        
                        #回傳結果
                        return $result;
                        
                        }#if end

                #將圖片從記憶體裏面釋放,必須爲函式 imagecreate 製造的圖片才行
                $imagedestroy=imagedestroy($im);

                #如果卸除編輯圖片的記憶體失敗
                if($imagedestroy==FALSE){
                        
                        #設置執行失敗
                        $result["status"]="false";
                        
                        #設置執行錯誤訊息
                        $result["error"][]="卸除編輯圖片的記憶體失敗";
                        
                        #回傳結果
                        return $result;
                        
                        }#if end

                #取得完整的圖片位置與名稱
                $result["content"]=$conf["imgStoreAddAndName"].".png";

                #執行到這邊代表執行正常
                $result["status"]="true";

                #回傳結果
                return $result;

                }#function create end

        /*
        #函式說明:
        #用data:mimeType;base64,imgVar的形式來提供圖片的連結,亦即圖片儲存在變數裡面,本函式包含顯示圖片的語法.
        #回傳結果:
        #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
        #$result["error"],錯誤訊息
        #$result["content"]["imgWithoutImgTag"],img的src數值內容.
        #$result["content"]["img"],圖片的連結資訊
        #$result["function"],當前執行的函數名稱 
        #必填參數:
        #$conf["imgPosition"],要轉存成2元碼的圖片檔案位置與名稱
        $conf["imgPosition"]="";
        #$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
        $conf["fileArgu"]=__FILE__;
        #可省略參數:
        #$conf["alt"],若沒有圖片要用什麼文字顯示。
        #$conf["alt"]="";
        #$conf["style"],字串陣列,要使用的style,key為樣式名稱,value為樣式值.
        #$conf["style"]=array();
        #$conf["class"],圖片要套用的css樣式名稱.
        #$conf["class"]="";
        #$conf["mimeType"],2元碼的內容是什麼,預設為"image/*".
        #$conf["mimeType"]="image/*";
        #$conf["compressType"],2元碼壓縮的方式,預設為"base64".
        #$conf["compressType"]="base64";
        #$conf["delImg"],讀取完圖片檔案後,要移除圖片嗎?"true"代表要移除,"false"代表不要移除,預設為"false".
        #$conf["delImg"]="false";
        #參考資料:
        #將檔案用字串變數儲存起來=>http://php.net/manual/en/function.file-get-contents.php
        #壓縮2元碼=>http://php.net/manual/en/function.base64-encode.php
        #備註:
        #參數mimeType可改用fileAccess::getFileContent來取得.
        */
        public static function data(&$conf){
                
                #初始化要回傳的變數
                $result=array();
                
                #記錄當前執行的函數名稱
                $result["function"]=__FUNCTION__;
                
                #如果 $conf 不為陣列
                if(gettype($conf)!="array"){
                        
                        #設置執行失敗
                        $result["status"]="false";
                        
                        #設置執行錯誤訊息
                        $result["error"][]="\$conf變數須為陣列形態";

                        #如果傳入的參數為 null
                        if($conf==null){
                                
                                #設置執行錯誤訊息
                                $result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
                                
                                }#if end

                        #回傳結果
                        return $result;
                        
                        }#if end
                
                #檢查參數
                #函式說明:
                #檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
                #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                #$reuslt["error"],執行不正常結束的錯訊息陣列.
                #$result["function"],當前執行的函式名稱.
                #$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
                #$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
                #$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
                #$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
                #必填寫的參數:
                #$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
                $conf["variableCheck::checkArguments"]["varInput"]=&$conf;
                #$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
                $conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","imgPosition");
                #$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double"); 
                $conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
                #$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
                $conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
                #可以省略的參數:
                #$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
                $conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
                #$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
                $conf["variableCheck::checkArguments"]["skipableVariableName"]=array("alt","style","class","mimeType","compressType","delImg");
                #$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
                $conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","array","string","string","string","string");
                #$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,「null」代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
                $conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,null,null,"base64","false");
                #$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
                #$conf["arrayCountEqualCheck"][]=array();
                $checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
                unset($conf["variableCheck::checkArguments"]);
                
                #如果檢查參數失敗
                if($checkResult["status"]=="false"){
                        
                        #設置執行失敗
                        $result["status"]="false";
                        
                        #設置錯誤訊息
                        $result["error"]=$checkResult;
                        
                        #回傳結果
                        return $result;
                        
                        }#if end
                        
                #如果檢查參數不通過
                if($checkResult["passed"]=="false"){
                        
                        #設置執行失敗
                        $result["status"]="false";
                        
                        #設置錯誤訊息
                        $result["error"]=$checkResult;
                        
                        #回傳結果
                        return $result;
                        
                        }#if end
                
                #函式說明:
                #依據行號分隔抓取檔案的內容,結果會回傳一個陣列
                #回傳的變數說明:
                #$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
                #$result["error"],錯誤訊息提示.
                #$result["warning"],警告訊息.
                #$result["function"],當前執行的函數名稱.
                #$result["fileContent"],爲檔案的內容陣列.
                #$result["lineCount"],爲檔案內容總共的行數.
                #$result["fullContent"],為檔案的完整內容.
                #$result["base64data"],為檔案的base64內容.
                #$result["mimeType"],為檔案的mime type.
                #必填參數:
                #$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
                $conf["fileAccess::getFileContent"]["filePositionAndName"]=$conf["imgPosition"];
                #$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
                $conf["fileAccess::getFileContent"]["fileArgu"]=__FILE__;
                #可省略參數:
                #$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
                #$conf["web"]="true";
                #$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
                #$conf["createIfnotExist"]="false";
                #$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
                #$conf["autoDeleteSpaceOnEachLineStart"]="false";
                #參考資料:
                #file(),取得檔案內容的行數.
                #file=>http:#php.net/manual/en/function.file.php
                #rtrim(),剔除透過file()取得每行內容結尾的換行符號.
                #filesize=>http://php.net/manual/en/function.filesize.php
                #參考資料:
                #無.
                #備註:
                #無.
                $getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
                unset($conf["fileAccess::getFileContent"]);
                
                #如果執行異常
                if($getFileContent["status"]=="false"){
                        
                        #設置執行失敗
                        $result["status"]="false";
                        
                        #設置錯誤訊息
                        $result["error"]=$getFileContent;
                        
                        #回傳結果
                        return $result;
                        
                        }#if end
                
                #如果 $conf["alt"] 有設定
                if(isset($conf["alt"])){
                        
                        #設置 alt 屬性
                        $conf["alt"]=" alt=\"".$conf["alt"]."\" ";
                        
                        }#if end
                        
                #反之設為 ""
                else{
                        
                        $conf["alt"]="";
                        
                        }#else end
                        
                #如果 $conf["class"] 有設定
                if(isset($conf["class"])){
                        
                        #設置 class 屬性
                        $conf["class"]=" class=\"".$conf["class"]."\" ";
                        
                        }#if end
                        
                #反之設為 ""
                else{
                        
                        $conf["class"]="";
                        
                        }#else end
                
                #如果 $conf["delImg"] 等於 "true"
                if($conf["delImg"]=="true"){
                        
                        #移除圖片檔案
                        #函式說明:
                        #移除檔案
                        #回傳結果:
                        #$result["status"],"true"代表移除成功,"false"代表移除失敗.
                        #$result["error"],錯誤訊息陣列
                        #$result["warning"],警告訊息陣列
                        #$result["function"],當前執行的函數名稱
                        #必填參數:
                        $conf["fileAccess::delFile"]["fileAddress"]=$conf["imgPosition"];#要移除檔案的位置
                        #$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
                        $conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
                        $del=fileAccess::delFile($conf["fileAccess::delFile"]);
                        unset($conf["fileAccess::delFile"]);
                        
                        #如果移除圖片失敗
                        if($del["status"]=="false"){
                                
                                #設置執行失敗
                                $result["status"]="false";
                                
                                #設置錯誤訊息
                                $result["error"]=$del;
                                
                                #回傳結果
                                return $result;
                                
                                }#if end
                        
                        }#if end
                
                #初始化樣式字串
                $style="";
                
                #如果有設置 $conf["style"]
                if(isset($conf["style"])){
                        
                        #初始化樣式名稱陣列
                        $styleN=array();
                        
                        #初始化樣式值陣列
                        $styleV=array();
                        
                        #以據每個樣式
                        foreach($conf["style"] as $styleName => $styleVal){
                                
                                #取得樣式名稱
                                $styleN[]=$styleName;
                                
                                #取得樣式值
                                $styleV[]=$styleVal;
                                
                                }#foreach end
                        
                        #函式說明: 
                        #建立給與html標籤使用的style屬性字串.
                        #回傳結果:
                        #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                        #$result["function"],當前執行的函數
                        #$result["error"],錯誤訊息陣列
                        #$result["content"],css設定內容
                        #必填參數:
                        $conf["css::styleStr"]["styleName"]=$styleN;#為屬性名稱,須為陣列值
                        $conf["css::styleStr"]["styleValue"]=$styleV;#為屬性值,須為陣列值
                        $styleStr=css::styleStr($conf["css::styleStr"]);
                        unset($conf["css::styleStr"]);
                        
                        #如果建立 style 字串失敗
                        if($styleStr["status"]==="false"){
                                
                                #設置執行失敗
                                $result["status"]="false";
                                
                                #設置錯誤訊息
                                $result["error"]=$styleStr;
                                
                                #回傳結果
                                return $result;
                                
                                }#if end
                                
                        #取得樣式字串
                        $style=$styleStr["content"];
                        
                        }#if end
                
                #如果未設置 mime type
                if(!isset($conf["mimeType"])){
                
                        #設置自動取得的mime tpye
                        $conf["mimeType"]=$getFileContent["mimeType"];
                
                        }#if end
                
                #設置 img 的 src 數值
                $result["content"]["imgWithoutImgTag"]="data:".$conf["mimeType"].";".$conf["compressType"].",".$getFileContent["base64data"];

                #放置圖片的語法
                $result["content"]["img"]="<img ".$style." ".$conf["alt"]." ".$conf["class"]." src=\"".$result["content"]["imgWithoutImgTag"]."\" >";
                
                #執行到這邊代表執行正常
                $result["status"]="true";
                
                #回傳結果
                return $result;
                
                }#function data end

        /*
        #函式說明:
        #建立用css樣式產生的圖片div或span區塊 
        #回傳結果:
        #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
        #$result["error"],錯誤訊息
        #$result["content"],圖片的連結資訊
        #$result["function"],當前執行的函數名稱 
        #必填參數:
        #$conf["imgAddr"],字串,圖片的位址.
        $conf["imgAddr"]="";
        #可省略參數:
        #$conf["imgClass"],字串,用來放置圖片的css類別樣式名稱.
        #$conf["imgClass"]=""
        #參考資料:
        #無.
        #備註:
        #建構中...
        */
        public static function cssContent(&$conf){
        
                #檢查參數
                
                
                #設置圖片的 css class
                
                
                #設置圖片區塊的 div
                
        
                $result["content"]="<div class=\"cssContnetImg\" style=\"content:url(https://start.fedoraproject.org/static/images/fedora-logo.png);width:200px;height:50px;\"></div>";
                
                $result["status"]="true";
                
                return $result;
                
                }#functin cssContent end

        }#class img end

#內建的繪圖函式

#劃綫
#參數1爲要畫在那張圖片上面,必須爲函式 imagecreate 製造的圖片才行
#參數2爲綫的x軸起點
#參數3爲綫的y軸起點
#參數4爲線的x軸終點
#參數5爲綫的y軸終點
#參數6爲線的顏色樣式,必須使用函式 imagecolorallocate 產生的顏色才行
#imageline($im, 0, 0, 200, 100, $red);

?>