GNU bug report logs - #44172
28.0.50; Exporting image data

Previous Next

Package: emacs;

Reported by: Lars Ingebrigtsen <larsi <at> gnus.org>

Date: Fri, 23 Oct 2020 11:19:02 UTC

Severity: normal

Merged with 49347

Found in version 28.0.50

To reply to this bug, email your comments to 44172 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#44172; Package emacs. (Fri, 23 Oct 2020 11:19:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Lars Ingebrigtsen <larsi <at> gnus.org>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 23 Oct 2020 11:19:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: bug-gnu-emacs <at> gnu.org
Subject: 28.0.50; Exporting image data
Date: Fri, 23 Oct 2020 13:18:40 +0200
There's been some discussion off-list about adding simple image
manipulation functions to Emacs, and there's really only three
transforms that are in scope for Emacs: Cropping, rotating and resizing.

Now, there are packages out there that allow doing this, but they rely
on external programs to actually do the image wrangling.  I wondered
what it would take to make it possible to do this in-Emacs, and I think
we basically have all the needed stuff -- we just need to hook it up and
make it available.

1) Making image data available to Emacs Lisp.

This is something that I've often wanted for other reasons -- I want to
know how an SVG was rendered, for instance (especially when doing
font-based stuff), and there's no way to actually tell.

So I think Emacs should have a function like

(export-image-data IMAGE &rest SPECS)

that will just take the image cache data for IMAGE (or the frame
specified by SPECS, if multi-frame) and dump the RGB(A) data into the
current buffer (which should be unibyte, for efficiency), and return
a plist of width/height/bytes-per-pixel/rgb(a) ordering.  This is
basically the PPM binary format, but without the heading.

This allows us to do easy transforms like cropping and rotating from
Lisp, too.

2) Create image files.

But mogrifying images is all well and good, but if we can't save the
data, it's not much use.  Of course we could just save the data as PPM,
but that's not very helpful.  So Emacs needs to be able to write image
files...  which sounds like a big thing, but it isn't really: As long as
we can save .jpeg and .png files, that's fine.

Fortunately, Emacs links with libpng and libjpeg already, so adding a

(encode-image-data TYPE)

function is less work than it would seem.




In GNU Emacs 28.0.50 (build 124, x86_64-pc-linux-gnu, GTK+ Version 3.24.23, cairo version 1.16.0)
 of 2020-10-22 built on xo
Repository revision: 954a4decfcc8e41084789516773b22d0adc11d91
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12008000
System Description: Debian GNU/Linux bullseye/sid


-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#44172; Package emacs. (Fri, 23 Oct 2020 11:47:02 GMT) Full text and rfc822 format available.

Message #8 received at 44172 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 44172 <at> debbugs.gnu.org
Subject: Re: bug#44172: 28.0.50; Exporting image data
Date: Fri, 23 Oct 2020 14:45:43 +0300
> From: Lars Ingebrigtsen <larsi <at> gnus.org>
> Date: Fri, 23 Oct 2020 13:18:40 +0200
> 
> 2) Create image files.

Doesn't svg.el come close enough?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#44172; Package emacs. (Fri, 23 Oct 2020 11:50:01 GMT) Full text and rfc822 format available.

Message #11 received at 44172 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 44172 <at> debbugs.gnu.org
Subject: Re: bug#44172: 28.0.50; Exporting image data
Date: Fri, 23 Oct 2020 13:49:49 +0200
Eli Zaretskii <eliz <at> gnu.org> writes:

> Doesn't svg.el come close enough?

Not really -- if you have an image you've cropped, you can certainly
write it out as .svg, but it'd be huge.  Then PPM would be preferable.
But neither are much good, in general.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#44172; Package emacs. (Fri, 23 Oct 2020 16:25:02 GMT) Full text and rfc822 format available.

Message #14 received at 44172 <at> debbugs.gnu.org (full text, mbox):

From: Alan Third <alan <at> idiocy.org>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 44172 <at> debbugs.gnu.org
Subject: Re: bug#44172: 28.0.50; Exporting image data
Date: Fri, 23 Oct 2020 17:24:19 +0100
On Fri, Oct 23, 2020 at 01:18:40PM +0200, Lars Ingebrigtsen wrote:
> 
> 1) Making image data available to Emacs Lisp.
> 
> This is something that I've often wanted for other reasons -- I want to
> know how an SVG was rendered, for instance (especially when doing
> font-based stuff), and there's no way to actually tell.
> 
> So I think Emacs should have a function like
> 
> (export-image-data IMAGE &rest SPECS)
> 
> that will just take the image cache data for IMAGE (or the frame
> specified by SPECS, if multi-frame) and dump the RGB(A) data into the
> current buffer (which should be unibyte, for efficiency), and return
> a plist of width/height/bytes-per-pixel/rgb(a) ordering.  This is
> basically the PPM binary format, but without the heading.
> 
> This allows us to do easy transforms like cropping and rotating from
> Lisp, too.

