From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jack Kamm Subject: Re: Displaying remote images Date: Thu, 28 Nov 2019 18:00:06 -0800 Message-ID: <87tv6nsaqh.fsf@gmail.com> References: <8736e8sza3.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:43343) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iaVaW-0004cE-EE for emacs-orgmode@gnu.org; Thu, 28 Nov 2019 21:00:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iaVaS-0001sR-SD for emacs-orgmode@gnu.org; Thu, 28 Nov 2019 21:00:50 -0500 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]:35488) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iaVaR-0001jB-Hb for emacs-orgmode@gnu.org; Thu, 28 Nov 2019 21:00:48 -0500 Received: by mail-pj1-x102a.google.com with SMTP id s8so12592344pji.2 for ; Thu, 28 Nov 2019 18:00:38 -0800 (PST) Received: from localhost (199-83-220-90.PUBLIC.monkeybrains.net. [199.83.220.90]) by smtp.gmail.com with ESMTPSA id r3sm6890848pfg.145.2019.11.28.18.00.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2019 18:00:35 -0800 (PST) In-Reply-To: <8736e8sza3.fsf@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain I've attached a patch which implements displaying remote images. > This is a longstanding problem, and there was an attempt to patch it in > 2014, but the patch was never accepted: > https://lists.gnu.org/archive/html/emacs-orgmode/2014-11/msg00583.html Compared to the previous attempt from 2014, I think my patch is simpler -- it doesn't require creating any temp files. > The fault might be with image.el rather than with org-mode itself -- > for example, when I execute the following elisp, I get the same blank > box: After doing some reading, I learned that image.el doesn't really create the image. Instead, create-image simply creates a blank string with a text property pointing to the image file location, and the rendering of the image gets handled later by the C code (for example, png_load_body() in image.c), which doesn't know how to read remote image files. Since I wasn't comfortable trying to get the C code to read the remote file, I instead took the approach used by image-mode.el, which reads the remote image file and passes its contents directly to create-image, instead of just passing the filename. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-org-display-remote-images.patch >From 47120666dad6eb0b6ca716325d7de86924e1d28e Mon Sep 17 00:00:00 2001 From: Jack Kamm Date: Thu, 28 Nov 2019 17:45:56 -0800 Subject: [PATCH] org: display remote images --- lisp/org.el | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 90f222c8b..dc7bcc7aa 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -16754,13 +16754,20 @@ buffer boundaries with possible narrowing." (t nil))) (old (get-char-property-and-overlay (org-element-property :begin link) - 'org-image-overlay))) + 'org-image-overlay)) + (remote-p (file-remote-p file))) (if (and (car-safe old) refresh) (image-refresh (overlay-get (cdr old) 'display)) - (let ((image (create-image file + (let ((image (create-image (if (not remote-p) + file + (with-temp-buffer + (insert-file-contents file) + (string-make-unibyte + (buffer-substring-no-properties + (point-min) (point-max))))) (and (image-type-available-p 'imagemagick) width 'imagemagick) - nil + remote-p :width width))) (when image (let ((ov (make-overlay -- 2.24.0 --=-=-=--