Page MenuHomePhabricator

imlib2: Read image from memory (instead of a file)
Closed, ResolvedPublic


I'm not quite sure this is the right place for this feature request. If not, I hope you can point me to the right direction.

Anyway, it would be great if imlib2 could read image content from memory. This would benefit programs that use imlib2 library. For instance, a program could read the image content from standard input (stdin) without needing to write the image content on disk. This would greatly improve security and usability.

On Linux, display program supports showing image content read from stdin:

cat mypicture.png | display

However, sxiv image viewer, which uses imlib2, cannot support that because imlib2 doesn't support reading image content from memory. See: It is possible to work around this by writing stdin to a temporary file, but sxiv shouldn't do it itself, because it would be misleading for the user who expects the content NOT to touch the disk when the content is fed directly to stdin. So, it is left for the user to do some clumsy temporary file stuff.

jluttine created this task.May 18 2020, 4:54 AM

One usecase is to read from clipboard, as can be done with display:

xclip -o -target image/png | display

Another usecase is to decrypt an encrypted image file and show it:

gpg --decrypt my-secret-qr.png.gpg | display

In order to implement this kind of features to programs using imlib2, imlib2 should be able to read image from memory, if I've understood correctly.

kwo added a subscriber: kwo.May 18 2020, 8:23 AM

I think that the feature you request has been implemented in git, after v1.6.1, so no official release yet.

ProhtMeyhet triaged this task as Wishlist priority.Oct 8 2020, 9:43 AM
kwo closed this task as Resolved.Dec 6 2020, 1:18 AM
kwo claimed this task.

Feature is in 1.7.0 - imlib_load_image_from_fd().

Oh, awesome! Thanks @kwo !

NRK added a subscriber: NRK.Nov 1 2021, 12:11 AM

@kwo I assume you mean imlib_load_image_fd() ? Since imlib_load_image_from_fd() does not seem to exist.

Also from some small testing, that function doesn't seem to work on stdin, or any pipes in general.

kwo added a comment.Nov 1 2021, 3:14 AM

Correct, imlib_load_image_fd(). imlib_load_image_from_fd() has only existed in my incorrect comments.
And yes, as is imlib2 cannot read an image from a pipe.

NRK added a comment.Sun, Nov 21, 3:39 AM

Btw, the docs provided on the release tarball (doc/index.html) as well as the live website ( don't have any reference to imlib_load_image_fd(). I assume they're a bit outdated. Shouldn't they be updated on each release?

kwo added a comment.Sun, Nov 21, 8:50 AM

You are right, of course. I may get around to sort that out some day :)