Skip to content

Commit

Permalink
Merge pull request #195 from TeaM-TL/arrow
Browse files Browse the repository at this point in the history
Arrow
  • Loading branch information
TeaM-TL authored Nov 3, 2024
2 parents 6f16d7c + 6c4206d commit fb210ca
Showing 18 changed files with 4,861 additions and 1,435 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -7,4 +7,4 @@ fotokilof/__pycache__/*
fotokilof/.coverage
.DS_Store
FotoKilof.egg-info/*

.coverage
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@

## 2024

5.1.1 add arrow into text if needed. Pillow works

5.1.0 use FindSystemFontsFilename for Pillow instead own ideas like cflist

5.0.7 real fix problem with path with colon, dot etc.
12 changes: 12 additions & 0 deletions fotokilof/__main__.py
Original file line number Diff line number Diff line change
@@ -441,6 +441,7 @@ def apply_all_button():
e_text_x.get(),
e_text_y.get(),
e_text.get(),
img_text_arrow.get(),
)
clone = convert_common.text(convert_text_data, PILLOW)
if img_logo_on.get():
@@ -751,6 +752,7 @@ def convert_text_button():
e_text_x.get(),
e_text_y.get(),
e_text.get(),
img_text_arrow.get(),
)
clone = convert_common.text(convert_text_data, PILLOW)
convert_common.save_close_clone(
@@ -1100,6 +1102,7 @@ def ini_read_wraper():
img_text_gravity_onoff.set(ini_entries["img_text_gravity_onoff"])
img_text_box.set(ini_entries["text_box"])
img_text_box_color.set(ini_entries["text_box_color"])
img_text_arrow.set(ini_entries["text_arrow"])
l_text_color.configure(fg=img_text_color.get(), bg=img_text_box_color.get())
img_text_rotate.set(ini_entries["text_rotate"])
e_text.delete(0, "end")
@@ -1263,6 +1266,7 @@ def ini_save_wraper():
"y": e_text_y.get(),
"text_rotate": img_text_rotate.get(),
"text_rotate_own": e_text_angle.get(),
'text_arrow': img_text_arrow.get(),
}
# rotate
rotate = {
@@ -1804,6 +1808,7 @@ def text_tool_hide_show():
rb_text_S.grid_remove()
rb_text_SE.grid_remove()
cb_text_gravity.grid_remove()
cb_text_arrow.grid_remove()
frame_text_rotate.grid_remove()
else:
# Inside
@@ -1812,6 +1817,7 @@ def text_tool_hide_show():
e_text_x.grid()
e_text_y.grid()
cb_text_gravity.grid()
cb_text_arrow.grid()
if img_text_gravity_onoff.get():
# Gravity on
rb_text_NW.grid()
@@ -1897,6 +1903,7 @@ def text_tool_hide_show():
img_text_box_color = StringVar()
img_text_inout = IntVar() # Text inside or outside picture
img_text_rotate = IntVar()
img_text_arrow = IntVar()
img_rotate_on = IntVar() # Rotate
img_rotate = IntVar()
img_rotate_own = IntVar()
@@ -2497,6 +2504,9 @@ def text_tool_hide_show():
cb_text_box = ttk.Checkbutton(
frame_text, text=_("Background"), variable=img_text_box, onvalue="1", offvalue="0"
)
cb_text_arrow = ttk.Checkbutton(
frame_text, text=_("Arrow"), variable=img_text_arrow, onvalue="1", offvalue="0"
)
cb_text_gravity = ttk.Checkbutton(
frame_text,
text=_("Gravity"),
@@ -2519,6 +2529,7 @@ def text_tool_hide_show():
rb_text_in.grid(row=3, column=1, sticky=W, padx=5, pady=1)
if not PILLOW:
cb_text_box.grid(row=4, column=1, sticky=W, padx=5, pady=1)
cb_text_arrow.grid(row=4, column=2, sticky=W, padx=5, pady=1)
cb_text_gravity.grid(row=2, column=3, columnspan=2, sticky=W, pady=1)

l_text_xy_x.grid(row=3, column=3, sticky=W, padx=5, pady=1)
@@ -3320,6 +3331,7 @@ def text_tool_hide_show():
ToolTip(cb_text_gravity, text=_("Use gravity for putting text or Absolute position"))
ToolTip(frame_text_gravity, text=_("Use gravity direction for text placement"))
ToolTip(cb_text_box, text=_("Use background for text"))
ToolTip(cb_text_arrow, text=_("Add arrow between text and origin point"))
ToolTip(e_text_x, text=_("Offset from gravity or absolute position"))
ToolTip(e_text_y, text=_("Offset from gravity or absolute position"))
ToolTip(l_text_color, text=_("Selected color of text and background"))
71 changes: 71 additions & 0 deletions fotokilof/common.py
Original file line number Diff line number Diff line change
@@ -30,13 +30,17 @@
- crop_gravity - convert coordinates for crop3 and logo position
- list_of_images - sorted list images in cwd
- file_from_list_of_images - return filename from file_list depends of request
- arrow_gravity - calculate coordinates if draw arrow
"""

import fnmatch
import logging
from pathlib import PurePosixPath, PureWindowsPath
import os
import os.path

module_logger = logging.getLogger(__name__)


def resize_subdir(resize_vatiant, pixel_x, pixel_y, percent):
"""prepare name for subdir and command for resize"""
@@ -247,4 +251,71 @@ def file_from_list_of_images(file_list, current_file, request):
return file


def arrow_gravity(position, length, x0, y0):
"""calculate coordinated to draw arrow"""
length = int(length)
x0 = int(x0)
y0 = int(y0)
width = int(length / 3 / 2)
length_1_2 = int(length / 2)
length_1_3 = int(length / 3)
length_1_4 = int(length / 4)

offset_x = 0
offset_y = 0
c = (x0, y0)
if position == "N":
a = (x0, y0 + length)
d = (x0 - width, y0 + length_1_3)
e = (x0 + width, y0 + length_1_3)
offset_y = length
elif position == "S":
a = (x0, y0 - length)
d = (x0 - width, y0 - length_1_3)
e = (x0 + width, y0 - length_1_3)
offset_y = -length
elif position == "W":
a = (x0 + length, y0)
d = (x0 + length_1_3, y0 - width)
e = (x0 + length_1_3, y0 + width)
offset_x = length
elif position == "E":
a = (x0 - length, y0)
d = (x0 - length_1_3, y0 - width)
e = (x0 - length_1_3, y0 + width)
offset_x = -length
elif position == "NW":
a = (x0 + length, y0 + length)
d = (x0 + length_1_4, y0 + length_1_2)
e = (x0 + length_1_2, y0 + length_1_4)
offset_x = length
offset_y = length
elif position == "NE":
a = (x0 - length, y0 + length)
d = (x0 - length_1_4, y0 + length_1_2)
e = (x0 - length_1_2, y0 + length_1_4)
offset_x = -length
offset_y = length
elif position == "SE":
a = (x0 - length, y0 - length)
d = (x0 - length_1_4, y0 - length_1_2)
e = (x0 - length_1_2, y0 - length_1_4)
offset_x = -length
offset_y = -length
elif position == "SW":
a = (x0 + length, y0 - length)
d = (x0 + length_1_4, y0 - length_1_2)
e = (x0 + length_1_2, y0 - length_1_4)
offset_x = length
offset_y = -length
else:
a = (0, 0)
d = (0, 0)
e = (0, 0)

msg = (position, a, c, d, e, offset_x, offset_y)
module_logger.debug("arrow_gravity: %s", msg)
return (a, c, d, e, offset_x, offset_y)


# EOF
16 changes: 14 additions & 2 deletions fotokilof/convert_pillow.py
Original file line number Diff line number Diff line change
@@ -229,11 +229,12 @@ def text(convert_data):
text_x = int(common.empty(convert_data[11]))
text_y = int(common.empty(convert_data[12]))
text_string = convert_data[13]
arrow = convert_data[14]

image_width, image_height = clone.size
font = ImageFont.truetype(font, text_size)

if len(text_string) > 0:
if len(text_string):
if in_out == 0:
# inside
if gravity_onoff == 0:
@@ -270,8 +271,19 @@ def text(convert_data):
text_x = image_width - text_x
text_y = image_height - text_y
draw_text = ImageDraw.Draw(clone)
if arrow:
if gravity_onoff == 0:
gravity = "NW"
a, c, d, e, offset_x, offset_y = common.arrow_gravity(gravity, text_size, text_x, text_y)
if gravity != "C":
draw_text.line([a, c], fill=text_color, width=2)
draw_text.line([d, c], fill=text_color, width=2)
draw_text.line([e, c], fill=text_color, width=2)
else:
offset_x = 0
offset_y = 0
draw_text.text(
(text_x, text_y),
(text_x + offset_x, text_y + offset_y),
text_string,
fill=text_color,
font=font,
29 changes: 26 additions & 3 deletions fotokilof/convert_wand.py
Original file line number Diff line number Diff line change
@@ -206,7 +206,10 @@ def text(convert_data):
text_x = convert_data[11]
text_y = convert_data[12]
text_string = convert_data[13]
if len(text_string) > 0:
arrow = convert_data[14]
arrow = 0

if len(text_string):
draw_gravity = gravitation(gravity)
if in_out == 0:
# inside
@@ -223,15 +226,22 @@ def text(convert_data):
angle = 0
text_x = 0
text_y = 0

if arrow:
if gravity_onoff == 0:
gravity = "NW"
a, c, d, e, offset_x, offset_y = common.arrow_gravity(gravity, text_size, text_x, text_y)
else:
offset_x = 0
offset_y = 0
text_x = str(int(text_x) + offset_x)
text_y = str(int(text_y) + offset_y)
draw = Drawing()
if box and not in_out:
draw.text_under_color = box_color
draw.fill_color = text_color
draw.font = font
draw.font_size = common.empty(text_size)
draw.gravity = draw_gravity

if in_out == 0:
# inside
clone.annotate(
@@ -241,6 +251,18 @@ def text(convert_data):
left=common.empty(text_x),
baseline=common.empty(text_y),
)
if arrow:
if gravity_onoff == 0:
gravity = "NW"
# a, c, d, e, offset_x, offset_y = common.arrow_gravity(gravity, text_size, text_x, text_y)
if gravity != "C":
print(a, c, d, e)
with Drawing() as draw_arrow:
draw_arrow.fill_color = text_color
draw_arrow.line(a, c)
draw_arrow.line(d, c)
draw_arrow.line(e, c)
draw_arrow(clone)
else:
# outside
metrics = draw.get_font_metrics(clone, text_string, multiline=False)
@@ -525,6 +547,7 @@ def preview(file_in, size, operating_system, coord=""):
right_top = (coord[2], coord[1])
right_bottom = (coord[2], coord[3])
draw.fill_color = "#FFFF00"
# draw.rectangle(left=coord[0], top=coord[1], right=coord[2], bottom=coord[3])
draw.line(left_top, right_top)
draw.line(left_top, left_bottom)
draw.line(left_bottom, right_bottom)
8 changes: 8 additions & 0 deletions fotokilof/ini_read.py
Original file line number Diff line number Diff line change
@@ -261,6 +261,14 @@ def text(file_ini, fonts_dict, operating_system):
rotate_own = "0"
dict_return["text_rotate_own"] = str(common.empty(rotate_own))

try:
text_arrow = config.getint("Text", "text_arrow")
except:
text_arrow = "0"
dict_return["text_arrow"] = entries.parse_list(
text_arrow, (0, 1), 0
)

return dict_return


1 change: 1 addition & 0 deletions fotokilof/ini_save.py
Original file line number Diff line number Diff line change
@@ -100,6 +100,7 @@ def save(ini_data):
config.set(text["section"], "y", text["y"])
config.set(text["section"], "text_rotate", str(text["text_rotate"]))
config.set(text["section"], "text_rotate_own", text["text_rotate_own"])
config.set(text["section"], "text_arrow", str(text["text_arrow"]))
# rotate
config.add_section(rotate["section"])
config.set(rotate["section"], "on", str(rotate["on"]))
Loading

0 comments on commit fb210ca

Please sign in to comment.