Skip to content

Instantly share code, notes, and snippets.

import sys
from PIL import Image, ImageOps
from pydmtx import DataMatrix
if __name__ == '__main__':
dmtx_image = Image.open(sys.argv[1])
dmtx_image.thumbnail((1060, 1500))
(width, height) = dmtx_image.size
dmtx_cropped = dmtx_image.crop((0,int(height*(0.667)), width, height))
dmtx_cropped = ImageOps.expand(dmtx_cropped, 20, "white") #add 20px white border around img as quiet zone
import sys
from PIL import Image
from pydmtx import DataMatrix
if __name__ == '__main__':
dmtx_image = Image.open(sys.argv[1])
dmtx_image.thumbnail((1060, 1500)) #"in-place" downscaling to 1060x1500 px
(width, height) = dmtx_image.size
dmtx_cropped = dmtx_image.crop((0,int(height*(0.667)), width, height)) # crop needs a left-top-right-bottom bounding box
(cropped_width, cropped_height) = dmtx_cropped.size
import sys
from PIL import Image
from pydmtx import DataMatrix
if __name__ == '__main__':
dmtx_image = Image.open(sys.argv[1])
(width, height) = dmtx_image.size
dm_read = DataMatrix(max_count = 1, timeout = 1500) # find max 1 dmtx code, stop after 1.5 secs
dmtx_code = dm_read.decode (width, height, buffer(dmtx_image.tostring()))
if dmtx_code is not None:
import sys
from PIL import Image
from pydmtx import DataMatrix
if __name__ == '__main__':
dmtx_image = Image.open(sys.argv[1])
(width, height) = dmtx_image.size
dm_read = DataMatrix()
dmtx_code = dm_read.decode (width, height, buffer(dmtx_image.tostring()))
if dmtx_code is not None:
import sys
import glob
def testfunc (param):
return param