Image Resize for Revealjs Presentation with Org-revealjs

Posted by:

The issue

There is a standing issue of how to adjust all the image size globally in revealjs presentation produced via org-reveal, see Can we add a config to make all images not overflow? · Issue #388 · yjwen/org-reveal. This partially stems from how org-mode handle image link in html export.

how image links are handled with org-mode export

The regular orgmode image export image with <div.figure> and <p> tags around the <img> tag, see also org-mode export images to html as figures, not img – Emacs Stack Exchange.


The culprit is the following function from ox-html. Note the suspicious <p> tags, adopted from org-mode export images to html as figures, not img – Emacs Stack Exchange:


You can render org to export <img> in a <figure> tag, instead of a <p> tag with the following code in emacs init file.


Solutions

Add r-stretch class to figure tags

First, render org to export <img> in a <figure> tag, instead of a <p> tag with the following.


Then add the following code in path-to-the-org-presentation/image-size.js and put #+REVEAL_EXTRA_JS: { src: './image-size.js' } at the top of the org file.


With additional js functions revealjs

Adapted from Can we add a config to make all images not overflow? · Issue #388 · yjwen/org-reveal.

  1. define some special functions


  2. append the following line in the body of layoutSlideContents():


  3. use the usual org-mode image link


    NOTES: The above two methods prevent the overflow of images. But stretch css won’t stretch the image to maximum.

Redefine the ox-html function to remove the figure and p tags during export.

org-mode export images to html as figures, not img – Emacs Stack Exchange


insert image link as follows:


NOTES: The images will stretch to maximum with this method.

use html attributes to insert images

I use the following format to embed images with stretch class to achieve a full-size view. The problem is that images are NOT encoded inline in base64 format if you want a single file export, also, the images won’t show in a PDF export. It is only good for revealjs presentation in html format. The inliner tool mentioned above is needed to for single-file convertion.


0

Add a Comment