1
0
mirror of https://github.com/gryf/ebook-converter.git synced 2026-03-30 08:43:31 +02:00

Move fit_image to img utils module.

This commit is contained in:
2020-10-13 19:39:05 +02:00
parent 250d0eeea7
commit b44926a6eb
6 changed files with 41 additions and 43 deletions

View File

@@ -1,5 +1,4 @@
import html
import math
import os
import re
@@ -9,30 +8,6 @@ from ebook_converter import constants_old
from ebook_converter.ebooks.html_entities import html5_entities
def fit_image(width, height, pwidth, pheight):
"""
Fit image in box of width pwidth and height pheight.
@param width: Width of image
@param height: Height of image
@param pwidth: Width of box
@param pheight: Height of box
@return: scaled, new_width, new_height. scaled is True iff new_width
and/or new_height is different from width or height.
"""
scaled = height > pheight or width > pwidth
if height > pheight:
corrf = pheight / float(height)
width, height = math.floor(corrf*width), pheight
if width > pwidth:
corrf = pwidth / float(width)
width, height = pwidth, math.floor(corrf*height)
if height > pheight:
corrf = pheight / float(height)
width, height = math.floor(corrf*width), pheight
return scaled, int(width), int(height)
class CurrentDir(object):
def __init__(self, path):