help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fetching an image from the net and inserting into the buffer


From: Eli Zaretskii
Subject: Re: Fetching an image from the net and inserting into the buffer
Date: Sat, 25 Oct 2014 10:18:40 +0300

> From: Tom <adatgyujto@gmail.com>
> Date: Sat, 25 Oct 2014 06:54:14 +0000 (UTC)
> 
> I tried this code which when evaluated should insert the
> image fetched from the net at point, but it inserts a rectangle
> instead:
> 
> (insert-image
>  (with-current-buffer 
>      (url-retrieve-synchronously
> "http://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/280px-PNG_transparency_demonstration_1.png";)
>    (goto-char (point-min))
>    (search-forward "\n\n") ;skip headers
>    (create-image (buffer-substring (point) (point-max)) 'png)))
> 
> It's emacs 24.1.1 on windows. Image are supported. If I download
> the image from the above URL to a file and use create-image on 
> that file then it displays properly.
> 
> But why doesn't it work when I try to fetch it dynamically with
> url retrieve?

You need to pass an additional argument to create-image, like this:

  (create-image (buffer-substring (point) (point-max)) 'png t)

That 't' tells create-image it should create an image from the data
that is its 1st argument.  Please see the doc string of the function
for details.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]