Are you talking about using an image spec that we use to display
images, which can already include rotation and resizing?

That would be difficult because the stored image data doesn't have
those transformations applied, unless you're using imagemagick. We'd
have to draw it to a buffer (either on-screen or off) and then read
back that data.

-- 
Alan Third




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#44172; Package emacs. (Sat, 24 Oct 2020 19:52:02 GMT) Full text and rfc822 format available.

Message #17 received at 44172 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Alan Third <alan <at> idiocy.org>
Cc: 44172 <at> debbugs.gnu.org
Subject: Re: bug#44172: 28.0.50; Exporting image data
Date: Sat, 24 Oct 2020 21:51:05 +0200
Alan Third <alan <at> idiocy.org> writes:

> Are you talking about using an image spec that we use to display
> images, which can already include rotation and resizing?

Yes.

> That would be difficult because the stored image data doesn't have
> those transformations applied, unless you're using imagemagick. We'd
> have to draw it to a buffer (either on-screen or off) and then read
> back that data.

But it's the untransformed data that we'd want here, so that sounds
great to me.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Forcibly Merged 44172 49347. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Sun, 04 Jul 2021 13:47:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#44172; Package emacs. (Sun, 31 Oct 2021 15:05:01 GMT) Full text and rfc822 format available.

Message #22 received at 44172 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefan <at> marxist.se>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 44172 <at> debbugs.gnu.org
Subject: Re: bug#44172: 28.0.50; Exporting image data
Date: Sun, 31 Oct 2021 08:04:40 -0700
Lars Ingebrigtsen <larsi <at> gnus.org> writes:

> There's been some discussion off-list about adding simple image
> manipulation functions to Emacs, and there's really only three
> transforms that are in scope for Emacs: Cropping, rotating and resizing.

I think we should have a special `image-edit-mode' to support this.  We
could have a keybinding to go to between that mode and `image-mode' (say
`C-x C-q').

In the short-term, I think `image-mode' should stop pretending it can
edit images by making `image-save' into an obsolete alias for
`write-file'.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#44172; Package emacs. (Sun, 31 Oct 2021 15:12:02 GMT) Full text and rfc822 format available.

Message #25 received at 44172 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Stefan Kangas <stefan <at> marxist.se>
Cc: 44172 <at> debbugs.gnu.org
Subject: Re: bug#44172: 28.0.50; Exporting image data
Date: Sun, 31 Oct 2021 16:11:24 +0100
Stefan Kangas <stefan <at> marxist.se> writes:

> In the short-term, I think `image-mode' should stop pretending it can
> edit images by making `image-save' into an obsolete alias for
> `write-file'.

Yup.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#44172; Package emacs. (Sun, 31 Oct 2021 15:40:02 GMT) Full text and rfc822 format available.

Message #28 received at 44172 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefan <at> marxist.se>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 44172 <at> debbugs.gnu.org
Subject: Re: bug#44172: 28.0.50; Exporting image data
Date: Sun, 31 Oct 2021 08:39:03 -0700
Lars Ingebrigtsen <larsi <at> gnus.org> writes:

> Stefan Kangas <stefan <at> marxist.se> writes:
>
>> In the short-term, I think `image-mode' should stop pretending it can
>> edit images by making `image-save' into an obsolete alias for
>> `write-file'.
>
> Yup.

Oops, this doesn't actually work though, does it?  For example,
`image-save' is also what gives us a command to save images in eww.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#44172; Package emacs. (Sun, 31 Oct 2021 15:43:01 GMT) Full text and rfc822 format available.

Message #31 received at 44172 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Stefan Kangas <stefan <at> marxist.se>
Cc: 44172 <at> debbugs.gnu.org
Subject: Re: bug#44172: 28.0.50; Exporting image data
Date: Sun, 31 Oct 2021 16:42:31 +0100
Stefan Kangas <stefan <at> marxist.se> writes:

>>> In the short-term, I think `image-mode' should stop pretending it can
>>> edit images by making `image-save' into an obsolete alias for
>>> `write-file'.
>>
>> Yup.
>
> Oops, this doesn't actually work though, does it?  For example,
> `image-save' is also what gives us a command to save images in eww.

Oh, `image-save'!  No, that can't be deprecated.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#44172; Package emacs. (Fri, 05 Nov 2021 13:58:01 GMT) Full text and rfc822 format available.

