From mboxrd@z Thu Jan 1 00:00:00 1970
From: =?ISO-8859-1?Q?Jan_B=F6cker?=
Subject: Re: Embedding images as data: URIs in the HTML exporter (was:
MathJax is now the default for HTML math)
Date: Fri, 03 Sep 2010 17:53:01 +0200
Message-ID: <4C8119DD.3030408@jboecker.de>
References: <63B79D2B-9483-481F-B7AB-88BEA753D5C8@gmail.com> <4C66F076.10505@jboecker.de>
<19584.26243.447375.125613@priss.frightenedpiglet.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Return-path:
Received: from [140.186.70.92] (port=46609 helo=eggs.gnu.org)
by lists.gnu.org with esmtp (Exim 4.43) id 1OrYZj-0004zB-0Y
for emacs-orgmode@gnu.org; Fri, 03 Sep 2010 11:53:11 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69)
(envelope-from ) id 1OrYZh-0000al-Pm
for emacs-orgmode@gnu.org; Fri, 03 Sep 2010 11:53:10 -0400
Received: from smtp01.worldserver.net ([217.13.200.37]:33401)
by eggs.gnu.org with esmtp (Exim 4.69)
(envelope-from ) id 1OrYZh-0000ZC-Ks
for emacs-orgmode@gnu.org; Fri, 03 Sep 2010 11:53:09 -0400
In-Reply-To: <19584.26243.447375.125613@priss.frightenedpiglet.com>
List-Id: "General discussions about Org-mode."
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org
Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org
To: sand@blarg.net
Cc: emacs-orgmode List , Carsten Dominik
On 09/03/2010 05:07 AM, sand@blarg.net wrote:
> How about doing the same data: URI embedding for images in the HTML
> exporter? It should be possible to implement it entirely inside
> Emacs. It would have to be optional, of course.
>
> Derek
>
This is certainly possible, the following patch would do this to *every*
image. Maybe someone who knows the HTML exporter code better than I do
can make it configurable and submit a patch.
Bonus points for an extra option which only embeds images smaller than
32 KB to keep it compatible with Internet Explorer.
Maybe something like this configuration variable:
(defcustom org-export-html-embed-images-as-data-uris 'never
"Controls if references to inlined images (see
`org-export-html-inline-images') are replaced with their contents as a
data: URI.
Possible values:
'never (default) All images are inlined using normal URL references.
'always Embed all images as data: URIs.
'up-to-32KB Use data: URIs only for images up to 32 KByte
(Internet Explorer does not allow bigger data: URIs)
See also: http://en.wikipedia.org/wiki/Data_URI_scheme"
:group org-export-html
:type (choice (const never) (const always) (const up-to-32KB)))
-- Jan
---
lisp/org-html.el | 12 +++++++++++-
1 files changed, 11 insertions(+), 1 deletions(-)
diff --git a/lisp/org-html.el b/lisp/org-html.el
index eecda0d..5e5ec95 100644
--- a/lisp/org-html.el
+++ b/lisp/org-html.el
@@ -1820,7 +1820,7 @@ lang=\"%s\" xml:lang=\"%s\">
(if org-par-open "
\n" "")
(if label (format "id=\"%s\" " label) "")))
(format ""
- src
+ (org-export-html-image-to-data-uri src)
(if (string-match "\\
(concat "\n" caption "
")
(if org-par-open "\n" ""))))))))
+(defun org-export-html-image-to-data-uri (src)
+ "Load an image file and convert it to a data: URI.
+See http://en.wikipedia.org/wiki/Data_URI_scheme"
+ (with-temp-buffer
+ (insert-file-contents src)
+ (base64-encode-region (point-min) (point-max))
+ (goto-char 1)
+ (insert "data:;base64,")
+ (buffer-string)))
+
(defun org-export-html-get-bibliography ()
"Find bibliography, cut it out and return it."
(catch 'exit
--
1.7.0.4