Page 1 of 1

How to change the default show: viewer?

Posted: 2016-01-27T18:23:46-07:00
by nicolai.rostov
How can I use a viewer other than IM's native display when using show: as the output of the command-line tool convert?

For example, suppose that I want to preview in ExactImage's edisplay an image generated by ImageMagick's convert:

Code: Select all

$ convert input.png -trim output.png
$ edisplay output.png
Is it possible to shortcut that to this?

Code: Select all

$ convert input.png -trim show:
Thanks.

Re: How to change the default show: viewer?

Posted: 2016-01-27T18:54:45-07:00
by fmw42
I am not well-versed on this, but create your own custom line in the delegates.xml file for your viewer.

Re: How to change the default show: viewer?

Posted: 2016-01-27T19:31:48-07:00
by snibgo
As Fred says. In delegates.xml, find the line with "show", something like this:

Code: Select all

  <delegate decode="png" encode="show" spawn="True" mode="encode" command="imdisplay "%i"" />
Delete or comment that out, and add your own. Probably:

Code: Select all

  <!-- delegate decode="png" encode="show" spawn="True" mode="encode" command="imdisplay "%i"" / -->
  <delegate decode="png" encode="show" spawn="True" mode="encode" command="edisplay "%i"">

Re: How to change the default show: viewer?

Posted: 2016-01-27T21:02:58-07:00
by nicolai.rostov
Thank you both. :) My /etc/ImageMagick/delegates.xml lacks such a line, though (ImageMagick 6.7.7-10). At any rate, I guess this hack would work only for PNG files but not generally, that is, not for any other format whatever.

I found out that merely replacing the executable /usr/bin/display with another one won't do either, since convert seems to hand its result down to the viewer through a ephemeral: coder, which seems to handle temporary files. I guess only IM's display will be able to understand this. :(

Re: How to change the default show: viewer?

Posted: 2016-01-27T21:26:51-07:00
by snibgo
6.7.7 is very old. You might consider upgrading. However, the technique worked then. If you add the line to delegates.xml, it should work.
nicolai.rostov wrote:At any rate, I guess this hack would work only for PNG files but not generally, that is, not for any other format whatever.
It isn't a hack. IM doesn't contain code to do everything that a user might want, and is designed to delegate work to other software. These delegates might be internal (compiled into IM binaries) or external (called via delegates.xml).

With that line in delegates.xml, if you write an image to "show:" then IM will write it in PNG format, for the viewer to read. So it will only work if your viewer can read that format. Most viewers can.

This is different to the convert command's input file. That can be any input format that IM can read.

IM waits for the delegate to finish before deleting the ephemeral file. So that shouldn't cause problems.

Re: How to change the default show: viewer?

Posted: 2016-01-27T22:07:42-07:00
by nicolai.rostov
Excellent. The method does indeed work. Thanks. :) There is, however, a typo in your code that prevents it from working as it is. We need to insert a slash at the end of the XML element. Otherwise the output will be written to a file named "show:", not delegated to a viewer. It should be as follows:

Code: Select all

<delegate decode="png" encode="show" spawn="True" mode="encode" command="edisplay "%i"" />

Re: How to change the default show: viewer?

Posted: 2016-01-27T22:45:41-07:00
by nicolai.rostov
Also, it seems we need to comment out the "miff" XML element as well. If input is a PBM file, then output still goes to IM's display. Don't ask me why. :?

Code: Select all

<!--delegate decode="miff" encode="show" spawn="True" command=""/usr/bin/display" -delay 0 -window-group %[group] -title "%l " "ephemeral:%i"" /-->

Re: How to change the default show: viewer?

Posted: 2016-01-27T22:55:12-07:00
by snibgo
nicolai.rostov wrote:...a typo in your code...
Oops, well spotted. Thanks.