摘要:在線編輯使用到的插件根據(jù)信息繪制二維碼插件用于顏色選擇,綁定事件更改二維碼的顏色用于將格式的二維碼轉(zhuǎn)換成的,之后使用方法生成二維碼圖片的編碼數(shù)據(jù),通過(guò)發(fā)送給后端熱敏打印機(jī)打印二維碼圖片要轉(zhuǎn)成格式。
在線編輯
使用到的 js 插件:
qrcodesvg
根據(jù)信息繪制二維碼插件
colorPicker
用于顏色選擇,js綁定事件更改二維碼(svg)的顏色
canvg
用于將svg格式的二維碼轉(zhuǎn)換成 html5 的 canvas ,之后使用 toDataURL 方法生成二維碼圖片的 base64 編碼數(shù)據(jù) ,通過(guò) Ajax 發(fā)送給后端
熱敏打印機(jī)打印二維碼圖片要轉(zhuǎn)成BMP格式。轉(zhuǎn)換圖片到BMP的類(lèi):
BMP * * { Description :- * class that resize and convert jpg, gif or png to bmp * } * for more info contact with me (mahabub1212@yahoo.com) * you can modify or use or redistribute this class. */ class ToBmp{ // new image width var $new_width; // new image height var $new_height; // image resources var $image_resource; function image_info($source_image){ $img_info = getimagesize($source_image); switch ($img_info["mime"]){ case "image/jpeg": { $this->image_resource = imagecreatefromjpeg ($source_image); break; } case "image/gif": { $this->image_resource = imagecreatefromgif ($source_image); break; } case "image/png": { $this->image_resource = imagecreatefrompng ($source_image); break; } default: {die("圖片錯(cuò)誤");} } } public function imagebmp($file_path = ""){ if(!$this->image_resource) die("圖片錯(cuò)誤"); $picture_width = imagesx($this->image_resource); $picture_height = imagesy($this->image_resource); if(!imageistruecolor($this->image_resource)){ $tmp_img_reource = imagecreatetruecolor($picture_width,$picture_height); imagecopy($tmp_img_reource,$this->image_resource, 0, 0, 0, 0, $picture_width, $picture_height); imagedestroy($this->image_resource); $this->image_resource = $tmp_img_reource; } if((int) $this->new_width >0 && (int) $this->new_height > 0){ $image_resized = imagecreatetruecolor($this->new_width, $this->new_height); imagecopyresampled($image_resized,$this->image_resource,0,0,0,0,$this->new_width,$this->new_height,$picture_width,$picture_height); imagedestroy($this->image_resource); $this->image_resource = $image_resized; } $result = ""; $biBPLine = ((int) $this->new_width >0 &&(int)$this->new_height > 0) ? $this->new_width * 3 : $picture_width * 3; $biStride = ($biBPLine + 3) & ~3; $biSizeImage = ((int) $this->new_width >0 &&(int)$this->new_height > 0) ? $biStride * $this->new_height : $biStride * $picture_height; $bfOffBits = 54; $bfSize = $bfOffBits + $biSizeImage; $result .= substr("BM", 0, 2); $result .= pack ("VvvV", $bfSize, 0, 0, $bfOffBits); $result .= ((int) $this->new_width >0 &&(int)$this->new_height > 0) ? pack ("VVVvvVVVVVV", 40, $this->new_width, $this->new_height, 1, 24, 0, $biSizeImage, 0, 0, 0, 0) : pack ("VVVvvVVVVVV", 40, $picture_width, $picture_height, 1, 24, 0, $biSizeImage, 0, 0, 0, 0); $numpad = $biStride - $biBPLine; $h = ((int) $this->new_width >0 &&(int)$this->new_height > 0) ? $this->new_height : $picture_height; $w = ((int) $this->new_width >0 &&(int)$this->new_height > 0) ? $this->new_width : $picture_width; for ($y = $h - 1; $y >= 0; --$y) { for ($x = 0; $x < $w; ++$x) { $col = imagecolorat ($this->image_resource, $x, $y); $result .= substr(pack ("V", $col), 0, 3); } for ($i = 0; $i < $numpad; ++$i) { $result .= pack ("C", 0); } } if($file_path == ""){ header("Content-type: image/bmp"); echo $result; } else { $fp = fopen($file_path,"wb"); fwrite($fp,$result); fclose($fp); //============= } return ; } }
使用方法
$ToBMP = new ToBmp(); $ToBMP->image_info($path_to_img); $ToBMP->new_width = 255; $ToBMP->new_height = 255; $output_path = realpath(PATH."test.bmp"); $ToBMP->imagebmp($output_path);
BMP格式根據(jù)文件頭信息不同數(shù)據(jù)組成結(jié)構(gòu)也不同
我的是24位BMP,去除頭文件54個(gè)字節(jié)后,每三個(gè)字節(jié)(RGB)表示一個(gè)點(diǎn)。
合并RGB(三字節(jié)合并為一字節(jié))后二值化像素點(diǎn)(得到 1bit ,即該點(diǎn)是黑或白。之所以要二值化是因?yàn)槲业臒崦舸蛴C(jī)打印黑白不打印彩色)。
每 8bit 拼接成1字節(jié)后用 "xx" 的16進(jìn)制形式表示。數(shù)據(jù)根據(jù)打印機(jī)給的接口發(fā)送給打印機(jī)就可以打印了。
特別注意:1.unpack的使用
$content = file_get_contents($path_to_img); $content = unpack("H*", $content); //獲得圖片數(shù)據(jù)的16進(jìn)制表示
2.
‘xFE’ 表示的是4個(gè)字符
“xFE” 表示的是1個(gè)字符(即該16進(jìn)制數(shù)字對(duì)應(yīng)的ascii碼字符)
單引號(hào)的可使用 chr("0xFE") 進(jìn)行轉(zhuǎn)換
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://m.hztianpu.com/yun/20602.html
摘要:將信號(hào)拉高激活打印元件,接著使步進(jìn)電機(jī)轉(zhuǎn)動(dòng)兩步完成一點(diǎn)行的打印。步進(jìn)電機(jī)的步長(zhǎng)為,一點(diǎn)行的寬度為,因此打印出一點(diǎn)行的數(shù)據(jù)需要步進(jìn)電機(jī)轉(zhuǎn)兩步。由于步進(jìn)電機(jī)和熱敏頭不能長(zhǎng)時(shí)間連續(xù)工作,因此打印份數(shù)不宜設(shè)置過(guò)多,否則容易燒壞電機(jī)和熱敏頭。 ...
摘要:和要先打開(kāi),再在目錄下執(zhí)行,和在目錄下執(zhí)行注啟動(dòng),后臺(tái)代碼更改才會(huì)實(shí)時(shí)響應(yīng)有問(wèn)題可發(fā)郵箱,有看到有空會(huì)回 項(xiàng)目完整代碼 github地址:singleStore 效果圖: showImg(https://segmentfault.com/img/bVbgFMz?w=640&h=1136);showImg(https://segmentfault.com/img/bVbgFMA?w=64...
摘要:在網(wǎng)上搜了一些方法,做法是獲取二維碼元素賦值給整個(gè)的,然后再調(diào)用瀏覽器的打印功能,缺點(diǎn)是會(huì)改變整個(gè)頁(yè)面,需要刷新恢復(fù)。但問(wèn)題還不止于此,由于二維碼是在線生成的,獲取到的二維碼元素沒(méi)有實(shí)際內(nèi)容,所以這個(gè)方法不可行。 二維碼由jquery.qrcode.min.js將json字符串轉(zhuǎn)換而成,細(xì)節(jié)不再贅述,效果如圖:showImg(https://segmentfault.com/img/b...
摘要:配置需要一個(gè)來(lái)用于與虛擬機(jī)進(jìn)行連接,默認(rèn)假定這個(gè)密鑰會(huì)被放在文件夾下。三使用管理項(xiàng)目版本使用可以對(duì)我們的代碼進(jìn)行版本控制,如果萬(wàn)一誤刪了代碼想回到之前的情況,則可以通過(guò)版本控制進(jìn)行回滾。配置選項(xiàng)代表對(duì)進(jìn)行全局設(shè)置。 laravel學(xué)習(xí)筆記,重新梳理知識(shí)點(diǎn)。 一、環(huán)境配置 1、編輯器選用 Atom PHPStorm SublimeText Atom 是由 GitHub 官方在 201...
摘要:并發(fā)和并行并發(fā)和并行是兩個(gè)非常容易被混淆的概念。并發(fā)說(shuō)的是在一個(gè)時(shí)間段內(nèi),多件事情在這個(gè)時(shí)間段內(nèi)交替執(zhí)行。并行說(shuō)的是多件事情在同一個(gè)時(shí)刻同事發(fā)生。由于線程池是一個(gè)線程,得不到執(zhí)行,而被餓死,最終導(dǎo)致了程序死鎖的現(xiàn)象。 同步(Synchronous)和異步(Asynchronous) 同步和異步通常來(lái)形容一次方法調(diào)用,同步方法調(diào)用一旦開(kāi)始,調(diào)用者必須等到方法調(diào)用返回后,才能繼續(xù)后續(xù)的行為...
閱讀 1956·2023-04-26 00:47
閱讀 1628·2021-11-11 16:55
閱讀 2806·2021-09-27 14:04
閱讀 3638·2021-09-22 15:58
閱讀 3619·2021-07-26 23:38
閱讀 2202·2019-08-30 13:47
閱讀 2044·2019-08-30 13:15
閱讀 1246·2019-08-29 17:09