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
cropRight = kindleResolutionWidth
cropBottom = kindleResolutionHeight
print("Image size is {}x{}, ratio is {}, kindle ratio is {}".format(width, height, ratio, kindleRatio))
if ratio > kindleRatio:
# Fit height
destHeight = kindleResolutionHeight
destWidth = width * ratio
destWidth = width * (destHeight / height)
# Calc crop
cropLeft = (destWidth - kindleResolutionWidth) / 2
cropRight = cropLeft + kindleResolutionWidth
else:
# Fit width
destWidth = kindleResolutionWidth
destHeight = height * (1 / ratio)
destHeight = height * (destWidth / width)
# Calc crop
cropTop = (destHeight - kindleResolutionHeight) / 2
cropBottom = cropTop + kindleResolutionHeight