1
0
mirror of https://github.com/gryf/ebook-converter.git synced 2026-04-07 21: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,4 +1,4 @@
from ebook_converter import fit_image
# from ebook_converter.util import img
from ebook_converter.constants_old import __appname__, __version__
from ebook_converter.gui2 import ensure_app, config, load_builtin_fonts, pixmap_to_data
from ebook_converter.utils.cleantext import clean_ascii_chars, clean_xml_chars
@@ -28,7 +28,7 @@ from ebook_converter.utils.config import JSONConfig
# bottom = footer_block.position.y - 50
# logo = QImage(logo_path or I('library.png'))
# pwidth, pheight = rect.width(), bottom - top
# scaled, width, height = fit_image(logo.width(), logo.height(), pwidth, pheight)
# scaled, width, height = img.fit_image(logo.width(), logo.height(), pwidth, pheight)
# x, y = (pwidth - width) // 2, (pheight - height) // 2
# rect = QRect(x, top + y, width, height)
# painter.setRenderHint(QPainter.SmoothPixmapTransform)

View File

@@ -6,9 +6,9 @@ import urllib.parse
from lxml import etree
from ebook_converter import fit_image
from ebook_converter.ebooks.docx.images import pt_to_emu
from ebook_converter.utils.filenames import ascii_filename
from ebook_converter.utils import img as uimg
from ebook_converter.utils.imghdr import identify
@@ -101,7 +101,8 @@ class ImagesManager(object):
img = self.images[href]
name = urllib.parse.unquote(posixpath.basename(href))
width, height = style.img_size(img.width, img.height)
scaled, width, height = fit_image(width, height, self.page_width, self.page_height)
scaled, width, height = uimg.fit_image(width, height, self.page_width,
self.page_height)
width, height = map(pt_to_emu, (width, height))
makeelement, namespaces = self.document_relationships.namespace.makeelement, self.document_relationships.namespace.namespaces

View File

@@ -19,9 +19,9 @@ import itertools
import math
import bs4
from PIL import Image as PILImage
from ebook_converter import entity_to_unicode, fit_image, \
force_unicode
from ebook_converter import entity_to_unicode, force_unicode
from ebook_converter.constants_old import __appname__, filesystem_encoding, \
preferred_encoding
from ebook_converter.devices.interface import DevicePlugin as Device
@@ -37,8 +37,7 @@ from ebook_converter.ebooks.lrf.pylrs.pylrs import (
RuledLine, Span, Sub, Sup, TextBlock
)
from ebook_converter.ptempfile import PersistentTemporaryFile
from PIL import Image as PILImage
from ebook_converter.utils import img as uimg
def strip_style_comments(match):
@@ -1075,7 +1074,7 @@ class HTMLConverter(object):
finally:
pt.close()
scaled, width, height = fit_image(width, height, pwidth, pheight)
scaled, width, height = uimg.fit_image(width, height, pwidth, pheight)
if scaled:
path = scale_image(width, height)
@@ -1956,7 +1955,8 @@ def process_file(path, options, logger):
corrf = pwidth/width
width, height = pwidth, int(corrf*height)
scaled, width, height = fit_image(width, height, pwidth, pheight)
scaled, width, height = uimg.fit_image(width, height, pwidth,
pheight)
try:
cim = im.resize((width, height),
PILImage

View File

@@ -1,9 +1,4 @@
from ebook_converter import fit_image
__license__ = 'GPL v3'
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
from ebook_converter.utils import img as uimg
class RescaleImages(object):
@@ -57,7 +52,9 @@ class RescaleImages(object):
except Exception:
self.log.exception('Failed to convert image %s from CMYK to RGB' % item.href)
scaled, new_width, new_height = fit_image(width, height, page_width, page_height)
scaled, new_width, new_height = uimg.fit_image(width, height,
page_width,
page_height)
if scaled:
new_width = max(1, new_width)
new_height = max(1, new_height)