Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Formats > ePub

Notices

Reply
 
Thread Tools Search this Thread
Old 09-27-2025, 08:15 AM   #1
ElMiko
Evangelist
ElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileRead
 
ElMiko's Avatar
 
Posts: 488
Karma: 65460
Join Date: Jun 2011
Device: Kindle
Variable/fixed image height

In the Kindle OS, images with a fixed height (and no specified width) that would exceed the screen width are resized proportionally to fit the screen width. In other words the fixed height is functionally overwritten to fit the image proportionally to the screen if honoring it (proportionally) would result in the image's exceeding the screen width. Otherwise, the fixed height value is honored as long as the implied image width is less than the width of the screen.

How would someone code this kind of conditional behavior in css for epub2 to acheive similar outcomes on non-Kindle, epub-based readers?

Last edited by ElMiko; 09-27-2025 at 08:22 AM.
ElMiko is offline   Reply With Quote
Old 09-27-2025, 04:55 PM   #2
Turtle91
A Hairy Wizard
Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.
 
Turtle91's Avatar
 
Posts: 3,377
Karma: 20212733
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 15/11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
Try an svg wrapper.
Turtle91 is offline   Reply With Quote
Old Yesterday, 08:58 AM   #3
ElMiko
Evangelist
ElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileRead
 
ElMiko's Avatar
 
