Advertisement
Guest User

print v2

a guest
May 3rd, 2017
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. from escpos.printer import Usb
  2. from PIL import Image
  3. import os, sys
  4.  
  5.  
  6. #########################################################
  7. # change these lines to adapt the script to your needs  #
  8. #########################################################
  9. file = "print.png"                                      # filename - adapt to your needs
  10. mm_h = 64                                               # width of the print - 64mm is the max our printer can handle in its current configuration
  11. #cutmode = 'PART'                                       # select if you want a full or partial cut
  12. cutmode = 'FULL'
  13. #########################################################
  14.  
  15. im = Image.open(file)                                   # read the image file
  16.  
  17. p = Usb(0x03f0, 0x0517)                                 # set device/vendor id
  18.  
  19. inch_h = mm_h*0.0393701                                 # some math following to scale the images correctly
  20. dpi_h = 203                                             # keeping the original ratio and scaling for maximum width
  21. dpi_v = 184                                             # manual says the vertical dpi should be 180 - 184 are needed for the correct aspect ratio
  22. size_h = int(inch_h * dpi_h)
  23. size_v = int(inch_h * (im.height/float(im.width)) * dpi_v)
  24. size = size_h, size_v
  25.  
  26. im = im.resize((size_h,size_v),Image.ANTIALIAS)         # resize the image
  27.  
  28. p.image(im)                                             # print
  29. p.cut(mode=cutmode)                                     # cut
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement