unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* imagemagick format detection code
@ 2013-08-11 21:14 Lars Magne Ingebrigtsen
  2013-08-11 21:27 ` Lars Magne Ingebrigtsen
  0 siblings, 1 reply; 10+ messages in thread
From: Lars Magne Ingebrigtsen @ 2013-08-11 21:14 UTC (permalink / raw)
  To: emacs-devel

duckduckgo outputs images as gzipped .ico files, and eww can now almost
display them.  But!  If I create the image from the data in the buffer,
I just get a square which imagemagick uses to tell us "nuh-huh; don't
understand": 

(with-temp-buffer
  (set-buffer-multibyte nil)
  (insert-file-contents-literally "/tmp/b.ico")
  (let ((image (create-image (buffer-string) 'imagemagick t)))
    (pop-to-buffer "*image*")
    (insert-image image "*")))

However, if I create the image with

(create-image "/tmp/b.ico" 'imagemagick)

then it works fine.

Does anybody have any, er, insights to offer here?

-- 
(domestic pets only, the antidote for overdose, milk.)
  No Gnus T-Shirt for sale: http://ingebrigtsen.no/no.php
  and http://lars.ingebrigtsen.no/2013/08/twenty-years-of-september.html




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: imagemagick format detection code
  2013-08-11 21:14 imagemagick format detection code Lars Magne Ingebrigtsen
@ 2013-08-11 21:27 ` Lars Magne Ingebrigtsen
  2013-08-12  1:06   ` Stefan Monnier
  0 siblings, 1 reply; 10+ messages in thread
From: Lars Magne Ingebrigtsen @ 2013-08-11 21:27 UTC (permalink / raw)
  To: emacs-devel

This is apparently a known bug -- ImageMagick isn't able to guess that
something is an ico file, so it needs "help" from the file name.  So one
could say something like

    MagickSetFilename(wand, "ico:favicon.ico");

But then we'd need to keep an alist of MIME types to suffixes like

Content-Type: image/x-icon

and feed that into `create-image' (er...  ":guessed-suffix"?) and then
set it with that function.

Meh.

-- 
(domestic pets only, the antidote for overdose, milk.)
  No Gnus T-Shirt for sale: http://ingebrigtsen.no/no.php
  and http://lars.ingebrigtsen.no/2013/08/twenty-years-of-september.html




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: imagemagick format detection code
  2013-08-11 21:27 ` Lars Magne Ingebrigtsen
@ 2013-08-12  1:06   ` Stefan Monnier
  2013-08-12 15:17     ` Lars Magne Ingebrigtsen
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2013-08-12  1:06 UTC (permalink / raw)
  To: emacs-devel

> and feed that into `create-image' (er...  ":guessed-suffix"?) and then
> set it with that function.

:guessed-suffix sounds like a hack.  Maybe a :format argument would be
better (and the ImageMagick could turn it into a file suffix).

We currently have a bit of a mess wrt to use of "format" and "type"
since they're both used currently to refer to the same thing, which is
not really the type or format of the image but rather something like the
rendering library used.


        Stefan



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: imagemagick format detection code
  2013-08-12  1:06   ` Stefan Monnier
@ 2013-08-12 15:17     ` Lars Magne Ingebrigtsen
  2013-08-12 17:43       ` Thien-Thi Nguyen
  2013-08-13 14:23       ` Stefan Monnier
  0 siblings, 2 replies; 10+ messages in thread
