-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.py
More file actions
71 lines (63 loc) · 2.38 KB
/
functions.py
File metadata and controls
71 lines (63 loc) · 2.38 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from tkinter import *
from PIL import Image, ImageTk
#place an image on the grid
def display_logo(url, row, column):
img = Image.open(url)
#resize image
img = img.resize((int(img.size[0]/1.5),int(img.size[1]/1.5)))
img = ImageTk.PhotoImage(img)
img_label = Label(image=img, bg="white")
img_label.image = img
img_label.grid(column=column, row=row, rowspan=2, sticky=NW, padx=20, pady=40)
def display_icon(url, row, column, stick, funct):
icon = Image.open(url)
#resize image
icon = icon.resize((20,20))
icon = ImageTk.PhotoImage(icon)
icon_label = Button(image=icon,command=funct, width=25, height=25)
icon_label.image = icon
icon_label.grid(column=column, row=row,sticky=stick)
#place a tebox on the pages
def display_textbox(content, ro, col, root):
text_box = Text(root, height=10, width=30, padx=10, pady=10)
text_box.insert(1.0, content)
text_box.tag_configure("center", justify="center")
text_box.tag_add("center", 1.0, "end")
text_box.grid(column=col, row=ro, sticky=SW, padx=25, pady=25)
#Detect Images inside the PDF document
#Thank you sylvain of Stackoverflow
def extract_images(page):
images = []
if '/XObject' in page['/Resources']:
xObject = page['/Resources']['/XObject'].getObject()
for obj in xObject:
if xObject[obj]['/Subtype'] == '/Image':
size = (xObject[obj]['/Width'], xObject[obj]['/Height'])
data = xObject[obj].getData()
mode = ""
if xObject[obj]['/ColorSpace'] == '/DeviceRGB':
mode = "RGB"
else:
mode = "CMYK"
img = Image.frombytes(mode, size, data)
images.append(img)
return images
def resize_image(img):
width, height = int(img.size[0]), int(img.size[1])
if width > height:
height = int(300/width*height)
width = 300
elif height > width:
width = int(250/height*width)
height = 250
else:
width, height = 250,250
img = img.resize((width, height))
return img
def display_images(img):
img = resize_image(img)
img = ImageTk.PhotoImage(img)
img_label = Label(image=img, bg="red")
img_label.image = img
img_label.grid(row=4, column=2, rowspan=2)
return img_label