In [2]:
import sys

In [3]:
!{sys.executable} -m pip install pyStrich


Collecting pyStrich
  Downloading https://files.pythonhosted.org/packages/a6/e1/76feba239737895214b5066177f6e01055083632b49312c271b1b2936f9e/pyStrich-0.8.tar.gz (981kB)
Requirement already satisfied: Pillow in c:\programdata\anaconda3\lib\site-packages (from pyStrich)
Collecting olefile (from Pillow->pyStrich)
  Downloading https://files.pythonhosted.org/packages/d3/8a/e0f0e56d6a542dd987f9290ef7b5164636ee597ce8c2932c19c78292d5ec/olefile-0.45.1.zip (112kB)
Building wheels for collected packages: pyStrich, olefile
  Running setup.py bdist_wheel for pyStrich: started
  Running setup.py bdist_wheel for pyStrich: finished with status 'done'
  Stored in directory: C:\Users\richa\AppData\Local\pip\Cache\wheels\e7\be\0c\8fe0bd5d5163e625d2904f676b7fd6456f63f5907115a244a7
  Running setup.py bdist_wheel for olefile: started
  Running setup.py bdist_wheel for olefile: finished with status 'done'
  Stored in directory: C:\Users\richa\AppData\Local\pip\Cache\wheels\dd\c5\34\b60edd3f8a0b5efd99ed392faacff6027ea37e27bbdd6949dd
Successfully built pyStrich olefile
Installing collected packages: pyStrich, olefile
Successfully installed olefile-0.45.1 pyStrich-0.8
You are using pip version 9.0.1, however version 10.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

In [4]:
"""Example code for datamatrix library"""
__revision__ = "$Revision$"

from pystrich.datamatrix import DataMatrixEncoder
import sys
import logging
import os.path
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir))

logging.getLogger("datamatrix").setLevel(logging.DEBUG)
logging.getLogger("datamatrix").addHandler(logging.StreamHandler(sys.stdout))

if __name__ == "__main__":
    encoder = DataMatrixEncoder(sys.argv[1])
    encoder.save("test.png")
    print(encoder.get_ascii())
    with open("test.dxf", "w") as text_file:
        text_file.write(encoder.get_dxf(inverse=True, cellsize=0.1))


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-4-8f4e8c24d1f5> in <module>()
      6 import logging
      7 import os.path
----> 8 sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir))
      9 
     10 logging.getLogger("datamatrix").setLevel(logging.DEBUG)

NameError: name '__file__' is not defined

In [5]:
from pystrich.datamatrix import DataMatrixEncoder

In [6]:
import sys

In [7]:
import logging

In [8]:
import os.path

In [9]:
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir))


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-9-8891cf2a8bdf> in <module>()
----> 1 sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir))

NameError: name '__file__' is not defined

In [10]:
logging.getLogger("datamatrix").setLevel(logging.DEBUG)

In [11]:
logging.getLogger("datamatrix").addHandler(logging.StreamHandler(sys.stdout))

In [12]:
if __name__ == "__main__":
    encoder = DataMatrixEncoder(sys.argv[1])
    encoder.save("test.png")
    print(encoder.get_ascii())
    with open("test.dxf", "w") as text_file:
        text_file.write(encoder.get_dxf(inverse=True, cellsize=0.1))


ascii:   "-" ==> 46
ascii:   "f" ==> 103
Unpadded data size:   2 bytes
Pad size: 1 bytes
Word size after padding: 3 bytes
Error word length: 5 bytes
Codewords: 46 103 129 170 17 74 248 46
Matrix size will be 8
                            
                            
    XX  XX  XX  XX  XX      
    XX  XX    XXXX  XXXX    
    XXXX          XX        
    XXXXXXXX  XX      XX    
    XXXX  XX    XXXX        
    XX      XX    XXXXXX    
    XXXX  XX  XX  XXXX      
    XXXXXXXX  XXXX  XXXX    
    XX          XX          
    XXXXXXXXXXXXXXXXXXXX    
                            
                            

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-12-bfa38aeaee7e> in <module>()
      4     print(encoder.get_ascii())
      5     with open("test.dxf", "w") as text_file:
----> 6         text_file.write(encoder.get_dxf(inverse=True, cellsize=0.1))

AttributeError: 'DataMatrixEncoder' object has no attribute 'get_dxf'

In [14]:
from pystrich.datamatrix import DataMatrixEncoder
encoder = DataMatrixEncoder("This is a DataMatrix.")
encoder.save( "datamatrix_test.png" )
print(encoder.get_ascii())


ascii:   "T" ==> 85
ascii:   "h" ==> 105
ascii:   "i" ==> 106
ascii:   "s" ==> 116
ascii:   " " ==> 33
ascii:   "i" ==> 106
ascii:   "s" ==> 116
ascii:   " " ==> 33
ascii:   "a" ==> 98
ascii:   " " ==> 33
ascii:   "D" ==> 69
ascii:   "a" ==> 98
ascii:   "t" ==> 117
ascii:   "a" ==> 98
ascii:   "M" ==> 78
ascii:   "a" ==> 98
ascii:   "t" ==> 117
ascii:   "r" ==> 115
ascii:   "i" ==> 106
ascii:   "x" ==> 121
ascii:   "." ==> 47
Unpadded data size:   21 bytes
Pad size: 1 bytes
Word size after padding: 22 bytes
Error word length: 18 bytes
Codewords: 85 105 106 116 33 106 116 33 98 33 69 98 117 98 78 98 117 115 106 121 47 129 184 210 67 89 228 224 4 157 190 90 216 105 92 51 255 126 181 147
Matrix size will be 18
                                                
                                                
    XX  XX  XX  XX  XX  XX  XX  XX  XX  XX      
    XX  XX  XX  XXXX    XX  XX      XX  XXXX    
    XXXX  XX    XX    XXXX    XXXXXX    XX      
    XX    XXXX      XXXX  XXXX        XX  XX    
    XX    XX    XXXX      XX  XX                
    XXXXXX  XX  XX  XX  XXXX  XXXXXX    XXXX    
    XXXX  XX          XXXX  XXXX    XX  XX      
    XXXX      XX  XXXXXX  XXXX        XXXXXX    
    XX    XX      XX  XXXXXX    XX  XX  XX      
    XX  XX    XXXX  XX  XXXX    XXXXXX    XX    
    XXXX      XX  XX    XXXX  XXXXXX  XX        
    XX  XX  XXXXXX  XX    XX  XXXX  XX    XX    
    XX          XX      XXXX  XX  XXXXXXXX      
    XXXXXX  XXXXXX  XXXX  XXXXXXXXXXXX    XX    
    XX  XXXXXX  XX    XX      XXXXXXXX          
    XX    XX    XX  XX  XX    XXXXXXXXXX  XX    
    XX  XXXXXXXX  XX    XXXXXX  XX  XX  XX      
    XX  XX        XXXX  XX  XXXX  XX      XX    
    XXXX  XX  XXXX    XX      XX  XXXX          
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX    
                                                
                                                


In [33]:
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw

In [49]:
img = Image.open('datamatrix_test.png')
width, height = img.size
msg = "sample text"
w,h = draw.textsize(msg)
draw = ImageDraw.Draw(img)
draw.text((((width-w)/2),(height-h)),msg)
img.show()

In [ ]: