Skip to content

Instantly share code, notes, and snippets.

import sys
import glob
def testfunc (param):
return param
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
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])
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, 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
@fbuchinger
fbuchinger / gist:674212
Created November 12, 2010 15:26
OxJs - jQuery for your Bytes

OxJs - jQuery for your Bytes

OxJs (speak: HexaJs) is a utility library for javascript, that facilitates parsing and creation of binary data in Javascript. While this sounds weird in the first moment, there are a few areas where OxJs can come in handy:

  • If you need to transfer huge amounts of numercial data via AJAX, binary encoding can be much more space-efficient than transfering it in JSON. The number 41239 for example needs 5 Bytes in JSON, but only 2 Bytes in binary encoding (unsigned short). A more practical example is the The Google Maps Polyline Utility, which saves over 80% of the json payload by binary encoding. However, de- and encoding binary information can be a quite tricky and this is were OxJs helps.

  • For client-side file parsing: Recent enhancements in Javascript allow us byte access for to-be-uploaded files. This can be used to perform enhanced sanity che

@fbuchinger
fbuchinger / DateTime Tagger
Created April 17, 2011 21:51
Mockup implementation of a DateTime Tagger. Requires underscore.js and doesn't yet follow the pictagger.api. Use with care
function dateTagger(date) {
var months = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'];
var weekdays = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];
function getWeekOfYear(date) {
a = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() + 5);
b = new Date(a.getFullYear(), 0, 4);
return ~~ ((a - b) / 864e5 / 7 + 1.5);
}
@fbuchinger
fbuchinger / HolidayTagger
Created April 17, 2011 21:53
Mockup Implementation of a HolidayTagger with sample holiday data from the United States. Doesn't yet follow the pictagger api spec. Requires underscore.js
function holidayTagger(date) {
var dateYear = date.getFullYear();
var dateMonth = date.getMonth();
var dateDay = date.getDate();
var getEasterDate = _.memoize(function (year) {
var Y = year;
var C = Math.floor(Y / 100);
var N = Y - 19 * Math.floor(Y / 19);
var K = Math.floor((C - 17) / 25);
var I = C - Math.floor(C / 4) - Math.floor((C - K) / 3) + 19 * N + 15;
@fbuchinger
fbuchinger / .picasa.ini
Created July 9, 2011 18:26
.picasa.ini decoded
#==============================================================
# .picasa.ini FILE STRUCTURE
#
# reverse-engineered by Franz Buchinger <[email protected]>
# licensed to the public domain
#
# Picasa Version(s): 3.8.0
#
# Changelog:
# v0.1: initial release
@fbuchinger
fbuchinger / gist:1307476
Created October 23, 2011 15:29
datefromarray
dateFromArray = (dateArr) ->
[year, month, day , hour, minute, second, millisecond] = dateArr
(new Date (year, month || 0, day || 0, minute || 0, second || 0, millisecond || 0))