Support » Plugin: Star CloudPRNT for WooCommerce » Add custom images

  • Resolved Ko Takagi

    (@ko31)


    I’d like to print the orders with my custom image, for example store logo, QR code and more.

    Is it possible to make it happen?

    If you have any sample code or infomation, I’d love to hear it.

    Thank you.

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Contributor lawrenceowen

    (@lawrenceowen)

    @ko31

    There are a few possible solutions for this.

    You can use Star utilities to pre-store images into the Printer FlashROM (255 or more, depending on printer model) and trigger these with a logo command. This is the fastest printing method, and definitely recommended if the images will not change very often (like a store logo).

    I’ve been looking in to printing images from the WordPress media library. To do this, iw would be necessary to use an image manipulation library like GD, to read the image pixel data and convert it into the printer graphic printing commands. I can share with you code I’ve written in C++ or C# to do this, but haven’t tried with php yet. Depending on your environment, I can also share with you a Linux command line utility that will convert images into printer command data, or support the Star Markup Document language. I cant use this in a general purpose WordPress plugin, but if you are happy to install the cputil utility on your servers then you can use it in your own variant.

    You might also want to have a look at the Star PromoPRNT system, which will let you remotely manage end-of document coupons and graphics on your printers using Star Micronics Cloud Services.

    Finally, if your priority is a QR Code, the printers do have built-in Qr Code printing, I can help you with an extension to the printer control classes to print a Qr.

    Thread Starter Ko Takagi

    (@ko31)

    @lawrenceowen

    Thank you for your information.

    > Finally, if your priority is a QR Code, the printers do have built-in Qr Code printing, I can help you with an extension to the printer control classes to print a Qr.

    Now, my top priority is a QR Code, could you tell me how to use the extension?

    Thread Starter Ko Takagi

    (@ko31)

    @lawrenceowen

    For now, I’m trying CPUtil you told me about.

    Using this page as a reference, I was able to install the command, but I still don’t know how to use it from the plugin.
    https://cloudprnt.net/CloudPRNTSDK/Documentation/articles/cputil/cputil.html

    I found that I can generate binary data from an image with the following command, but how can I use that data from the plugin?

    
    cputil thermal2 dither scale-to-fit decode application/vnd.star.starprnt barcode.png outputdata.bin
    

    For example, I would like to print additional barcode data for each product below the product items on the current receipt.

    I would appreciate it if you could let me know.

    Thank you.

    • This reply was modified 1 year, 1 month ago by Ko Takagi.
    Plugin Contributor lawrenceowen

    (@lawrenceowen)

    @ko31 Sorry, I should have mentioned that there is not an existing integration with cputil. Although I would really love to use the Star Document Document Markup Language (SDML) for generating print jobs, it is just impractical for a typical WordPress site to expect them to install cputil.

    There are lots of ways you could potentially use cputil, but my suggested integration would require the following modifications:
    generate the receipt data using SDML instead of using the $printer object. This makes it easy to include images and QrCodes in your document.
    use php to call cputil as a a local process to convert the SDML data into printer native binary data
    store that converted data in the plugins print queue folder

    The printer would then pick up and print the document that was generated from an SDML.

    This is quite a significant modification, I only suggest it at all because I know that you are a developer.

    I hope, today to be able to provide an example of adding QrCode printing support to the $printer object, which is probably quicker/easier for you?

    Thread Starter Ko Takagi

    (@ko31)

    @lawrenceowen

    Thank you for helping.

    I’ll look into the way of using SDML that you mentioned.

    > I hope, today to be able to provide an example of adding QrCode printing support to the $printer object, which is probably quicker/easier for you?

    If you can tell me how to do that as well, that would be great. It might help us solve the problem faster.🙏

    • This reply was modified 1 year, 1 month ago by Ko Takagi.
    Plugin Contributor lawrenceowen

    (@lawrenceowen)

    @ko31

    Try adding the following function to both “cloudprnt/printer_star_line.inc.php” and “cloudprnt/printer_star_prnt.inc.php”.

    public function add_qr_code($error_correction, $cell_size, $data)
    {
    	$model = 2;
    	if($error_correction < 0) $error_correction = 0;
    	if($error_correction > 3) $error_correction = 3;
    	if($cell_size < 1) $cell_size = 1;
    	if($cell_size > 8) $cell_size = 8;
    	$data_length = strlen($data);
    
    	$set_model = sprintf("1B1D795330%02X", $model);
    	$set_error_level = sprintf("1B1D795331%02X", $error_correction);
    	$set_cell_size = sprintf("1B1D795332%02X", $cell_size);
    	$set_data_prefix = sprintf("1B1D79443100%02X%02X", fmod($data_length, 256), intval($data_length / 256));
    	$print = "1B1D7950";
    
    	$this->printJobBuilder .= $set_model
    		. $set_error_level
    		. $set_cell_size
    		. $set_data_prefix
    		. $this->str_to_hex($data)
    		. $print;
    }

    Then you can call $printer->add_qr_code($error_correction, $cell_size, $data) from within your order-handler.php.

    • $error_correction indicates how much error correction information to add to the Qr, from 0 (lowest) to 3(maximum). More error correction increases the size of the Qr.
    • $cell_size is the size in printer dots (1/8mm) of a single dot/module of the Qr.
    • $data is a string containing the data you want to encode. The printer will choose the most efficient data encoding method automatically.
    Thread Starter Ko Takagi

    (@ko31)

    @lawrenceowen

    That’s great! I tried it and was able to print QrCode.

    I’m grateful to you.

    If possible, could you please tell me how to print JAN13 (EAN13) as well?

    Plugin Contributor lawrenceowen

    (@lawrenceowen)

    @ko31

    Yes, the following function, added to the same files will give you a 2D barcode printing method.

    public function add_barcode($type, $module, $hri, $height, $data)
    {
    	$n2 = 1; 
    	$n3 = 1;
    
    	if($type < 0 || $type > 13)	return;	 // Invalid barcode type
    	if($hri) $n2 = 2; // Print human-readable characters under the bacrode
    			
    	if($type == 0 || $type == 1 || $type == 3 || $type == 4 || $type == 6 || $type == 7)    // UPC-E, UPC-A, JAN/EAN8, JAN/EAN13, Code128, Code 93
    	{
    		$n3 = $module - 1;
    		if($n3 < 1) $n3 = 1;
    		if($n3 > 3) $n3 = 3;
    	}
    	elseif ($type == 4 || $type == 5 || $type == 8)	 // Code 93, ITF, NW-7
    	{
    		$n3 = $module;
    		if($n3 < 1) $n3 = 1;
    		if($n3 > 9) $n3 = 9;
    	}
    	elseif ($type >= 9 && $type <= 13)  // GS1-128, GS1 DataBar
    	{
    		$n3 = $module;
    		if($n3 < 1) $n3 = 1;
    		if($n3 > 6) $n3 = 6;
    	}
    
    	if($height < 8) $height = 8;	  // Minimum 1mm height
    	if($height > 255) $height = 255;  // Max 32mm height
    
    	$print_bc = sprintf("1B62%02X%02X%02X%02X", $type, $n2, $n3, $height)
    		. $this->str_to_hex($data)
    		. "1E";
    
    	$this->printJobBuilder .= $print_bc;
    }
    • $type is the barcode type where – 0: UPC-E, 1: UPC-A, 2: JAN/EAN8, 3: JAN/EAN13, 4:Code 39, 5: ITF, 6:Code128, 7:Code93, 8:NW7, 9:GS1-128, 10 GS1 DataBar (Omnidirectional, 11: GS1 DataBar (Truncated) 12: GS1 DataBar (Limited), 13: GS1 Databar (Expanded)
    • $module is the width of the barcode bars, this parameter varies depending on the barcode type, for EAN13 it can be a value from 2 to 4 and represents the base module size in printer dots (1/8mm).
    • $hri set to true to print the human readable data value underneath the barcode
    • $height is the height of the barcode in 1/8mm printer dots, maximum 255.
    • $data is the barcode data – it is your responsibility to ensure that the data is valid for the requested barcode type. For JAN/EAN13 that means 12 or 13 numeric digits.
    Thread Starter Ko Takagi

    (@ko31)

    @lawrenceowen

    Great code! I was able to print 2D barcode.

    Thank you so much for your help as always.🙏

    Plugin Contributor lawrenceowen

    (@lawrenceowen)

    @ko31 Great, thanks for letting me know it’s working.

    I’ve included the Qr and Barcode methods in the base code, so from 2.0.3 (pre release version is here) you can use those methods without modifying the “cloudprnt/printer_*” files.

    Thread Starter Ko Takagi

    (@ko31)

    @lawrenceowen

    I really appreciate it. Thanks a million!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Add custom images’ is closed to new replies.