首頁  >  文章  >  後端開發  >  PHP透過文字傳遞創建的圖形按鈕

PHP透過文字傳遞創建的圖形按鈕

WBOY
WBOY原創
2016-08-08 09:33:51981瀏覽

透過文字傳遞建立圖形按鈕,說明請看文內詳細說明
    /* PHP3 按鈕產生器,(c) 2000 by IzzySoft (izzysoft@buntspecht.de)
    * 許可證:GPL(如果您找到了它,最好給我留言
    * 有用 - 如果你使用它。當然,我也非常感興趣
    * 您對腳本所做的改進!
    *
    * 目的:產生帶有參數傳遞文字的按鈕。
    *
    * 腳本可能的參數:
    *按鈕-輸入gif影像。只是檔案名稱中點號之前的部分。
    *指定的影像檔案需要在同一目錄中
    *這個腳本所在的位置。
    *font - 要使用的字體(1 - 5;1 非常小,3 中等,5 正常大小。
    *如果文字是
,腳本將自動使用較小的字體     *對於所選尺寸來說太長。 )預設值:5
    *text - 要放置在按鈕上的文字。將會居中。
    *textcolor - 字母的顏色。預設值:白色。
    *在此範例程式碼中僅定義了藍色、白色和黑色;
    *但您可以輕鬆新增自訂顏色。
    *width,heigth - 按鈕的寬度和高度。僅當目標有效時才有用
    *按鈕的大小應與來源影像不同。
    *
    * 使用範例:
    * PHP透過文字傳遞創建的圖形按鈕;
    * 將尋找 Yellow.gif 並在其上新增字串「Example」。
    *
    * 我通常會產生三個按鈕(其中一個顯示選定的
    * 項,一項用於 mouSEOver(),一項是預設按鈕)。來源
    * 圖像是 Yellow.gif、white.gif 和 blue.gif - 所以我的腳本假設
    * 如果未指定“button=”,則預設為 blue.gif - 您可能想要更改
    * 下面這個,很簡單;)
    */
    // =============================[檢查
    //     r 參數和/或設定預設值 ]===
    if (($font == "") || ($font > 5) || ($font     if ($text == "") { $text="Moin!"; }//按鈕文字
    if ($textcolor == "") {// 字母的顏色
    開關($按鈕){
    案例「黃色」:
    案例「白色」:
    $textcolor = "黑色";
    休息;
    預設:
    if ($button == "") { $button = "藍色"; }
    $textcolor = "白色";
    休息;
    }
    } // 文字顏色結束
    $im_info = getimagesize("$button.gif"); // 按鈕大小
    if ($width == "") {
    if ($im_info == "") {
    $按鈕寬度= 125;
    } 其他 {
    $buttonwidth = "$im_info[0]";
    }
    } 其他 {
    $按鈕寬度=$寬度;
    }
    if ($heigth == "") {
    if ($im_info == "") {
    $按鈕高度= 30;
    } 其他 {
    $buttonheigth = "$im_info[1]";
    }
    } 其他 {
    $buttonheigth = $heigth;
    }
    $vmidth = ceil($buttonheigth / 2);
    // =========================================
    //     ===[ 現在讓我們定義一些顏色 ]===
     
    $白色=「255,255,255」;
    $black = "0,0,0";
    $藍色 = "0x2c,0c6d,0xaf";
    // =========================================
    //     =============[建構顏色陣列]===
    // 現在我們將所需的顏色放入 a
    //     rray(例如“$textcolor=white”,
    // 陣列 $textcolor_array 代表
    //     「白色」)
    $textcolor_array = 爆炸(",", $$textcolor);
    // =======================[ 計算 po
    //     按鈕上文字的位置]===
    做{
    $textwidth = strlen($text) * imagefontwidth($font);
    $x = ($buttonwidth - $textwidth) / 2; $x = ceil($x);
    $y = $vmidth - (imagefontheight($font) / 2);
    $字體--;
    while (($x 0)); $字型++;
    // =========================================
    //     ======[ 現在我們建立按鈕 ]===
    if (isset($width) || isset($heigth)) {// 預期尺寸會改變?
    $ima = imagecreatefromgif("$button.gif");// 開啟輸入 gif
    $im = imagecreate($buttonwidth,$buttonheigth); // 建立所需大小的 img
    $uglybg = ImageColorAllocate($im,0xf4,0xb2,0xe5);
    ImageRectangle($im,0,0,$buttonwidth,$buttonheigth,$uglybg);
    $dummy = imagecopyresized($im,$ima,0,0,0,0,$buttonwidth,$buttonheigth,$im_info[0],$im_info[1]);
    if ($dummy == "") {
    影像銷毀($im); // 如果它不起作用,請在下方建立預設值
    } 其他 {;}
    ImageDestroy($ima);
    ImageColorTransparent($im,$uglybg);
    } 其他 {
    $im = imagecreatefromgif("$button.gif");// 開啟輸入 gif
    }
    if ($im == "") { $im = imagecreate($buttonwidth,$buttonheigth); // 若找不到輸入的 gif,
    $rblue = ImageColorAllocate($im, 0x2c,0x6D,0xAF);// 建立預設方塊
    ImageRectangle($im,0,0,200,100,$rblue);
    }
    $color = ImageColorAllocate($im, $textcolor_array[0], $textcolor_array[1], $textcolor_array[2]); // 分配顏色
    imagestring($im, $font, $x, $y, "$text", $color); // 將文字放在上面
    ImageGif($im);// 傳送按鈕至瀏覽器
    ImageDestroy($im);//釋放已使用的記憶體
    ? >         

以上就是介紹了PHP透過文字傳遞所創造的圖形按鈕,包括圖形按鈕方面的內容,希望對PHP教學有興趣的朋友能得到幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn