Fixed image ratio

This commit is contained in:
Daniele Verducci (Slimpenguin) 2023-02-28 22:39:50 +01:00
parent daac9f8ccb
commit 6c2e0730ee

View File

@ -81,18 +81,17 @@ cropLeft = 0
cropTop = 0 cropTop = 0
cropRight = kindleResolutionWidth cropRight = kindleResolutionWidth
cropBottom = kindleResolutionHeight cropBottom = kindleResolutionHeight
print("Image size is {}x{}, ratio is {}, kindle ratio is {}".format(width, height, ratio, kindleRatio))
if ratio > kindleRatio: if ratio > kindleRatio:
# Fit height # Fit height
destHeight = kindleResolutionHeight destHeight = kindleResolutionHeight
destWidth = width * ratio destWidth = width * (destHeight / height)
# Calc crop # Calc crop
cropLeft = (destWidth - kindleResolutionWidth) / 2 cropLeft = (destWidth - kindleResolutionWidth) / 2
cropRight = cropLeft + kindleResolutionWidth cropRight = cropLeft + kindleResolutionWidth
else: else:
# Fit width # Fit width
destWidth = kindleResolutionWidth destWidth = kindleResolutionWidth
destHeight = height * (1 / ratio) destHeight = height * (destWidth / width)
# Calc crop # Calc crop
cropTop = (destHeight - kindleResolutionHeight) / 2 cropTop = (destHeight - kindleResolutionHeight) / 2
cropBottom = cropTop + kindleResolutionHeight cropBottom = cropTop + kindleResolutionHeight