From: Lars Magne Ingebrigtsen @ 2013-08-12 15:17 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> and feed that into `create-image' (er...  ":guessed-suffix"?) and then
>> set it with that function.
>
> :guessed-suffix sounds like a hack.  Maybe a :format argument would be
> better (and the ImageMagick could turn it into a file suffix).

Or we could explicit and call it :content-type, since that's what it
is.  But that may lead callers to expect that it (always) be heeded
instead of treating it as a hint.  Uhm...  :content-type-hint?

And then, as you say, the ImageMagick code in image.c will do the right
thing.

For instance, have an alist where the initial population is just

'(("image/x-icon" "ico"))

and we'd set the file name to (say) "/tmp/foo.ico" before asking
ImageMagick to parse the data blob.

If this doesn't seem too gruesome, I can implement this, and we'll see
whether there are further elements that should be added after a while...

> We currently have a bit of a mess wrt to use of "format" and "type"
> since they're both used currently to refer to the same thing, which is
> not really the type or format of the image but rather something like the
> rendering library used.

Yes.  This will add to the general confusion in this area.

-- 
(domestic pets only, the antidote for overdose, milk.)
  No Gnus T-Shirt for sale: http://ingebrigtsen.no/no.php
  and http://lars.ingebrigtsen.no/2013/08/twenty-years-of-september.html



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: imagemagick format detection code
  2013-08-12 15:17     ` Lars Magne Ingebrigtsen
@ 2013-08-12 17:43       ` Thien-Thi Nguyen
  2013-08-13 14:23       ` Stefan Monnier
  1 sibling, 0 replies; 10+ messages in thread
From: Thien-Thi Nguyen @ 2013-08-12 17:43 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 794 bytes --]

() Lars Magne Ingebrigtsen <larsi@gnus.org>
() Mon, 12 Aug 2013 17:17:39 +0200

   Yes.  This will add to the general confusion in this area.

Another idea (that may or may not increase confusion) is to
use GNU libextractor:

 http://www.gnu.org/software/libextractor/

for image type (format) detection, and perhaps (w/ a SMOP) as an
additional "magic" for ‘magic-mode-alist’, something like:

 (EXTRACTOR-SPEC . FUNCTION)

where EXTRACTOR-SPEC is a non-string (otherwise it would be taken as
REGEXP) form that configures libextractor to DTRT.

