File tree Expand file tree Collapse file tree 3 files changed +17
-3
lines changed
Expand file tree Collapse file tree 3 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -100,3 +100,5 @@ printer.close()
100100### Sending images to the printer
101101
102102Format: ` phomemo_printer -a bluetooth_address -c bluetooth_channel -i "/path/to/image.png" `
103+
104+ You can increase or decrease the brightness of the image using ` -b <float> ` - numbers < 1.0 decrease the brightness, and > 1.0 increase it.
Original file line number Diff line number Diff line change 22from .pixel_sans .charset import charset
33from .ESCPOS_constants import *
44import socket
5- from PIL import Image
5+ from PIL import Image , ImageEnhance
66
77
88class Printer :
@@ -140,12 +140,13 @@ def print_charset(self):
140140 self .print_text (char_string_split )
141141
142142 # from https://github.com/vivier/phomemo-tools
143- def print_image (self , image_path ):
143+ def print_image (self , image_path , brightness = None ):
144144 """
145145 Print an image
146146
147147 Args:
148148 image_path (str): Path to an image file to print
149+ brightness (float): Optionally decrease (< 1.0) or increase (> 1.0) image brightness
149150 """
150151 image = Image .open (image_path )
151152 if image .width > image .height :
@@ -158,6 +159,10 @@ def print_image(self, image_path):
158159 size = (IMAGE_WIDTH_BITS , int (image .height * IMAGE_WIDTH_BITS / image .width ))
159160 )
160161
162+ if brightness is not None :
163+ filter = ImageEnhance .Brightness (image )
164+ image = filter .enhance (brightness )
165+
161166 # black&white printer: dithering
162167 image = image .convert (mode = "1" )
163168
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ def main(args):
1111 elif args .text :
1212 printer .print_text (args .text )
1313 elif args .image :
14- printer .print_image (args .image )
14+ printer .print_image (args .image , args . brightness )
1515
1616 printer .close ()
1717
@@ -50,6 +50,13 @@ def cli():
5050 help = "The channel to connect to your bluetooth device on" ,
5151 required = True ,
5252 )
53+ parser .add_argument (
54+ "-b" ,
55+ "--brightness" ,
56+ type = float ,
57+ help = "Optionally alter image brightness before printing (< 1.0 - decrease brightness; > 1.0 - increase brightness)" ,
58+ required = False ,
59+ )
5360
5461 args = parser .parse_args ()
5562 main (args )
You can’t perform that action at this time.
0 commit comments