09-24-2023, 12:36 AM | #1 |
Groupie
Posts: 153
Karma: 474196
Join Date: Jan 2011
Location: Ottawa
Device: Kobo Aura H2O
|
Image sizeing no longer working on some platforms?
*"sizing"
I feel like I'm going crazy here. I recently created an ebook with images in the <h2> headers (an alien language as chapter number), and styled it as I have many times before, with something like: Code:
<h2><img style="height: 1em;max-width: 50%; object-fit: contain;" src="../Images/ch01.jpg"/><br/>Title</h2> I've tried playing around with the specific size values, different images, and creating a brand new epub to no avail, and it's freaking me out a bit because I've been doing this for years and and can't see what I'm missing. See an attached test epub and a screenshot of what it looks like in Moon+ reader. Thanks in advance for any help. Last edited by Vanguard3000; 09-24-2023 at 01:10 AM. |
09-24-2023, 05:43 AM | #2 |
Reading till the spring
Posts: 12,642
Karma: 96386975
Join Date: Jun 2017
Location: Ireland
Device: All 4 Kinds: epub eink, Kindle, android eink, NxtPaper
|
Use a class and CSS rather than an Inline style anyway.
If you want correct aspect ratio and a percentage <h2><img class="ch-image" src="../Images/ch01.jpg"/><br/>Title</h2> .h2 { // no left and right margins (or padding), but do center and set font & size } .ch-image { image-width: 50%; image-height: auto } Last edited by Quoth; 09-24-2023 at 05:46 AM. |
Advert | |
|
09-24-2023, 11:42 AM | #3 |
Groupie
Posts: 153
Karma: 474196
Join Date: Jan 2011
Location: Ottawa
Device: Kobo Aura H2O
|
As I mentioned in my initial post, I had it as a class originally, but it makes no difference to the problem I'm seeing so I simplified my example by inlining it.
In my actual book, I'm overriding h2 to center and style the text, then classing the image via "h2 > img". |
09-25-2023, 07:00 AM | #4 | |
Reading till the spring
Posts: 12,642
Karma: 96386975
Join Date: Jun 2017
Location: Ireland
Device: All 4 Kinds: epub eink, Kindle, android eink, NxtPaper
|
Quote:
|
|
09-25-2023, 01:58 PM | #5 |
Groupie
Posts: 153
Karma: 474196
Join Date: Jan 2011
Location: Ottawa
Device: Kobo Aura H2O
|
If that were the case, the inline styling I've provided as an example ought to work. In any case, here is the stylesheet info from the actual file for reference:
Code:
h2,h3,h4 { page-break-after: avoid; } h2 { text-align: center; font-style: italic; font-size: 2.5em; font-weight: normal; } h2 > img { height: 1em; object-fit: contain; } |
Advert | |
|
09-25-2023, 05:30 PM | #6 |
Reading till the spring
Posts: 12,642
Karma: 96386975
Join Date: Jun 2017
Location: Ireland
Device: All 4 Kinds: epub eink, Kindle, android eink, NxtPaper
|
But your image style and class are both wrong.
You either set height and and width to px (never em or rem), or set one to auto and the other to a % Anything else is unreliable. Like .ch-image { width: 50%; height: auto } Also don't use h2 > img "object-fit: contain" will not be reliable and will distort as height: 1em Last edited by Quoth; 10-01-2023 at 03:12 PM. Reason: mistake |
09-25-2023, 06:06 PM | #7 |
Enthusiast
Posts: 33
Karma: 2538
Join Date: Aug 2023
Location: NW US
Device: none
|
The heading elements <h_> by default is block-level, which means it spreads full line width. It can be assumed that Moon+ is merely holding to the standards expected for the <h2> element and making your image also spread full line width regardless of your CSS.
And...you likely don't want the image to be 1em tall - that's the height of the words on that line, and your image is a fully detailed designed image that can only be viewed when its larger than 1em. So...set the image outside of the <h2> element, and use the <img> tag as Quoth suggested: width: 50%; height: auto; . Read the following at Mozilla. MDN heading MDN block image |
09-26-2023, 01:01 PM | #8 | |
Evangelist
Posts: 471
Karma: 7897546
Join Date: Aug 2013
Location: Hamden, CT
Device: Kindle Paperwhite (11th gen), Scribe
|
Quote:
But, "em" is a perfectly valid way to declare the value, especially for height, if you want the image to scale with user font size changes. For an image that shouldn't change size with font size changes, then px or % would be correct. |
|
09-26-2023, 01:28 PM | #9 | |||
Groupie
Posts: 153
Karma: 474196
Join Date: Jan 2011
Location: Ottawa
Device: Kobo Aura H2O
|
The sample you provided worked as it should (after removing the "image-" the attributes), but I specifically want the image to scale with the h2 text as it's technically a part of the chapter title, which is why I was using em for the height. Is there an alternative that satisfies that requirement?
How come? Is that a limited-compatibility thing? Quote:
In any case, thanks for your help so far. I'm self-taught with this stuff so if there are ways I can improve I'm happy to learn them. Quote:
Quote:
-- I guess the crux of my issue is this: Is there a way to add an image within a paragraph or header block that scales properly with the text? I feel like this shouldn't be a difficult thing but it seems to elude me right now. Last edited by Vanguard3000; 09-26-2023 at 01:50 PM. |
|||
09-26-2023, 08:05 PM | #10 |
Enthusiast
Posts: 33
Karma: 2538
Join Date: Aug 2023
Location: NW US
Device: none
|
Some web link solutions (for Epub3.0) below.
Epub2.0 won't allow CSS min/max, or calc(), or @supports, or @media. But with a bit of reading there you might find an alternate workable option. Moon+ App was a stumbling block even for me and involved additional CSS trickery (on a different CSS issue). Simplified fluid font size: CSS-tricks1 Viewport fluid font size: CSS-tricks2 |
09-27-2023, 06:56 AM | #11 |
Resident Curmudgeon
Posts: 77,187
Karma: 138591138
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
For images you want to scale, use SVG if you can so when it does scale, it will look OK.
|
09-27-2023, 07:45 AM | #12 |
Reading till the spring
Posts: 12,642
Karma: 96386975
Join Date: Jun 2017
Location: Ireland
Device: All 4 Kinds: epub eink, Kindle, android eink, NxtPaper
|
Set height and width (proportionately) in pt or em (1em = 12pt) for images that scale with user selected font size. But only works on some devices/apps. Unreliable!
Normally px should be used and images should not attempt to rescale with user font size selection. |
09-27-2023, 07:48 AM | #13 |
Reading till the spring
Posts: 12,642
Karma: 96386975
Join Date: Jun 2017
Location: Ireland
Device: All 4 Kinds: epub eink, Kindle, android eink, NxtPaper
|
Yes. but there is no way to reliably autoscale with user changing font size. It sometimes works. I agree that if width or height is a % and the other is auto, then SVG is good, but for Amazon KDP simply downscaling a larger png or jpg (no transparency) works better.
|
09-27-2023, 07:56 AM | #14 |
Resident Curmudgeon
Posts: 77,187
Karma: 138591138
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
The problem with using px is that unless you know the screen the ePub is going to be read on, it could maybe be too large or too small.
|
09-27-2023, 01:56 PM | #15 | |
frumious Bandersnatch
Posts: 7,540
Karma: 19001081
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
|
Quote:
Another thing, of course, is whether the reading application knows this and complies with it, but that's the realm of bugs and quirks. |
|
Tags |
image, scale, size |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Netflix No Longer Working!!!! | pokee | Kobo Tablets | 11 | 11-13-2011 12:40 AM |
Calibre No Longer Working | hmf | Calibre | 5 | 06-12-2011 01:45 AM |
Help! Image Consistency across platforms | Souldor_MT | General Discussions | 1 | 04-01-2011 03:50 PM |
Fetch cover image from server no longer working | ki5ck | Calibre | 2 | 02-09-2009 08:09 PM |