View Single Post
Old 07-25-2017, 01:43 AM   #1
roger64
Wizard
roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.
 
Posts: 2,624
Karma: 3120635
Join Date: Jan 2009
Device: Kindle PW3 (wifi)
Calculating and inserting image width. A plugin?

Hi

Sigil is very handy namely for its plugins, this explains the title I gave to this thread.
It is about calculating and inserting image width.

Rationale: we have two kinds of images: the fullscreen ones and the others.

1. - A fullscreen image is very safely contained in its own page.

I tend to use this very basic code (example):
Spoiler:

<?xml version='1.0' encoding='utf-8'?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Whatever</title>
<style type="text/css">body { margin:0 }</style>
</head>
<body>
<div style="text-align:center"><img alt="002" id="fig-2" src="../Images/Image-02.jpg" style="width: 80%;"/></div>

</body>

</html>


2. - A plain image will just flow with the text:
We'll use only a part of the above code.
Code:
<div style="text-align:center"><img alt="002" id="fig-2" src="../Images/Image-02.jpg" style="width: 60%;"/></div>
For both kinds of images, the width calculation to perform will be the same.

The percentage of width (here in bold) is truly the crucial figure. The more precise, the better display. Obviously it can't be more than 100%.

This how I calculate width for an image of a 626 × 942 pixels size to obtain 88.6%
(626/942) ×4 /3

I wish this could be done and inserted automatically for all images of an Epub.

If one does not agree with the 4/3 fraction (because his(her) own screen may have a different size), this fraction could be defined as a variable.

Last edited by roger64; 07-25-2017 at 01:57 AM.
roger64 is offline   Reply With Quote