laitkor commited on
Commit
100080e
·
verified ·
1 Parent(s): 9b54af9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -1
app.py CHANGED
@@ -3,7 +3,37 @@ import os
3
  import zipfile
4
  from PIL import Image, ImageDraw, ImageFont
5
 
6
- def draw_ruler(image, dpi=72, font_size=144):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  """
8
  Draw a virtual ruler 10 cm from the bottom of the image.
9
  Args:
 
3
  import zipfile
4
  from PIL import Image, ImageDraw, ImageFont
5
 
6
+ def draw_ruler(image, dpi=72, unit="in", color="black"):
7
+ """
8
+ Draws a ruler on the top and left edges of an image.
9
+
10
+ Args:
11
+ image: The PIL Image object to draw on.
12
+ dpi: The DPI of the image (default 300).
13
+ unit: The unit of measurement (default "in").
14
+ color: The color of the ruler (default "black").
15
+ """
16
+
17
+ draw = ImageDraw.Draw(image)
18
+ width, height = image.size
19
+
20
+ # Draw top ruler
21
+ for i in range(0, width, int(dpi)):
22
+ x = i
23
+ draw.line((x, 0, x, 10), fill=color)
24
+ if i % int(dpi) == 0:
25
+ draw.text((x, 12), str(i // dpi), fill=color)
26
+
27
+ # Draw left ruler
28
+ for i in range(0, height, int(dpi)):
29
+ y = i
30
+ draw.line((0, y, 10, y), fill=color)
31
+ if i % int(dpi) == 0:
32
+ draw.text((12, y), str(i // dpi), fill=color)
33
+
34
+ return image
35
+
36
+ def draw_ruler1(image, dpi=72, font_size=144):
37
  """
38
  Draw a virtual ruler 10 cm from the bottom of the image.
39
  Args: