emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Grant Rettke <gcr@wisdomandwonder.com>
To: Greg Sexton <gsexton@amazon.co.uk>
Cc: "emacs-orgmode@gnu.org" <emacs-orgmode@gnu.org>
Subject: Re: Base 64 inline images in html export
Date: Tue, 22 Dec 2015 19:48:00 -0600	[thread overview]
Message-ID: <CAAjq1mfmVB9P3uC2Xji4bUGeYgNwpGkKt7K4Vs_FmtRO8q9q9Q@mail.gmail.com> (raw)
In-Reply-To: <cieptky4d6lait.fsf@amazon.co.uk>

Since you too are exploring packaging, this might give you some test:

http://kitchingroup.cheme.cmu.edu/blog/2014/03/05/Creating-a-transportable-zip-archive-of-an-org-file/
Sincerely,

Grant Rettke


On Mon, Dec 7, 2015 at 6:15 AM, Greg Sexton <gsexton@amazon.co.uk> wrote:
> Hi,
>
> I did find a post about this from around 2009 but I'm not sure it went
> anywhere. It's very useful for me to be able to export a single html
> file that I can distribute around. Base 64 encoding images directly in
> to the exported html makes this possible.
>
> The feature seems fairly well supported by browsers these days.[1]
>
> I've hacked up this ugly proof of concept. I guess it wouldn't take too
> much to productionize this and make the behavior configurable. Any
> thoughts?
>
> --8<---------------cut here---------------start------------->8---
> (defun gs/b64-img (file-uri)
>   (let ((file (s-replace "file://" "" file-uri)))
>     (if (f-exists? file)
>         ;; src="data:image/png;base64,iVBORw0KGgoAAAANSUh..."
>         (s-concat "data:image/"
>                   (f-ext file)
>                   ";base64,"
>                   (base64-encode-string (f-read-bytes file)))
>       file-uri)))
>
> (defun org-html--format-image (source attributes info)
>   "Return \"img\" tag with given SOURCE and ATTRIBUTES.
> SOURCE is a string specifying the location of the image.
> ATTRIBUTES is a plist, as returned by
> `org-export-read-attribute'.  INFO is a plist used as
> a communication channel."
>   (org-html-close-tag
>    "img"
>    (org-html--make-attribute-string
>     (org-combine-plists
>      (list :src (gs/b64-img source)   ; <-- interesting line is here
>            :alt (if (string-match-p "^ltxpng/" source)
>                     (org-html-encode-plain-text
>                      (org-find-text-property-in-string 'org-latex-src source))
>                   (file-name-nondirectory source)))
>      attributes))
>    info))
> --8<---------------cut here---------------end--------------->8---
>
>
> [1]: http://stackoverflow.com/questions/1207190/embedding-base64-images
>
> --
>  Greg
>
>
>
> Amazon Development Centre (London) Ltd. Registered in England and Wales with registration number 04543232 and which has its registered office at Leadenhall Court, One Leadenhall Street, London EC3V 1PP, United Kingdom.
>
>

  parent reply	other threads:[~2015-12-23  1:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-07 12:15 Base 64 inline images in html export Greg Sexton
2015-12-08 18:47 ` Rasmus
2015-12-23  1:48 ` Grant Rettke [this message]
2015-12-23  2:04   ` John Kitchin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAAjq1mfmVB9P3uC2Xji4bUGeYgNwpGkKt7K4Vs_FmtRO8q9q9Q@mail.gmail.com \
    --to=gcr@wisdomandwonder.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=gsexton@amazon.co.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).