forked from thehovdev/print-py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint.py
52 lines (40 loc) · 1.57 KB
/
print.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
48
49
50
51
52
import os
import sys
import loadconfig
from PIL import Image
from urllib.request import urlretrieve
from urllib.parse import urlparse
from threading import Thread
def get_filename(url_address):
filename = urlparse(url_address)
return os.path.basename(filename.path)
# Function for print file
def print_file(file):
os.startfile(file, "print")
# Function for check if image is in RGB color format
def file_color_mode(file):
image = Image.open(file)
mode = image.mode
print('File details:%s\nColor mode: %s' % file, mode)
return mode
# Function for translate RGB image to CMYK image
def translate_image(image, output_filename):
Image.open(image).convert('CMYK').save(output_filename)
os.chdir(loadconfig.directory)
url = sys.argv[1].replace(loadconfig.proto, "")
current_filename = get_filename(url)
new_filename = "cmyk-%s" % current_filename
urlretrieve(url, current_filename)
if file_color_mode(current_filename) != "CMYK":
# translate image color to CMYK and print
translate_image(current_filename, new_filename)
print ("File successfully converted")
file_color_mode(new_filename)
# Новый поток нужен для того чтобы после закрытия основной программы
# не закрывалось окно печати
print_new_file = Thread(target=print_file(new_filename))
print_new_file.start()
else:
print_current_file = Thread(target=print_file(current_filename))
print_current_file.start()
file_color_mode(current_filename)