emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nick Dokos <ndokos@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: Displaying remote images
Date: Mon, 02 Dec 2019 15:27:09 -0500	[thread overview]
Message-ID: <871rtmbhia.fsf@alphaville.usersys.redhat.com> (raw)
In-Reply-To: 87tv6nsaqh.fsf@gmail.com

Jack Kamm <jackkamm@gmail.com> writes:

> 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.
>
> From 47120666dad6eb0b6ca716325d7de86924e1d28e Mon Sep 17 00:00:00 2001
> From: Jack Kamm <jackkamm@gmail.com>
> 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

FWIW, looks good to me, but I've only (carefully) read the patch: I have not actually ran it.

-- 
Nick

"There are only two hard problems in computer science: cache
invalidation, naming things, and off-by-one errors." -Martin Fowler

  parent reply	other threads:[~2019-12-02 20:27 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-28 17:09 Displaying remote images Jack Kamm
2019-11-28 21:50 ` briangpowell .
2019-11-29  1:39   ` Jack Kamm
2019-11-29  2:00 ` Jack Kamm
2019-11-29  5:36   ` briangpowell .
2019-12-02 20:27   ` Nick Dokos [this message]
2019-12-02 22:39     ` briangpowell .
2019-12-07 14:41     ` Jack Kamm
2020-01-19 22:17       ` Jack Kamm
2020-01-21 16:39         ` Nicolas Goaziou
2020-01-22 15:31           ` stardiviner
2020-01-25  0:28           ` Jack Kamm
2020-02-01 10:51             ` Nicolas Goaziou

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=871rtmbhia.fsf@alphaville.usersys.redhat.com \
    --to=ndokos@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /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).