View Single Post
Old 08-18-2017, 05:22 AM   #1
slowsmile
Witchman
slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.
 
Posts: 628
Karma: 788808
Join Date: May 2013
Location: Philippines
Device: Android S5
[Plugin] AddKindleMediaQueries

Optimally dual-formats all epub image entries both for KF7 devices(in pixels) and KF8 devices(as a %)

Requirements
Plugin Type: Edit
MIT Licence(OSI)
Minimum Sigil requirement: v0.9.3 or higher
Python Requirements: Python 3.4+ (Bundled or External)
OS Requirements: Windows, Linux or OSX
*** Tested on Windows 7, 8 & 10 only ***
Current Version: "0.1.9"

Installation
* Select Manage Plugins from the Plugins menu. In the dialog box, select either the Bundled Python or the External Python(Python 3.4+ should be installed on your computer to run this plugin externally).
* Click Add Plugin and select AddKindleMediaQueries_vXXX.zip. This will load and install the plugin into Sigil, which you can then select and run the plugin by selecting Plugins > Edit > AddKindleMediaQueries.

Description
This simple plugin is an edit plugin that automatically dual formats all ebook image entries in your epub and also adds the appropriate media queries to the main stylesheet for optimal rendering of all images on both KF7 devices(in pixels) and KF8 devices(as percentages). At runtime on Kindle ereaders the media queries in the CSS will then select the appropriate image line to display according to whether your ebook is running on a Kindle KF7 device or KF8 device.

This plugin will now automatically dual format svg images for Kindle epubs. KF8 ebook images will be displayed in svg format whereas KF7 ebook images will be added and displayed in html style using pixel values.See Caveat below.(added in v0.1.8)

User Options(via dialog):

*Add media queries to this stylesheet
This is an option dropdown list that allows you to select the right stylesheet from your epub to add the media queries. The stylesheet that you choose should be the main stylesheet that is used to style all text files and images in your epub.

* Type preferred base pixel width value
This text entry option allows you to type in your own preferred base width value in pixels for the % calculation. This value is used to calculate the percentage width of the images for KF8 devices only. The calculation is shown below.

image-width-in-pixels/630 x 100

The 630px value is the default base width option(or default screen width option). So the user has the option of either typing in a larger or smaller base width value for all ebook images which allows the user to increase or decrease the dimensions of all ebook images or the user can just use the default -- 630px. If you are unsure about how to use this option then you should just use the default base pixel width value.

Plugin Run
First load your epub into Sigil and then just run this plugin.

Please also be aware that the above percentage calculation for all Kindle KF8 image dimensions will not be exact but will instead be a best-average or ballpark percentage width because I've only used a single, default base width value(average screen width value) for all Kindle KF8 devices in my percentage calculation above. This will inevitably give small variances in displayed image size across the many different KF8 devices and legacy KF8s(with slightly different screen widths) because I have only used a single, best-average screen width value for all calculations.

Updates
* The plugin can now handle all forms of div with image tag formatting(changed in v0.1.5)

Changes
Spoiler:

v0.1.9
-- Added error warning dialog if any image filenames contain spaces.
v0.1.8
-- This plugin will now automatically dual format svg images for Kindle epubs. KF8 ebook images will be displayed in svg format whereas KF7 ebook images will be added and displayed using their original pixel values.
-- Improved logging
v0.1.7
-- Added MIT SW Licence
v0.1.6
-- Fixed bug causing SVG errors. You can now load an epub containing SVG image wrappers and there should be no Epubcheck errors.
v0.1.5
-- The plugin can now handle all forms of div with image tag formatting
v0.1.4
-- Fixed a bug causing lower case font name errors and duplication errors in the css and the html repectively. Thanks to Doitsu.
v0.1.3
-- Initial release
Attached Thumbnails
Click image for larger version

Name:	User_Options.JPG
Views:	1053
Size:	23.2 KB
ID:	163063  
Attached Files
File Type: zip AddKindleMediaQueries_v019.zip (46.8 KB, 1626 views)

Last edited by slowsmile; 11-02-2019 at 04:17 AM.
slowsmile is offline   Reply With Quote