1

According to the ImageMagick manual, file descriptors are supported as of v.6.4.9-3. I am running v.6.9.7-4. However, I have been able to determine the correct syntax. Examples tried:

convert 'xc:white[100x100!]' fd:3 ;       display fd:3
convert 'xc:white[100x100!]' miff:fd:3 ;  display fd:3
convert 'xc:white[100x100!]' miff: fd:3 ; display fd:3
convert 'xc:white[100x100!]' miff:fd:3 ;  display miff:fd:3

The error produced by the first and second commands is as follows:

convert-im6.q16: no encode delegate for this image format `FD' @ error/constitute.c/WriteImage/1176.
display-im6.q16: no decode delegate for this image format `' @ error/constitute.c/ReadImage/504.
display-im6.q16: no data returned `3' @ error/fd.c/ReadFDImage/123.

The third command causes the terminal to hang but eventually produces the same error message as the first two commands. The fourth command produces the following error:

Aborted
display-im6.q16: improper image header `/tmp/magick-7315YQugjYiINA9c' @ error/miff.c/ReadMIFFImage/507.

The redirection can be accomplished using native bash file descriptors instead of ImageMagick's cross-platform implementation thereof; e.g.,

exec 3> myfifo ; convert 'xc:white[100x100!]' miff:- 1>&3 ; exec 3>&-; exec 3< myfifo; display - 0<&3 ; exec 3<&- ; rm myfifo

or

exec 3> myfifo ; convert 'xc:white[100x100!]' miff:- 1>&3 ; exec 3>&-; exec 3< myfifo; display <&3 ; exec 3<&- ; rm myfifo

However, that is much longer to write and is also not cross-platform, so I am hoping to be able to figure out ImageMagick's file descriptor syntax.

My intent is to be able to read from multiple fds for a convert command, for instance:

<upstream commands> | convert - fd:3 -append | <downstream commands>

Edit:

I was able to use the following hybrid approach:

exec 3> myfifo ; convert 'xc:white[100x100!]' miff:- 1>&3 ; exec 3>&-; exec 3< myfifo; display fd:3 ; exec 3<&- ; rm myfifo

Trying to write to fd:3, however, does not work:

exec 3> myfifo ; convert 'xc:white[100x100!]' miff:fd:3 ; exec 3>&-; exec 3< myfifo; display fd:3 ; exec 3<&- ; rm myfifo
  • What does "not working" mean? Any error message? Is the resulting image corrupted or in the wrong format? I have no problem to have convert (IM 6.8) read or write to fds. – xhienne Aug 30 '17 at 23:49
  • miff:fd:3 produces a file of length 0 for me (6.9.2-7), but gif:fd:3 and jpg:fd:3 work ok, so it might be a bug for some image formats. – meuh Aug 31 '17 at 13:21
  • @xhienne : I added error message information to the post. – user001 Aug 31 '17 at 16:54
  • @meuh : The command also fails when I try other formats (e.g., convert 'xc:white[100x100!]' gif:fd:3; the error message is simply Aborted). – user001 Aug 31 '17 at 16:55
  • I agree with meuh, this seems like a bug. convert 'xc:white[100x100!]' png:fd:10 10> /tmp/foo.png works well for me. OTOH, with jpg and miff, only stdout (i.e. jpeg:- or miff:-) is actually working. As for your Aborted error message, I get this when my fd is not opened for writing. – xhienne Aug 31 '17 at 23:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.