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:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user