-
Notifications
You must be signed in to change notification settings - Fork 2
/
printImage.py
49 lines (42 loc) · 1.9 KB
/
printImage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/python
#
# Sudoku Generator and Solver in 250 lines of python
# Copyright (c) 2006 David Bau. All rights reserved.
#
# Can be used as either a command-line tool or as a cgi script.
#
# As a cgi-script, generates puzzles and estimates their level of
# difficulty. Uses files sudoku-template.pdf/.ps/.txt/.html
# in which it can fill in 81 underscores with digits for a puzzle.
# The suffix of the request URL determines which template is used.
#
# On a command line without any arguments, prints text for a
# random sudoku puzzle, with an estimate of its difficulty.
# On a command line with a filename, solves the given puzzles
# (files should look like the text generated by the generator).
#
# Adapted for Adafruit_Thermal library by Phil Burgess for Adafruit
# Industries. This version uses bitmaps (in the 'gfx' subdirectory)
# to render the puzzle rather than text symbols. See sudoku-txt
# for a different Sudoku example that's all text-based.
from __future__ import print_function
import sys, os, random, getopt, re
from Adafruit_Thermal import *
from PIL import Image
from PrinterProject_book_recommend import gray_Scale
def printImage(nameImg):
printer = Adafruit_Thermal("/dev/serial0", 19200, timeout=5)
basewidth = 400
img = Image.open('ThermalVis/images/'+nameImg+'.png')
wpercent = (basewidth/float(img.size[0]))
hsize = int((float(img.size[1])*float(wpercent)))
#bg = Image.new("1", [282 , 271], "white") # Working 'background' image
bg = Image.new("1", [basewidth , hsize], "white") # Working 'background' image
img = img.resize((basewidth,hsize), Image.ANTIALIAS)
img.save('ThermalVis/images/'+nameImg+'.png')
imgGray = gray_Scale("ThermalVis/images/"+nameImg+".png")
imgGray = Image.open(imgGray)
# Crop number bitmaps out of source image
printer.printImage(imgGray, True) # This does the printing
printer.println()
printer.feed(3)