QR コードをオンラインで編集し、サーマル プリンターに送信して印刷します。

WBOY
リリース: 2016-07-25 08:46:27
オリジナル
2656 人が閲覧しました
オンライン編集

使用されるJSプラグイン:

qrコードvg

情報をもとにQRコードを描画するプラグイン カラーピッカー

色の選択に使用され、QR コードの色を変更する js バインディング イベント (svg)

svg 形式の QR コードを html5 キャンバスに変換し、toDataURL メソッドを使用して QR コード画像の Base64 エンコード データを生成し、Ajax 経由でバックエンドに送信するために使用されます。 サーマルプリンターでQRコードを印刷

画像はBMP形式に変換する必要があります。画像を BMP に変換するためのクラス:

  1. /**
  2. * クラス jpg、gif、png =========> BMP
  3. *
  4. * { 説明 :-
  5. * jpg、gif、または png をサイズ変更して bmp に変換するクラス
  6. * }
  7. * 詳細については、私 (mahabub1212@yahoo.com) までお問い合わせください
  8. * 変更、使用、再配布できますこのクラス
  9. */
  10. class ToBmp{
  11. // 新しい画像の幅
  12. var $new_width;
  13. // 新しい画像の高さ
  14. var $new_height;
  15. //画像リソース
  16. var $image_resource;
  17. function image_info($source_image){
  18. $img_info = getimagesize($source_image);
  19. switch ($img_info['mime']){
  20. case "image/jpeg": { $this ->image_resource = imagecreatefromjpeg ($source_image); }
  21. case "image/gif": { $this->image_resource = imagecreatefromgif ($source_image) }
  22. case "image/png"; ->image_resource = imagecreatefrompng ($source_image); }
  23. デフォルト: {die("画像エラー");}
  24. }
  25. }
  26. public function imagebmp($file_path = ''){
  27. if(! $this->image_resource) die("画像エラー");
  28. $picture_width = imagex($this->image_resource);
  29. $picture_height = imagey($this->image_resource);
  30. if(!imageistruecolor ($this->image_resource)){
  31. $tmp_img_resource = imagecreatetruecolor($picture_width,$picture_height);
  32. imagecopy($tmp_img_reource,$this->image_resource, 0, 0, 0, 0, $picture_width, $picture_height) ;
  33. imagedestroy($this->image_resource);
  34. $this->image_resource = $tmp_img_resource;
  35. }
  36. if((int) $this->new_width >0 && (int) $this- >new_height > 0){
  37. $image_resize = imagecreatetruecolor($this->new_width, $this->new_height);
  38. imagecopyresampled($image_resize,$this->image_resource,0,0,0,0) ,$this->new_width,$this->new_height,$picture_width,$picture_height);
  39. imagedestroy($this->image_resource);
  40. $this->image_resource = $image_resize;
  41. }
  42. $ result = '';
  43. $biBPLine = ((int) $this->new_width >0 &&(int)$this->new_height > 0) $this->new_width * 3 : $picture_width * 3;
  44. $biStride = ($biBPLine + 3) & ~3;
  45. $biSizeImage = ((int) $this->new_width >0 &&(int)$this->new_height > 0) ? * $this->new_height : $biStride * $picture_height;
  46. $bfOffBits = 54;
  47. $bfSize = $bfOffBits + $biSizeImage;
  48. $result .= substr('BM', 0, 2);
  49. $result .= パック ('VvvV', $bfSize, 0, 0, $bfOffBits);
  50. $result .= ((int) $this->new_width >0 &&(int)$this->new_height > 0 ) ? パック ('VVVvvVVVVVV', 40, $this->new_width, $this->new_height, 1, 24, 0, $biSizeImage, 0, 0, 0, 0) : パック ('VVVvvVVVVVV', 40, $picture_width, $picture_height, 1, 24, 0, $biSizeImage, 0, 0, 0, 0);
  51. $numpad = $biStride - $biBPLine;
  52. $h = ((int) $this->new_width >0 &&(int)$this->new_height > 0) ? $this->new_height : $picture_height;
  53. $w = ((int) $this->new_width >0 &&(int)$ this->new_height > 0) ? $this->new_width : $picture_width;
  54. for ($y = $h - 1; $y >= 0; --$y) {
  55. for ($x) = 0; $x < $w ++$x) {
  56. $col = image_resource, $x, $y);
  57. $result('V', $ Col), 0, 3);
  58. }
  59. for ($i = 0; $i < $numpad; ++$i) {
  60. $result .= Pack ('C', 0);
  61. }
  62. }
  63. if($file_path == ''){
  64. header("Content-type: image/bmp");
  65. echo $result;
  66. } else {
  67. $fp = fopen($file_path,"wb") ;
  68. fwrite($fp,$result);
  69. fclose($fp);
  70. //=============
  71. }
  72. return
  73. }
  74. }
コードをコピー

使用方法

  1. $ToBMP = new ToBmp();
  2. $ToBMP->image_info($path_to_img);
  3. $ToBMP->new_width = 255;
  4. $ToBMP->new_height = 255;
  5. $output_path = realpath( PATH.'test.bmp');
  6. $ToBMP->imagebmp($output_path);
コードをコピー

BMP 形式には、異なるファイルヘッダー情報に基づいた異なるデータ構成構造があります

QR コードをオンラインで編集し、サーマル プリンターに送信して印刷します。

私のものは 24 ビット BMP で、ヘッダー ファイルの 54 バイトを削除した後、3 バイトごと (RGB) がポイントを表します。

RGB (3 バイトを 1 バイトに) を結合し、ピクセルを 2 値化します (1 ビットを取得します。つまり、ポイントは黒または白です。2 値化の理由は、サーマル プリンターが白黒で印刷するがカラーでは印刷しないためです)。

各 8 ビットは 1 バイトに連結され、「xx」の 16 進形式で表現されます。プリンタが提供するインターフェースに従い、データをプリンタに送信することで印刷することができます。

注意してください:

1.unpackの使い方

  1. $content = file_get_contents($path_to_img);
  2. $content = unpack("H*", $content) //画像データの 16 進表現を取得します
コードをコピーします

2.

「xFE」は4文字を表します

「xFE」は1文字(つまり、16進数に対応するASCIIコード文字)を表します

単一引用符は chr('0xFE') を使用して変換できます

プリンター印刷


ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!