Message #34 received at 44172 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefan <at> marxist.se>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 49347 <at> debbugs.gnu.org, 44172 <at> debbugs.gnu.org
Subject: Re: bug#49347: image-save not working as expected for transformed
 image saving!
Date: Fri, 5 Nov 2021 06:57:48 -0700
Lars Ingebrigtsen <larsi <at> gnus.org> writes:

> Oh, `image-save'!  No, that can't be deprecated.

Maybe we should remove the key binding from `image-mode' though?
Or is it useful in `image-mode' buffers?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#44172; Package emacs. (Sat, 06 Nov 2021 00:39:01 GMT) Full text and rfc822 format available.

Message #37 received at 44172 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Stefan Kangas <stefan <at> marxist.se>
Cc: 49347 <at> debbugs.gnu.org, 44172 <at> debbugs.gnu.org
Subject: Re: bug#49347: image-save not working as expected for transformed
 image saving!
Date: Sat, 06 Nov 2021 01:38:25 +0100
Stefan Kangas <stefan <at> marxist.se> writes:

> Lars Ingebrigtsen <larsi <at> gnus.org> writes:
>
>> Oh, `image-save'!  No, that can't be deprecated.
>
> Maybe we should remove the key binding from `image-mode' though?
> Or is it useful in `image-mode' buffers?

It's not very useful in `image-mode' buffers, but it's nice for
consistency, perhaps?  I think whenever you see an image in Emacs, you
should be able to interact with it that way.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#44172; Package emacs. (Sat, 06 Nov 2021 08:01:02 GMT) Full text and rfc822 format available.

Message #40 received at 44172 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefan <at> marxist.se>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 49347 <at> debbugs.gnu.org, 44172 <at> debbugs.gnu.org
Subject: Re: bug#49347: image-save not working as expected for transformed
 image saving!
Date: Sat, 6 Nov 2021 01:00:10 -0700
Lars Ingebrigtsen <larsi <at> gnus.org> writes:

> It's not very useful in `image-mode' buffers, but it's nice for
> consistency, perhaps?  I think whenever you see an image in Emacs, you
> should be able to interact with it that way.

I'm all for consistency, but in this case I think it confuses more than
it helps.  Actually, to explain what I think, "rotate" is an even better
example than "save", so please bear with me:

- eww: I'm hard-pressed to think of a case when I have ever wanted to
  rotate an image on a website.

- image-dired-thumbnail-mode: the thumbnails are currently rotatable,
  but that just makes it go out of synch with the picture.

- In the icons.el library I'm working on, we will use SVG images as
  icons.  They should not rotate on "r".  The same goes for the logo on
  the about/splash screen, etc.

IOW, I think we should consider "what might the user want to do with an
image here?" and then provide the bindings to do that.  The consistency
I would go for is more along the line of "every time you rotate an
image, it is the 'r' key" rather than "you can always rotate an image,
anywhere, even if it makes no sense".

For `image-save' specifically, I think this command makes sense in eww
as you will obviously want to be able to save images from websites.
I also think it would make obvious sense in a new `image-edit-mode'.

But I don't see that it makes sense in `image-mode' that is
fundamentally about displaying an image in various ways, and where users
might be lead to think that any activated display options (scaling,
etc.) will be reflected in a saved file.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#44172; Package emacs. (Sat, 06 Nov 2021 18:13:01 GMT) Full text and rfc822 format available.

Message #43 received at 44172 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Stefan Kangas <stefan <at> marxist.se>
Cc: 49347 <at> debbugs.gnu.org, 44172 <at> debbugs.gnu.org
Subject: Re: bug#49347: image-save not working as expected for transformed
 image saving!
Date: Sat, 06 Nov 2021 19:12:13 +0100
Stefan Kangas <stefan <at> marxist.se> writes:

> - eww: I'm hard-pressed to think of a case when I have ever wanted to
>   rotate an image on a website.

I do that all the time.  :-)  Well, OK, not all the time, but it's
happened more than once when people post upside-down images for the lulz.

> For `image-save' specifically, I think this command makes sense in eww
> as you will obviously want to be able to save images from websites.
> I also think it would make obvious sense in a new `image-edit-mode'.

I think whenever a user sees an image in Emacs, they should be able to
save it somewhere so that they can use it for something else.

> But I don't see that it makes sense in `image-mode' that is
> fundamentally about displaying an image in various ways, and where users
> might be lead to think that any activated display options (scaling,
> etc.) will be reflected in a saved file.

I see your point.  I have no strong opinions on whether these bindings
should be in image-mode, too -- if they're too confusing, we can remove
them there.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




This bug report was last modified 3 years and 220 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.