diff --git a/src/calibre/gui2/tweak_book/boss.py b/src/calibre/gui2/tweak_book/boss.py index 3e22e41ba5..677adbae2f 100644 --- a/src/calibre/gui2/tweak_book/boss.py +++ b/src/calibre/gui2/tweak_book/boss.py @@ -48,6 +48,7 @@ from calibre.gui2.tweak_book.widgets import ( InsertSemantics, BusyCursor, InsertTag, FilterCSS, AddCover) from calibre.utils.config import JSONConfig from calibre.utils.icu import numeric_sort_key +from calibre.utils.imghdr import identify _diff_dialogs = [] last_used_transform_rules = [] @@ -861,7 +862,8 @@ class Boss(QObject): self.refresh_file_list() chosen_name = chosen_image_is_external[0] href = current_container().name_to_href(chosen_name, edname) - ed.insert_image(href, fullpage=fullpage, preserve_aspect_ratio=preserve_ar) + fmt, width, height = identify(current_container().raw_data(chosen_name, decode=False)) + ed.insert_image(href, fullpage=fullpage, preserve_aspect_ratio=preserve_ar, width=width, height=height) elif action[0] == 'insert_hyperlink': self.commit_all_editors_to_container() d = InsertLink(current_container(), edname, initial_text=ed.get_smart_selection(), parent=self.gui) diff --git a/src/calibre/gui2/tweak_book/editor/text.py b/src/calibre/gui2/tweak_book/editor/text.py index 479bed211a..e76c0b34b0 100644 --- a/src/calibre/gui2/tweak_book/editor/text.py +++ b/src/calibre/gui2/tweak_book/editor/text.py @@ -836,7 +836,11 @@ class TextEdit(PlainTextEdit): c.setPosition(c.position() - len(suffix)) self.setTextCursor(c) - def insert_image(self, href, fullpage=False, preserve_aspect_ratio=False): + def insert_image(self, href, fullpage=False, preserve_aspect_ratio=False, width=-1, height=-1): + if width <= 0: + width = 1200 + if height <= 0: + height = 1600 c = self.textCursor() template, alt = 'url(%s)', '' left = min(c.position(), c.anchor) @@ -849,9 +853,9 @@ class TextEdit(PlainTextEdit): template = '''\