Best way to scale images when compiling to ebook

I was just wondering how people set up their interior images for Kindle books.

I had started out setting a pixel width for interior images ( <$IMG:name;w=200> ), as I had read somewhere that percentages weren’t supported (Is this correct?).

The problem is that on higher resolution devices the images begin to shrink on the page:

To get around this I have been creating a full-width white background for my images. There is a setting (compile format --> Text Layout 'use 100% width for images wider than x-pts ) that means that now my images are always scaled to 100% width, so they now scale up and down with different devices. Perfect…

However. The only trouble with this is that the white background is now visible when the Kindle is set to Sepia or black:

I think I will have to live with this, as I much prefer that the images scale, but I was just wondering how anybody else had approached this.

Is it there any way to use percentages for images instead of pts or pixels?

Many thanks,
Ian

p.s. When I’m web-developing I use:

width = x%
max-width = xpx

That way an image will always scale up or down until it reaches the maximum desired pixel size. Perfect.
I don’t suppose this is supported in epub or Kindle formats is it?

1 Like

Use the image placeholder tag in the text, for example:

<$img://Users/username/Desktop/scrivenerlogo.png>

And when compiling to ePub 3, edit the Formats > [Format Name] > CSS > Append Custom CSS Stylesheet to add:

img { width: 100% !important; height: auto !important }

You can set the per cent number as you think best.

Does this work as you need it to?

Ah, that works great for the smaller images - thanks! :slight_smile:

Is there a way to add percentage sizes per image? I have some at 50% and some 100%.

It doesn’t seem to work trying to add percentage sizes in the placeholder tags: <$Img:name;w=50%>

Many thanks,
Ian

On this, there is currently no way to add a percentage size, because <$img> tags just get inserted into the text before export using the size tags. However, I have added an extra “ebook” tag for the next update. So, from now on, you could do this:

<$img:ImgName;w=400;ebook=50%>

In this example, the image will appear at 50% the width of the page on ebooks, but be 400pt across for all other formats. If you leave “ebook” out, then ebooks will use the same size as other formats. (“ebook” only works for ePub 3 and KF8, though.)

We’ve recently switched from compiling to mobi to ePub 3 to take advantage of this feature and flowing eBook text.

It doesn’t seem to be working for me… this is the placeholder:

<$Img:./Artwork/Diagrams/Visual-Index.png;ebook=80%> Figure <$n:Figure:<$title_no_spaces>> <$title>

Viewed in several different viewers: Books, calibre, ebook-viewer, Kindle Previewer 3

All come out with the image the same size, irrespective of the percentage, bumping the Figure placeholder onto the following page.

What am I doing wrong?

This is a fantastic solution!

I would like to ask, however, if the ‘w’ and ‘ebook’ parameters can be preceded by a white space in the string. Having them attached to the name of the image file makes the spelling checker underline them. I see doing it breaks the string.

Paolo

Doing what breaks the string? Spelling is irrelevant in code like this. Ignore it.

Writing something like:

<$img: ImgName; w=400; ebook=50%>

instead of:

<$img:ImgName;w=400;ebook=50%>

I would like, but the automatic spelling checker continues to distract me with its red wavy lines. I wouldn’t want to switch it off, because this would make typing errors pass unnoticed.

Paolo

You’ll have to either turn it off or ignore it. The spelling checker is 3rd party; there’s no way for it to know what’s happening in relation to placeholder tags.