How to change the default show: viewer?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
nicolai.rostov
Posts: 18
Joined: 2015-10-06T10:42:17-07:00
Authentication code: 1151

How to change the default show: viewer?

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to change the default show: viewer?

Post by fmw42 »

I am not well-versed on this, but create your own custom line in the delegates.xml file for your viewer.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to change the default show: viewer?

Post 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"">
snibgo's IM pages: im.snibgo.com
nicolai.rostov
Posts: 18
Joined: 2015-10-06T10:42:17-07:00
Authentication code: 1151

Re: How to change the default show: viewer?

Post 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. :(
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to change the default show: viewer?

Post 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.
snibgo's IM pages: im.snibgo.com
nicolai.rostov
Posts: 18
Joined: 2015-10-06T10:42:17-07:00
Authentication code: 1151

Re: How to change the default show: viewer?

Post 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"" />
nicolai.rostov
Posts: 18
Joined: 2015-10-06T10:42:17-07:00
Authentication code: 1151

Re: How to change the default show: viewer?

Post 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"" /-->
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to change the default show: viewer?

Post by snibgo »

nicolai.rostov wrote:...a typo in your code...
Oops, well spotted. Thanks.
snibgo's IM pages: im.snibgo.com
Post Reply