diff --git a/CHANGES.md b/CHANGES.md index c50220a..37ad915 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,7 +2,9 @@ ## 2025 -5.1.6 I hope, that locale will be added +5.1.7 inserting picture into picture works + +5.1.6 locale has been added, fixed github/actions 5.1.5 fixed right mouse button for crop, small code polishing diff --git a/fotokilof/__main__.py b/fotokilof/__main__.py index 99ad870..39a8aec 100644 --- a/fotokilof/__main__.py +++ b/fotokilof/__main__.py @@ -77,7 +77,6 @@ # my modules import check_new_version import convert -import convert_wand import convert_pillow import convert_common import common @@ -386,12 +385,13 @@ def apply_all_button(): clone, img_normalize.get(), co_normalize_channel.get(), PILLOW ) if img_vignette_on.get(): - convert_wand.vignette( + convert_common.vignette( clone, e_vignette_dx.get(), e_vignette_dy.get(), e_vignette_radius.get(), e_vignette_radius.get(), + PILLOW, ) if img_rotate_on.get(): clone = convert_common.rotate( @@ -453,8 +453,8 @@ def apply_all_button(): ) height = clone.height width = clone.width - convert_wand.pip( - clone, file_logo_path.get(), coordinates, width, height + convert_common.pip( + clone, file_logo_path.get(), coordinates, width, height, PILLOW ) file_out = convert.out_full_filename(file_in, subdir, co_apply_type.get()) @@ -620,12 +620,13 @@ def convert_vignette_button(): file_in_path.get(), PILLOW, img_vignette_color.get() ) if clone is not None: - convert_wand.vignette( + convert_common.vignette( clone, e_vignette_dx.get(), e_vignette_dy.get(), e_vignette_radius.get(), e_vignette_radius.get(), + PILLOW, ) convert_common.save_close_clone( clone, path_to_file_out(0), img_exif_on.get(), PILLOW @@ -809,8 +810,8 @@ def convert_logo_button(): ) clone = convert_common.make_clone(file_in_path.get(), PILLOW) if clone is not None: - convert_wand.pip( - clone, file_logo_path.get(), coordinates, clone.width, clone.height + convert_common.pip( + clone, file_logo_path.get(), coordinates, clone.width, clone.height, PILLOW ) convert_common.save_close_clone( clone, path_to_file_out(0), img_exif_on.get(), PILLOW @@ -2221,8 +2222,8 @@ def text_tool_hide_show(): cb_rotate.pack(padx=5, pady=5, anchor=W, side=LEFT) cb_resize.pack(padx=5, pady=5, anchor=W, side=LEFT) cb_text.pack(padx=5, pady=5, anchor=W, side=LEFT) +cb_logo.pack(padx=5, pady=5, anchor=W, side=LEFT) if not PILLOW: - cb_logo.pack(padx=5, pady=5, anchor=W, side=LEFT) cb_custom.pack(padx=5, pady=5, anchor=W, side=LEFT) cb_exif.pack(padx=5, pady=5, anchor=W, side=LEFT) cb_compose.pack(padx=5, pady=5, anchor=W, side=LEFT) @@ -3454,7 +3455,6 @@ def text_tool_hide_show(): if PILLOW: # disable processing buttons img_logo_on.set(0) - cb_logo.configure(state=DISABLED) img_custom_on.set(0) cb_custom.configure(state=DISABLED) img_vignette_on.set(0) diff --git a/fotokilof/convert_common.py b/fotokilof/convert_common.py index d7b15e4..363e0a7 100644 --- a/fotokilof/convert_common.py +++ b/fotokilof/convert_common.py @@ -65,17 +65,7 @@ module_logger.info(WAND_TEXT) -def fonts_list(set_pillow): - """list of available fonts""" - start_time = time.time() - if set_pillow: - result = convert_pillow.fonts_list() - else: - result = convert_wand.fonts_list() - module_logger.info("Get fonts list: %ss", str(time.time() - start_time)) - return result - - +# ------------------------------------ Common def display_image(file_to_display, set_pillow): """display image""" module_logger.info(" Display file: %s", file_to_display) @@ -133,24 +123,15 @@ def get_image_size(file_in, is_pillow): return size -def preview(file_logo, size, set_pillow, coord=""): - """preview""" +# ------------------------------------ Common +def fonts_list(set_pillow): + """list of available fonts""" start_time = time.time() - if set_pillow: - result = convert_pillow.preview(file_logo, size, coord) + result = convert_pillow.fonts_list() else: - result = convert_wand.preview(file_logo, size, coord) - if result is None: - result = { - "filename": None, - "size": "0", - "width": "0", - "height": "0", - "preview_width": "0", - "preview_height": "0", - } - module_logger.info("preview: %s s", str(time.time() - start_time)) + result = convert_wand.fonts_list() + module_logger.info("Get fonts list: %ss", str(time.time() - start_time)) return result @@ -176,6 +157,28 @@ def save_close_clone(clone, file_out, exif_on, set_pillow): module_logger.info("Save clone: %ss", str(time.time() - start_time)) +# ------------------------------------ Converters +def pip(clone, logo, logo_data, image_height, image_width, set_pillow): + """put picture on picture + clone - clone of image for processing + logo - filename of logo + logo_data = offset_x, offset_y, width, height, gravitation + original image size: image_height, image_width + """ + if clone: + start_time = time.time() + if set_pillow: + result = convert_pillow.pip( + clone, logo, logo_data, image_height, image_width + ) + else: + result = convert_wand.pip(clone, logo, logo_data, image_height, image_width) + module_logger.info("PIP %ss", str(time.time() - start_time)) + else: + result = None + return result + + def rotate(clone, angle, color, angle_own, set_pillow): """rotate""" start_time = time.time() @@ -206,18 +209,6 @@ def mirror(clone, flip, flop, set_pillow): return result -def resize(clone, command, set_pillow): - """resize picture""" - start_time = time.time() - if set_pillow: - result = convert_pillow.resize(clone, command) - else: - convert_wand.resize(clone, command) - result = clone - module_logger.info("Resize: %ss", str(time.time() - start_time)) - return result - - def border(clone, color, x, y, set_pillow): """mirror: flip and flop""" start_time = time.time() @@ -230,15 +221,14 @@ def border(clone, color, x, y, set_pillow): return result -def normalize(clone, normalize_variant, channel, set_pillow): - """normalize levels of colors""" +def text(convert_data, set_pillow): + """black and white or sepia""" start_time = time.time() if set_pillow: - result = convert_pillow.normalize(clone, normalize_variant, channel) + result = convert_pillow.text(convert_data) else: - convert_wand.normalize(clone, normalize_variant, channel) - result = clone - module_logger.info("Normalize %ss", str(time.time() - start_time)) + result = convert_wand.text(convert_data) + module_logger.info("Text %ss", str(time.time() - start_time)) return result @@ -254,6 +244,30 @@ def bw(clone, bw_variant, sepia, set_pillow): return result +def resize(clone, command, set_pillow): + """resize picture""" + start_time = time.time() + if set_pillow: + result = convert_pillow.resize(clone, command) + else: + convert_wand.resize(clone, command) + result = clone + module_logger.info("Resize: %ss", str(time.time() - start_time)) + return result + + +def normalize(clone, normalize_variant, channel, set_pillow): + """normalize levels of colors""" + start_time = time.time() + if set_pillow: + result = convert_pillow.normalize(clone, normalize_variant, channel) + else: + convert_wand.normalize(clone, normalize_variant, channel) + result = clone + module_logger.info("Normalize %ss", str(time.time() - start_time)) + return result + + def contrast(clone, contrast_variant, selection, black, white, set_pillow): """black and white or sepia""" start_time = time.time() @@ -334,14 +348,24 @@ def crop(file_in, clone, crop_variant, gravity, entries, set_pillow): return result -def text(convert_data, set_pillow): - """black and white or sepia""" - start_time = time.time() - if set_pillow: - result = convert_pillow.text(convert_data) +def vignette(clone, dx, dy, radius, sigma, set_pillow): + """add vignette into picture + clone - clone of image for processing + dx, dy - offset from border + radius - radius of Gaussian blur + sigma - standard deviation for Gaussian blur + color - color of corners + """ + if clone: + start_time = time.time() + if set_pillow: + module_logger.info("Vignette doesn't work with Pillow yet") + # result = convert_pillow.vignette(clone, dx, dy, radius, sigma) + else: + result = convert_wand.vignette(clone, dx, dy, radius, sigma) + module_logger.info("Vignette %ss", str(time.time() - start_time)) else: - result = convert_wand.text(convert_data) - module_logger.info("Text %ss", str(time.time() - start_time)) + result = None return result @@ -361,3 +385,28 @@ def compose(clone, compose_file, right, autoresize, color, gravity, set_pillow): else: result = None return result + + +# ------------------------------------ Preview +def preview(file_logo, size, set_pillow, coord=""): + """preview""" + start_time = time.time() + + if set_pillow: + result = convert_pillow.preview(file_logo, size, coord) + else: + result = convert_wand.preview(file_logo, size, coord) + if result is None: + result = { + "filename": None, + "size": "0", + "width": "0", + "height": "0", + "preview_width": "0", + "preview_height": "0", + } + module_logger.info("preview: %s s", str(time.time() - start_time)) + return result + + +# EOF diff --git a/fotokilof/convert_pillow.py b/fotokilof/convert_pillow.py index 58eb529..1d295dc 100644 --- a/fotokilof/convert_pillow.py +++ b/fotokilof/convert_pillow.py @@ -60,7 +60,7 @@ module_logger = logging.getLogger(__name__) -# ------------------------------------ Info +# ------------------------------------ Common def version(): """version of PIL""" return Image.__version__ @@ -85,7 +85,6 @@ def fonts_list(): return result -# ------------------------------------ Common def make_clone(file_to_clone, color=None): """open picture and make clone for processing""" if file_to_clone: @@ -116,22 +115,21 @@ def pip(clone, logo, logo_data, image_height, image_width): logo_data = offset_x, offset_y, width, height, gravitation original image size: image_height, image_width """ - if len(logo): + result = None + if clone: if os.path.isfile(logo): - pass - # with Image(logo) as logo_img: - # with Drawing() as draw: - # position = common.crop_gravity(logo_data, image_height, image_width) - # draw.composite( - # operator="over", - # left=common.empty(position[0]), - # top=common.empty(position[1]), - # width=common.empty(logo_data[2]), - # height=common.empty(logo_data[3]), - # image=logo_img, - # ) - # draw(clone) - module_logger.warning("PIP is not available for PILLOW yet, install ImageMagick") + position = common.crop_gravity(logo_data, image_height, image_width) + logo_left = common.empty(position[0]) + logo_top = common.empty(position[1]) + logo_width = common.empty(logo_data[2]) + logo_height = common.empty(logo_data[3]) + + with Image.open(logo) as logo_image: + logo_size = str(logo_width) + "x" + str(logo_height) + logo_image = resize(logo_image, logo_size) + clone.paste(logo_image, (logo_left, logo_top)) + result = clone + return result def rotate(clone, angle, color): @@ -410,7 +408,8 @@ def preview(file_in, max_size, coord=""): - width and height """ - if file_in is not None: + result = None + if file_in: if os.path.isfile(file_in): filesize = common.humansize(os.path.getsize(file_in)) clone = make_clone(file_in) @@ -449,8 +448,6 @@ def preview(file_in, max_size, coord=""): "preview_width": str(preview_width), "preview_height": str(preview_height), } - else: - result = None return result diff --git a/fotokilof/convert_wand.py b/fotokilof/convert_wand.py index 4b83fcf..7794f27 100644 --- a/fotokilof/convert_wand.py +++ b/fotokilof/convert_wand.py @@ -65,13 +65,12 @@ module_logger.info(WAND_TEXT) -# ------------------------------------ Info +# ------------------------------------ Common def fonts_list(): """list of available fonts""" return fontsList() -# ------------------------------------ Common def make_clone(file_to_clone, color=None): """open picture and make clone for processing""" if file_to_clone: @@ -102,7 +101,7 @@ def pip(clone, logo, logo_data, image_height, image_width): logo_data = offset_x, offset_y, width, height, gravitation original image size: image_height, image_width """ - if len(logo): + if logo: if os.path.isfile(logo): with Image(filename=logo) as logo_img: with Drawing() as draw: diff --git a/fotokilof/version.py b/fotokilof/version.py index 1178916..bfdf74d 100644 --- a/fotokilof/version.py +++ b/fotokilof/version.py @@ -22,7 +22,7 @@ THE SOFTWARE. """ -__version__ = "5.1.6" +__version__ = "5.1.7" __author__ = "Tomasz Ɓuczak" __email__ = "tlu@team-tl.pl" __appname__ = "FotoKilof"