thinkphp5 + バーコードを生成するバーコードメソッド
1. 公式 Web サイトにアクセスしてクラス ライブラリ "https://www.barcodebakery.com/en/download" をダウンロードし、独自のバージョンを選択してダウンロードします。 ## 推奨チュートリアル:
thinkphp チュートリアル<?php namespace app\index\controller; use think\Controller; /** * 条形码操作类 */ class Barcode extends Controller { public function createBarcode() { $class_dir = VENDOR_PATH.'barcode/class/'; // Including all required classes require_once($class_dir.'BCGFontFile.php'); require_once($class_dir.'BCGColor.php'); require_once($class_dir.'BCGDrawing.php'); require_once($class_dir.'BCGcode39.barcode.php'); // Loading Font // 注意font和class是同一级文件夹 $font = new \BCGFontFile(VENDOR_PATH.'barcode/font/Arial.ttf', 18);// The arguments are R, G, B for color. $color_black = new \BCGColor(0, 0, 0); $color_white = new \BCGColor(255, 255, 255); $drawException = null; try { $code = new \BCGcode39(); $code->setScale(2); // Resolution $code->setThickness(30); // Thickness $code->setForegroundColor($color_black); // Color of bars $code->setBackgroundColor($color_white); // Color of spaces $code->setFont($font); // Font (or 0) 0不显示文字 $text = isset($_GET['text']) ? $_GET['text'] : 'HELLO'; $code->parse($text); // Text } catch(Exception $exception) { $drawException = $exception; } /* Here is the list of the arguments 1 - Filename (empty : display on screen) 2 - Background color */ $drawing = new \BCGDrawing('', $color_white); if($drawException) { $drawing->drawException($drawException); } else { $drawing->setBarcode($code); $drawing->draw(); } // Header that says it is an image (remove it if you save the barcode to a file) header('Content-Type: image/png'); header('Content-Disposition: inline; filename="barcode.png"'); // Draw (or save) the image into PNG format. $drawing->finish(\BCGDrawing::IMG_FORMAT_PNG); } public function barcodedes() { return $this->fetch(); } } ?>

<img src="/static/imghw/default1.png" data-src="{:url('createBarcode')}" class="lazy" alt="thinkphp5 + バーコードを生成するバーコードメソッド" >
もちろん、srcパラメータも指定できます。次のコードを変更するだけです。 html code
<img src="/static/imghw/default1.png" data-src="{:url('createBarcode',array('text'= alt="thinkphp5 + バーコードを生成するバーコードメソッド" >'123'))}" class="lazy" >

change
$text = isset($_GET['text']) ? $_GET['text'] : 'HELLO';
を
$text = input('text'); //接收的参数
// 文件路径 $file_dir = 'uploads/barcode/'.date('Y-m-d'); if (!file_exists($file_dir)) { mkdir($file_dir,0755,true); } $imgUrl = $file_dir.'/'.time().'.png'; $class_dir = VENDOR_PATH.'barcode/class/'; // Including all required classes require_once($class_dir.'BCGFontFile.php'); require_once($class_dir.'BCGColor.php'); require_once($class_dir.'BCGDrawing.php'); require_once($class_dir.'BCGcode39.barcode.php'); // Loading Font // 注意font和class是同一级文件夹 $font = new \BCGFontFile(VENDOR_PATH.'barcode/font/Arial.ttf', 18); // Don't forget to sanitize user inputs // $text = isset($_GET['text']) ? $_GET['text'] : 'HELLO'; // The arguments are R, G, B for color. $color_black = new \BCGColor(0, 0, 0); $color_white = new \BCGColor(255, 255, 255); $drawException = null; try { $code = new \BCGcode39(); $code->setScale(2); // Resolution $code->setThickness(30); // Thickness $code->setForegroundColor($color_black); // Color of bars $code->setBackgroundColor($color_white); // Color of spaces $code->setFont($font); // Font (or 0) $text = input('text'); //接收的参数 $text = isset($text) ? $text :'无参数'; $code->parse($text); // Text } catch(Exception $exception) { $drawException = $exception; } /* Here is the list of the arguments 1 - Filename (empty : display on screen) 2 - Background color */ // 保存到本地 (路径,颜色)路径为空则表示显示到页面上 $drawing = new \BCGDrawing($imgUrl, $color_white); if($drawException) { $drawing->drawException($drawException); } else { $drawing->setBarcode($code); $drawing->draw(); } $drawing->finish(\BCGDrawing::IMG_FORMAT_PNG);
以上がthinkphp5 + バーコードを生成するバーコードメソッドの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

メモ帳++7.3.1
使いやすく無料のコードエディター

SublimeText3 中国語版
中国語版、とても使いやすい

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

ホットトピック











Pagoda に thinkphp5 をデプロイするときに報告されたエラーの解決策: 1. Pagoda サーバーを開き、php pathinfo 拡張機能をインストールして有効にします; 2. 「.access」ファイルをコンテンツ「RewriteRule ^(.*)$index.php」で構成します。 ?s=/$1 [QSA ,PT,L]”; 3. Web サイト管理で、thinkphp の疑似静的機能を有効にするだけです。

thinkphp5 の URL 書き換えが機能しない場合の解決策: 1. mod_rewrite.so モジュールが httpd.conf 設定ファイルにロードされているかどうかを確認します; 2.AllowOverride None の None を All に変更します; 3. Apache 設定ファイル .htaccess を「RewriteRule ^」に変更します(.*)$index.php [L,E=PATH_INFO:$1]」を選択して保存します。

thinkphp5 が要求された URL を取得するためのメソッド: 1. "\think\Request" クラスの "$request = Request::instance();" メソッドを使用して、現在の URL 情報を取得します。 2. 組み込みヘルパーを使用します。関数「$request-> url()」を使用して、ドメイン名を含む完全な URL アドレスを取得します。

thinkphp5 タイトル バー アイコンを削除する方法: 1. thinkphp5 フレームワーク public で favicon.ico ファイルを見つけます; 2. ファイルを削除するか、別の画像を選択して名前を favicon.ico に変更し、元の favicon.ico ファイルを置き換えます。

TP5 が strpos 関数を使用してヘッダーの content-type 値で app/json 文字列を検索するため、thinkphp5 post は値を取得できません。解決策は、ヘッダーの content-type 値を app/json に設定することです。

thinkphp5 でコントローラーが存在しないというプロンプトが表示される場合の解決策: 1. 対応するコントローラーの名前空間が正しく記述されているかどうかを確認し、正しい名前空間に変更します; 2. 対応する tp ファイルを開いてクラス名を変更します。

ThinkPHP5 で昨日のデータをクエリする方法: 1. ThinkPHP5 関連ファイルを開きます; 2. 式「db('table')->whereTime('c_time', 'yesterday')->select();」を使用して昨日のデータをクエリします。 。

thinkphp5 でエラー プロンプトを設定する方法: 1. プロジェクト ルート ディレクトリのパブリック フォルダーに入り、index.php エントリ ファイルを開きます; 2. デバッグ モード スイッチに関するコメントを表示します; 3. 「APP_DEBUG」定数の値を調整しますtrue に設定すると、エラー メッセージ プロンプトが表示されます。
