Online Editing Js plug-ins used: Qrcodesvg
Draw the QR code plugin colorPicker based on the information
Used for color selection, js binding event changes the color of the QR code (svg) canvg
It is used to convert a two-dimensional code in svg format to an html5 canvas, and then generate the base64 encoded data of the two-dimensional code image using the toDataURL method, and send the two-dimensional code to the backend thermal printer through Ajax to print the two-dimensional code.Convert the image to BMP format. Class for converting images to BMP:
-
- /**
- * Class jpg, gif, png ========> 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 ("image Error ");}
- }
- }
- Public function imagebmp ($ file_path = ''){
- If (! $ This-> image_resource) die ("image 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, $ 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 ('vvvvvvvvv ', 40, $ this-> new_width, $ this-> new_height, 1, 24, 0, $ biSizeImage, 0, 0, 0, 0 ): pack ('vvvvvvvvv ', 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;
- }
- }
Usage
- $ ToBMP = new ToBmp ();
- $ ToBMP-> image_info ($ path_to_img );
- $ ToBMP-> new_width = 255;
- $ ToBMP-> fig = 255;
- $ Output_path = realpath(PATH.'test.bmp ');
- $ ToBMP-> imagebmp ($ output_path );
The BMP format varies with the data structure based on the file header information. I have 24-bit BMP. after 54 bytes are removed from the header file, each three bytes (RGB) represent a vertex. After merging RGB (three bytes into one byte), the binarization pixel (1 bit, that is, the point is black or white. The reason for binarization is that my thermal printer prints black and white without printing color ). Each 8-bit is spliced into 1 byte and expressed in hexadecimal format of '\ xx. Data can be printed after being sent to the printer based on the interface provided by the printer. Note:1. Use of unpack
- $ Content = file_get_contents ($ path_to_img );
- $ Content = unpack ("H *", $ content); // Obtain the hexadecimal representation of image data
2. '\ XFE' indicates four characters "\ XFE" indicates 1 character (that is, the ascii character corresponding to the hexadecimal number) You can use chr ('0xfe ') to convert single quotes. |