Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil > Plugins

Notices

Reply
 
Thread Tools Search this Thread
Old 12-05-2015, 02:12 PM   #1
rubeus
Banned
rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.
 
Posts: 272
Karma: 1224588
Join Date: Sep 2014
Device: Sony PRS 650
Limit images to be resized

Hi,

over the time the resolution of ebook devices increased from 800x60 too full HD and even more (retine displays)

What resolution should an image have? An image having a gootd resolution for 800x600 looks like a stamp on hires screens. If you assign a proportonal width like 90% may lead to a resizing where the displayed image is oversized. it looks ugly - especially indexed images. So the ideal formatting would resize the image proportional, but stop the image to be scaled larger than it is. Im archiving this by using these css rules:

Code:
div.cimg {
  width: 100%;
  text-align: center;
  margin: 1em 8px 1em 8px;
}

div.cimg img {
  width: 100%;
}

div.cimg + p {
  text-indent: 0;
}
This will center the image, make a margin around it, scaling the image to fit on the screen and set the indentation of the following paragraph to zero.
But it will not prevent the image to be resized larger than it is. This is done by adding the max-width style to the img rule. As the width of an image varies from image to image a special css rule is necassry for each image - or each image needs to have the same resolution.
To solve that the max-width style can be apllied to the img element:

Code:
  <div class="cimg">
    <img alt="" src="../Images/img07.png" style="max-width: 520px"/>
  </div>
Now the image will be resized according to the screen size but this will stop at 520px, the width of the image itself.
Still this is very time consuming even with a snippet as the snippet cant retrieve the image resolution.

The Plugin below will go through every text file and will add the maxwidth style te every img element. Existing styles will be kept, if there is already a max-width style the value will be checked and corrected if necessary.
I'm new to Python, especially to PIL and BS4, so i gave the version 0.0.1. Use at your own risk and always have a backup

This plugin wouldnt exist without the help of Doitso and KevinH.

Every comment to improve is welcomed.

Requirements: Sigil 0.9.1 with internal Python enabled. The Plugin is not 2.7 enabled.

Last edited by rubeus; 03-30-2016 at 04:28 AM.
rubeus is offline   Reply With Quote
Old 12-06-2015, 10:19 AM   #2
Jellby
frumious Bandersnatch
Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.
 
Jellby's Avatar
 
Posts: 7,516
Karma: 19000001
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
You can specify sizes in absolute units (cm, in, mm... even px are supposed to be absolute units, not physical pixels).

But I think what you are after is simply "div.cimg img {max-width:100%}". That should show the image at its "natural" size, but resize it down to 100% if it's larger.

Quote:
Originally Posted by rubeus View Post
To solve that the max-width style can be apllied to the img element:

Code:
  <div class="cimg">
    <img alt="" src="../Images/img07.png" style="max-width: 520px"/>
  </div>
Now the image will be resized according to the screen size but this will stop at 520px, the width of the image itself.
Wrong. "px" are absolute units 1/96 inches, if I remember correctly, so it won't prevent the image to be magnified if the device resolution is higher than 96ppi.

Last edited by Jellby; 12-06-2015 at 10:22 AM.
Jellby is offline   Reply With Quote
Advert
Old 12-06-2015, 11:08 AM   #3
rubeus
Banned
rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.
 
Posts: 272
Karma: 1224588
Join Date: Sep 2014
Device: Sony PRS 650
Quote:
Originally Posted by Jellby View Post
But I think what you are after is simply "div.cimg img {max-width:100%}". That should show the image at its "natural" size, but resize it down to 100% if it's larger.


All that effort for nothing....

Why didnt you tell this in before?

Quote:
Originally Posted by Jellby View Post
Wrong. "px" are absolute units 1/96 inches, if I remember correctly, so it won't prevent the image to be magnified if the device resolution is higher than 96ppi.
On my devices it is stopping and i'm pretty sure that a 520px width image will use only 520 px regardless what dimensions a pixel has. On my full hd tablet a 520px image is round about a quarter of the screen width having 1920px...

At least i will check my old Sony 650 but as ADE 2 is displaying the image correctly i have no doubt about.

Well, at least theres only a learning effect for me...
rubeus is offline   Reply With Quote
Old 12-06-2015, 12:58 PM   #4
Jellby
frumious Bandersnatch
Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.
 
Jellby's Avatar
 
Posts: 7,516
Karma: 19000001
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
One thing is what the CSS 2.1 and CSS 3 specs say, another thing is what ePub readers actually do (note that ePub 2 is based on CSS 2, not 2.1, so the px definition is a bit more ambiguous). I have seen readers say "10cm" was something like 8.5 cm, and that an A4-sized PDF displayed to fit the 6" screen was at "100%"...
Jellby is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML + Images = MOBI without Images SunLight Amazon Kindle 5 08-25-2012 02:27 PM
What do you do with large graphics that are getting resized? SEI Publications Sigil 5 08-02-2011 05:04 PM
Limit file name wwaldo Calibre 3 04-28-2010 09:04 PM
There Is A Limit C6REW Sony Reader 20 09-06-2008 04:12 PM


All times are GMT -4. The time now is 09:17 PM.


MobileRead.com is a privately owned, operated and funded community.