Skip to content

Commit

Permalink
5.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
TeaM-TL committed Oct 3, 2024
1 parent 13587c1 commit 2d943c4
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions fotokilof/convert_wand.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
- crop - crop picture
- vignete - add vignete into picture
- compose - join two pictures
- preview_wand - preview done by Wand
- preview - preview done by Wand
"""

import logging
Expand Down Expand Up @@ -76,12 +76,12 @@ def fonts_list():
# ------------------------------------ Common
def make_clone(file_to_clone, color=None):
"""open picture and make clone for processing"""
if len(file_to_clone) > 0:
if len(file_to_clone):
with Image(filename=file_to_clone, background=color) as image:
clone = image.clone()
result = image.clone()
else:
clone = None
return clone
result = None
return result


def save_close_clone(clone, file_out, exif=0):
Expand All @@ -91,8 +91,9 @@ def save_close_clone(clone, file_out, exif=0):
else:
if not exif:
clone.strip()
module_logger.debug(" Save file: %s", file_out)
clone.save(filename=file_out)
with open(file_out, "wb") as file_handler:
clone.save(file=file_handler)
module_logger.debug(" Save file: %s", file_out)
clone.close()


Expand Down Expand Up @@ -513,10 +514,8 @@ def preview(file_in, size, operating_system, coord=""):
if file_in is not None:
if os.path.isfile(file_in):
filesize = common.humansize(os.path.getsize(file_in))

clone = make_clone(file_in)
width, height = clone.size
clone.convert("ppm")
resize(clone, str(size) + "x" + str(size))
# write crop if coordinates are given
if len(coord) == 4:
Expand All @@ -533,7 +532,8 @@ def preview(file_in, size, operating_system, coord=""):
draw(clone)
preview_width, preview_height = clone.size
file_preview = os.path.join(tempfile.gettempdir(), "fotokilof_preview.ppm")
save_close_clone(clone, file_preview)
with clone.convert("ppm") as converted:
save_close_clone(converted, file_preview)
result = {
"filename": common.spacja(file_preview, operating_system),
"size": filesize,
Expand Down

0 comments on commit 2d943c4

Please sign in to comment.