mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
MOBI Output: Add an option to not convert all images to JPEG when creating MOBI files
This commit is contained in:
parent
04cbade264
commit
61fddc54fb
@ -56,7 +56,16 @@ class MOBIOutput(OutputFormatPlugin):
|
|||||||
help=_('Enable sharing of book content via Facebook etc. '
|
help=_('Enable sharing of book content via Facebook etc. '
|
||||||
' on the Kindle. WARNING: Using this feature means that '
|
' on the Kindle. WARNING: Using this feature means that '
|
||||||
' the book will not auto sync its last read position '
|
' the book will not auto sync its last read position '
|
||||||
' on multiple devices. Complain to Amazon.'))
|
' on multiple devices. Complain to Amazon.')
|
||||||
|
),
|
||||||
|
OptionRecommendation(name='mobi_keep_original_images',
|
||||||
|
recommended_value=False,
|
||||||
|
help=_('By default calibre converts all images to JPEG format '
|
||||||
|
'in the output MOBI file. This is for maximum compatibility '
|
||||||
|
'as some older MOBI viewers have problems with other image '
|
||||||
|
'formats. This option tells calibre not to do this. '
|
||||||
|
'Useful if your document contains lots of GIF/PNG images that '
|
||||||
|
'become very large when converted to JPEG.')),
|
||||||
])
|
])
|
||||||
|
|
||||||
def check_for_periodical(self):
|
def check_for_periodical(self):
|
||||||
|
@ -7,7 +7,7 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import struct, string
|
import struct, string, imghdr
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
from calibre.utils.magick.draw import Image, save_cover_data_to, thumbnail
|
from calibre.utils.magick.draw import Image, save_cover_data_to, thumbnail
|
||||||
@ -363,3 +363,11 @@ def to_base(num, base=32):
|
|||||||
ans.reverse()
|
ans.reverse()
|
||||||
return ''.join(ans)
|
return ''.join(ans)
|
||||||
|
|
||||||
|
def mobify_image(data):
|
||||||
|
'Convert PNG images to GIF as the idiotic Kindle cannot display some PNG'
|
||||||
|
what = imghdr.what(None, data)
|
||||||
|
if what == 'png':
|
||||||
|
data = save_cover_data_to(data, 'img.gif', return_data=True)
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ from calibre.ebooks.compression.palmdoc import compress_doc
|
|||||||
from calibre.ebooks.mobi.langcodes import iana2mobi
|
from calibre.ebooks.mobi.langcodes import iana2mobi
|
||||||
from calibre.utils.filenames import ascii_filename
|
from calibre.utils.filenames import ascii_filename
|
||||||
from calibre.ebooks.mobi.writer2 import (PALMDOC, UNCOMPRESSED, RECORD_SIZE)
|
from calibre.ebooks.mobi.writer2 import (PALMDOC, UNCOMPRESSED, RECORD_SIZE)
|
||||||
from calibre.ebooks.mobi.utils import (rescale_image, encint,
|
from calibre.ebooks.mobi.utils import (rescale_image, encint, mobify_image,
|
||||||
encode_trailing_data, align_block, detect_periodical)
|
encode_trailing_data, align_block, detect_periodical)
|
||||||
from calibre.ebooks.mobi.writer2.indexer import Indexer
|
from calibre.ebooks.mobi.writer2.indexer import Indexer
|
||||||
from calibre.ebooks.mobi import MAX_THUMB_DIMEN, MAX_THUMB_SIZE
|
from calibre.ebooks.mobi import MAX_THUMB_DIMEN, MAX_THUMB_SIZE
|
||||||
@ -179,7 +179,11 @@ class MobiWriter(object):
|
|||||||
for item in self.oeb.manifest.values():
|
for item in self.oeb.manifest.values():
|
||||||
if item.media_type not in OEB_RASTER_IMAGES: continue
|
if item.media_type not in OEB_RASTER_IMAGES: continue
|
||||||
try:
|
try:
|
||||||
data = rescale_image(item.data)
|
data = item.data
|
||||||
|
if self.opts.mobi_keep_original_images:
|
||||||
|
data = mobify_image(data)
|
||||||
|
else:
|
||||||
|
data = rescale_image(data)
|
||||||
except:
|
except:
|
||||||
oeb.logger.warn('Bad image file %r' % item.href)
|
oeb.logger.warn('Bad image file %r' % item.href)
|
||||||
continue
|
continue
|
||||||
|
@ -22,6 +22,7 @@ class PluginWidget(Widget, Ui_Form):
|
|||||||
def __init__(self, parent, get_option, get_help, db=None, book_id=None):
|
def __init__(self, parent, get_option, get_help, db=None, book_id=None):
|
||||||
Widget.__init__(self, parent,
|
Widget.__init__(self, parent,
|
||||||
['prefer_author_sort', 'toc_title',
|
['prefer_author_sort', 'toc_title',
|
||||||
|
'mobi_keep_original_images',
|
||||||
'mobi_ignore_margins', 'mobi_toc_at_start',
|
'mobi_ignore_margins', 'mobi_toc_at_start',
|
||||||
'dont_compress', 'no_inline_toc', 'share_not_sync',
|
'dont_compress', 'no_inline_toc', 'share_not_sync',
|
||||||
'personal_doc']#, 'mobi_navpoints_only_deepest']
|
'personal_doc']#, 'mobi_navpoints_only_deepest']
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
<string>Form</string>
|
<string>Form</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="7" column="0" colspan="2">
|
<item row="8" column="0" colspan="2">
|
||||||
<widget class="QGroupBox" name="groupBox">
|
<widget class="QGroupBox" name="groupBox">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Kindle options</string>
|
<string>Kindle options</string>
|
||||||
@ -57,7 +57,7 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="8" column="0">
|
<item row="9" column="0">
|
||||||
<spacer name="verticalSpacer_2">
|
<spacer name="verticalSpacer_2">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
@ -104,7 +104,7 @@
|
|||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QLineEdit" name="opt_toc_title"/>
|
<widget class="QLineEdit" name="opt_toc_title"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="5" column="0">
|
<item row="6" column="0">
|
||||||
<widget class="QCheckBox" name="opt_dont_compress">
|
<widget class="QCheckBox" name="opt_dont_compress">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Disable compression of the file contents</string>
|
<string>Disable compression of the file contents</string>
|
||||||
@ -118,6 +118,13 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="5" column="0" colspan="2">
|
||||||
|
<widget class="QCheckBox" name="opt_mobi_keep_original_images">
|
||||||
|
<property name="text">
|
||||||
|
<string>Do not convert all images to &JPEG (may result in images not working in older viewers)</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user