Posts: 488
Karma: 65460
Join Date: Jun 2011
Device: Kindle
Okay, so lets say i want the attached image to have a height of 4em (unless this would results in a concomitant width that exceeded the device's screen width)...

how would this work with an svg wrapper, bearing in mind this is not a standalone image, but one that occurs with normal text above and below it?
Attached Thumbnails
Click image for larger version

Name:	SigilTestImg.jpg
Views:	13
Size:	18.9 KB
ID:	218337  
ElMiko is offline   Reply With Quote
Old Yesterday, 09:52 AM   #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,566
Karma: 20150435
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
What's wrong with "max-height: 4em; max-width: 100%"? Is the natural height of the image less than 4em?
Jellby is offline   Reply With Quote
Old Yesterday, 01:38 PM   #5
ElMiko
Evangelist
ElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileRead
 
ElMiko's Avatar
 
Posts: 488
Karma: 65460
Join Date: Jun 2011
Device: Kindle
As I understand it, "em" isn't a absolute unit, it's a relative unit. So, I mean, I guess it's as natural as any other em value.

Regarding max-width, the issue is that setting it at 100% means that the image will appear to stretch vertically if the screen width is too narrow relative to the defined height. See the attached images: test1 has a viewing window that accomodates both the defined 4em height and the proportionally scaled width; test2 shows what happens when the viewing window is narrower than a 4em height and a proportional width would allow—namely, it preserves the height and squishes it width-wise to fit it all on the screen.
Attached Thumbnails
Click image for larger version

Name:	test1.jpg
Views:	9
Size:	76.6 KB
ID:	218357   Click image for larger version

Name:	test2.jpg
Views:	8
Size:	62.8 KB
ID:	218358  

Last edited by ElMiko; Yesterday at 01:49 PM.
ElMiko is offline   Reply With Quote
Old Yesterday, 01:56 PM   #6
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 80,356
Karma: 148951763
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
Quote:
Originally Posted by ElMiko View Post
As I understand it, "em" isn't a absolute unit, it's a relative unit. So, I mean, I guess it's as natural as any other em value.

Regarding max-width, the issue is that setting it at 100% means that the image will appear to stretch vertically if the screen width is too narrow relative to the defined height. See the attached images: test1 has a viewing window that accomodates both the defined 4em height and the proportionally scaled width; test2 shows what happens when the viewing window is narrower than a 4em height and a proportional width would allow—namely, it preserves the height and squishes it width-wise to fit it all on the screen.
Why not just make it real text? One thing I dislike is graphics taking the place of text when there's no good reason for it.
JSWolf is offline   Reply With Quote
Old Yesterday, 02:31 PM   #7
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,566
Karma: 20150435
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
Quote:
Originally Posted by ElMiko View Post
As I understand it, "em" isn't a absolute unit, it's a relative unit. So, I mean, I guess it's as natural as any other em value.
With "natural" height, I mean the height of the image if you don't specify any height. If it's smaller than 4em, setting max-height:4em will not do anything.

Quote:
Regarding max-width, the issue is that setting it at 100% means that the image will appear to stretch vertically if the screen width is too narrow relative to the defined height.
Not in Firefox, or in the calibre viewer, or in KOReader, at least with the attached test, as far as I can see.
Attached Files
File Type: epub test.epub (19.4 KB, 2 views)

Last edited by Jellby; Yesterday at 02:38 PM.
Jellby is offline   Reply With Quote
Old Yesterday, 03:39 PM   #8
ElMiko
Evangelist
ElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileRead
 
ElMiko's Avatar
 
Posts: 488
Karma: 65460
Join Date: Jun 2011
Device: Kindle
Quote:
Originally Posted by JSWolf View Post
Why not just make it real text? One thing I dislike is graphics taking the place of text when there's no good reason for it.
JSWolf, for pete's sake just imagine it's an image that is not text based and doesn't have a wingding equivalent and, and, and.... I created it as a simple illustrative example.

But even if it were the exact case, this is the kind of advice that is really crazy-making:

-- Question: How do i solve problem X?
-- Answer: By deciding you no longer want to solve problem X.

The issue I described in my original post was not "I want to make a image of text behave a
certain way" it was "I want to make an image behave a certain way", so telling me not to use text images is a non-sequitur.

@Jellby - I think I'm seeing the difference between our two codes, and I don't really understand what the implications are:

Basically, in your test version the height is defined at the <div> level, not the <img> level, resulting in the correct scaling that you observed. I'm confused, though, why definiing the height at the <img> level would result in squishing, and I'm wondering if there are any other unintended consequences depending on which level the height/width values are assigned. Do you know?

EDIT: Welp, I've found unintended consequences...

Whatever protocol PageEdit is using to parse height/width values defined at the <div> results in the image going off the screen (see test3, attached).

And in the EpubJSReader Sigil plugin it cuts off part of the right-hand side of the image (see test4).
Attached Thumbnails
Click image for larger version

Name:	test3.jpg
Views:	6
Size:	137.3 KB
ID:	218363   Click image for larger version

Name:	test4.jpg
Views:	5
Size:	124.6 KB
ID:	218364  

Last edited by ElMiko; Yesterday at 04:02 PM.
ElMiko is offline   Reply With Quote
Old Yesterday, 05:40 PM   #9
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 80,356
Karma: 148951763
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
Quote:
Originally Posted by ElMiko View Post
JSWolf, for pete's sake just imagine it's an image that is not text based and doesn't have a wingding equivalent and, and, and.... I created it as a simple illustrative example.

But even if it were the exact case, this is the kind of advice that is really crazy-making:

-- Question: How do i solve problem X?
-- Answer: By deciding you no longer want to solve problem X.

The issue I described in my original post was not "I want to make a image of text behave a
certain way" it was "I want to make an image behave a certain way", so telling me not to use text images is a non-sequitur.

@Jellby - I think I'm seeing the difference between our two codes, and I don't really understand what the implications are:

Basically, in your test version the height is defined at the <div> level, not the <img> level, resulting in the correct scaling that you observed. I'm confused, though, why definiing the height at the <img> level would result in squishing, and I'm wondering if there are any other unintended consequences depending on which level the height/width values are assigned. Do you know?

EDIT: Welp, I've found unintended consequences...

Whatever protocol PageEdit is using to parse height/width values defined at the <div> results in the image going off the screen (see test3, attached).

And in the EpubJSReader Sigil plugin it cuts off part of the right-hand side of the image (see test4).
I did give you a solution because it's sans-serif text. You may not like it, but it's a valid solution.
JSWolf is offline   Reply With Quote
Old Yesterday, 05:45 PM   #10
ElMiko
Evangelist
ElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileRead
 
ElMiko's Avatar
 
Posts: 488
Karma: 65460
Join Date: Jun 2011
Device: Kindle
It's not a valid solution to the original problem as it was articulated. Has nothing to do with what I might like or not. It has to do with your addressing the topic. You might as well have objected to my creating an ebook out of a fraction of the "Lorem ipsum..." text. Its content was as relevant to the question as the visual content of the image.

Instead, you have taken the liberty of inventing your own problem to solve, namely: someone desperately wants to know if JSWolf thinks an image file is the worst way to display text in an ebook, and is annoyed by it. So, I guess on that count you absolutely nailed the answer.

Last edited by ElMiko; Yesterday at 05:54 PM.
ElMiko is offline   Reply With Quote
Old Yesterday, 06:07 PM   #11
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 80,356
Karma: 148951763
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
To solve the problem, make the image the height you want. Then the only issue will be if it has to reduced in width. You have two options. It can be reduced so the aspect ratio is correct or reduced so the aspect ratio is not correct.
JSWolf is offline   Reply With Quote
Old Yesterday, 07:13 PM   #12
RbnJrg
Wizard
RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.
 
Posts: 1,861
Karma: 8821117
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Well, you want a solution for epub2. With this restriction in mind, you'll need to use an SVG wrapper and assign it the "display: inline-block; width: 100%; margin: 1em 0; text-indent:0" properties. This seems to work:

Inlined_Block_SVG.epub

Click image for larger version

Name:	One1.jpg
Views:	5
Size:	105.8 KB
ID:	218370

Crop to content the image before including it in the svg wrapper and use margins (or paddings) to add blank spaces. Of course, I set "margin; 1em 0" but you can set the values you want.

Last edited by RbnJrg; Yesterday at 07:15 PM.
RbnJrg is offline   Reply With Quote
Old Yesterday, 07:14 PM   #13
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 80,356
Karma: 148951763
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
Quote:
Originally Posted by RbnJrg View Post
Well, you want a solution for epub2. With this restriction in mind, you'll need to use an SVG wrapper and assign it the "display: inline-block; width: 100%; margin: 1em 0; text-indent:0" properties. This seems to work:

Attachment 218369

Attachment 218370

Crop to content the image before including it in the svg wrapper and use margins (or paddings) to add blank spaces.
That's a rather good solution.
JSWolf is offline   Reply With Quote
Reply

Tags
image height, image scaling


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
line-height is fixed? nano5 Viewer 5 01-25-2025 08:01 AM
Image height JSWolf KOReader 6 03-29-2021 04:29 PM
QT5 and image height Turtle91 Sigil 23 02-21-2013 01:44 PM
Image height in div soparch ePub 5 03-29-2012 01:18 PM
What image height causes images to fill the screen? karenbryant ePub 7 01-04-2012 04:23 AM


All times are GMT -4. The time now is 02:52 AM.


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