-- 
Thien-Thi Nguyen
   GPG key: 4C807502
   (if you're human and you know it)
      read my lisp: (responsep (questions 'technical)
                               (not (via 'mailing-list)))
                     => nil

[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: imagemagick format detection code
  2013-08-12 15:17     ` Lars Magne Ingebrigtsen
  2013-08-12 17:43       ` Thien-Thi Nguyen
@ 2013-08-13 14:23       ` Stefan Monnier
  2013-08-13 18:14         ` Lars Magne Ingebrigtsen
  1 sibling, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2013-08-13 14:23 UTC (permalink / raw)
  To: Lars Magne Ingebrigtsen; +Cc: emacs-devel

> Or we could explicit and call it :content-type, since that's what it
> is.  But that may lead callers to expect that it (always) be heeded
> instead of treating it as a hint.  Uhm...  :content-type-hint?

I like content-type in the sense that I'd like to see it used as an
intermediate step between file names and major modes.  But I'm not sure
it's the right thing here.

> '(("image/x-icon" "ico"))

For example, here we end up using a non-official content-type because
there's no official content-type for it.

This said, it's probably no worse than hacking up our own
classification, so... yes, I guess it's a good plan.  But please make
them be symbols rather than strings:

 '((image/x-icon . "ico"))

>> We currently have a bit of a mess wrt to use of "format" and "type"
>> since they're both used currently to refer to the same thing, which is
>> not really the type or format of the image but rather something like the
>> rendering library used.
> Yes.  This will add to the general confusion in this area.

We should at least rework the doc to use "type" everywhere, so we can
use :format for the new notion.


        Stefan



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: imagemagick format detection code
  2013-08-13 14:23       ` Stefan Monnier
@ 2013-08-13 18:14         ` Lars Magne Ingebrigtsen
  2013-08-13 18:19           ` Lars Magne Ingebrigtsen
  2013-08-13 18:56           ` Stefan Monnier
  0 siblings, 2 replies; 10+ messages in thread
From: Lars Magne Ingebrigtsen @ 2013-08-13 18:14 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> This said, it's probably no worse than hacking up our own
> classification, so... yes, I guess it's a good plan.  But please make
> them be symbols rather than strings:
>
>  '((image/x-icon . "ico"))

I've now committed an attempt at this.  That is, it works, and one can
now use duckduckgo.com and get nice images in the search results in eww,
but I'm not sure about the implementation.

Perhaps the rummaging around in the alist should have been done on the
elisp side instead of in C.  I always feel that I'm doing something not
quite...  good...  when I'm writing Lisp in C:

  suffix = Fcar (Fcdr (Fassq (content_type, Fsymbol_value (symbol))));

Anyway.  

>>> We currently have a bit of a mess wrt to use of "format" and "type"
>>> since they're both used currently to refer to the same thing, which is
>>> not really the type or format of the image but rather something like the
>>> rendering library used.
>> Yes.  This will add to the general confusion in this area.
>
> We should at least rework the doc to use "type" everywhere, so we can
> use :format for the new notion.

Yup.

-- 
(domestic pets only, the antidote for overdose, milk.)
  No Gnus T-Shirt for sale: http://ingebrigtsen.no/no.php
  and http://lars.ingebrigtsen.no/2013/08/twenty-years-of-september.html



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: imagemagick format detection code
  2013-08-13 18:14         ` Lars Magne Ingebrigtsen
@ 2013-08-13 18:19           ` Lars Magne Ingebrigtsen
  2013-08-13 18:56           ` Stefan Monnier
  1 sibling, 0 replies; 10+ messages in thread
From: Lars Magne Ingebrigtsen @ 2013-08-13 18:19 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Lars Magne Ingebrigtsen <larsi@gnus.org> writes:

> Perhaps the rummaging around in the alist should have been done on the
> elisp side instead of in C.  I always feel that I'm doing something not
> quite...  good...  when I'm writing Lisp in C:
>
>   suffix = Fcar (Fcdr (Fassq (content_type, Fsymbol_value (symbol))));
>
> Anyway.  

Especially that one, since it can error out.  I'll fix.

-- 
(domestic pets only, the antidote for overdose, milk.)
  No Gnus T-Shirt for sale: http://ingebrigtsen.no/no.php
  and http://lars.ingebrigtsen.no/2013/08/twenty-years-of-september.html



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: imagemagick format detection code
  2013-08-13 18:14         ` Lars Magne Ingebrigtsen
  2013-08-13 18:19           ` Lars Magne Ingebrigtsen
@ 2013-08-13 18:56           ` Stefan Monnier
  2013-08-13 19:05             ` Lars Magne Ingebrigtsen
  1 sibling, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2013-08-13 18:56 UTC (permalink / raw)
  To: Lars Magne Ingebrigtsen; +Cc: emacs-devel

>> We should at least rework the doc to use "type" everywhere, so we can
>> use :format for the new notion.
> Yup.

Yet I see you've used :content-type rather than :format.


        Stefan



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: imagemagick format detection code
  2013-08-13 18:56           ` Stefan Monnier
@ 2013-08-13 19:05             ` Lars Magne Ingebrigtsen
  0 siblings, 0 replies; 10+ messages in thread
From: Lars Magne Ingebrigtsen @ 2013-08-13 19:05 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>>> We should at least rework the doc to use "type" everywhere, so we can
>>> use :format for the new notion.
>> Yup.
>
> Yet I see you've used :content-type rather than :format.

Sorry, I misinterpreted you.  I thought you wanted :content-type for
this hint-ey usage.  I'll change it to :format.

-- 
(domestic pets only, the antidote for overdose, milk.)
  No Gnus T-Shirt for sale: http://ingebrigtsen.no/no.php
  and http://lars.ingebrigtsen.no/2013/08/twenty-years-of-september.html



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2013-08-13 19:05 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-11 21:14 imagemagick format detection code Lars Magne Ingebrigtsen
2013-08-11 21:27 ` Lars Magne Ingebrigtsen
2013-08-12  1:06   ` Stefan Monnier
2013-08-12 15:17     ` Lars Magne Ingebrigtsen
2013-08-12 17:43       ` Thien-Thi Nguyen
2013-08-13 14:23       ` Stefan Monnier
2013-08-13 18:14         ` Lars Magne Ingebrigtsen
2013-08-13 18:19           ` Lars Magne Ingebrigtsen
2013-08-13 18:56           ` Stefan Monnier
2013-08-13 19:05             ` Lars Magne Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.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).