From 4336c25193d991fb703117e29033882cfe0cf181 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 4 Jun 2015 10:04:23 +0530 Subject: [PATCH] DOCX Output: Fix aspect ratio of images being distorted when the input document specifies image width but not height or vice-versa. See #1455502 (EPUB to DOCX Conversation) --- src/calibre/ebooks/oeb/stylizer.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/calibre/ebooks/oeb/stylizer.py b/src/calibre/ebooks/oeb/stylizer.py index ec986b168b..ee5db28daf 100644 --- a/src/calibre/ebooks/oeb/stylizer.py +++ b/src/calibre/ebooks/oeb/stylizer.py @@ -535,7 +535,13 @@ class Style(object): def img_size(self, width, height): ' Return the final size of an given that it points to an image of size widthxheight ' - return self.img_dimension('width', width), self.img_dimension('height', height) + w, h = self._get('width'), self._get('height') + answ, ansh = self.img_dimension('width', width), self.img_dimension('height', height) + if w == 'auto' and h != 'auto': + answ = (float(width)/height) * ansh + elif h == 'auto' and w != 'auto': + ansh = (float(height)/width) * answ + return answ, ansh @property def width(self):