Online editing JS Plugin to use: Qrcodesvg
Draw two-dimensional code plug-in colorpicker based on information
For color selection, JS binding event Change the color of the QR Code (SVG) CANVG
Used to convert the SVG format QR code into a HTML5 canvas, and then use the Todataurl method to generate the base64 encoded data of a two-dimensional code image, and send the QR code to the backend thermal printer via AjaxPicture to be converted into BMP format. To convert a picture to a BMP class:
-
- /**
- * Class jpg, GIF, PNG =========> BMP
- *
- * {Description:-
- * Class that resize and convert jpg, GIF or PNG to BMP
- * }
- * for + 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);
- Case "Image/gif": {$this->image_resource = imagecreatefromgif ($source _image);
- Case "Image/png": {$this->image_resource = imagecreatefrompng ($source _image);
- Default: {die ("Picture error");}
- }
- }
- Public Function imagebmp ($file _path = ") {
- if (! $this->image_resource) die ("Picture error");
- $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) & ~;
- $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 ', Max, $this->new_width, $this->new_height, 1, 0, $biSizeImage, 0, 0, 0, 0): Pack (' VVVVVVVVV VV ', _width, $picture, $picture _height, 1, 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;
- }
- }
Copy CodeHow to use
- $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);
Copy CodeBMP format According to file header information different data composition structure is also different My is 24-bit BMP, after removing the header file 54 bytes, each three bytes (RGB) represents a point. Merge RGB (three bytes merged into one byte) after two to value the pixel point (get 1bit, that is, the point is black or white. The reason for the binary is because my thermal printer printing black and white does not print color. Each 8bit is stitched into 1 bytes and is represented by the ' \xx ' 16 binary form. The data is sent to the printer according to the interface that the printer sends to print. Special attention:Use of 1.unpack
- $content = file_get_contents ($path _to_img);
- $content = Unpack ("h*", $content); Get 16 binary representations of picture data
Copy Code2. ' \xfe ' represents 4 characters "\xfe" represents 1 characters (that is, the ASCII character corresponding to the 16 binary digits) Single quotes can be converted using Chr (' 0xFE ') |