Well, Irfanview in this case :-)
Anyone who has used Irfanview knows that it’s the best image viewer and lightweight editor out there. It’s fast, handy and the photo correction functions can do some amazing things to photos. Only problem for us Linux fans is, it’s a windows-only application. To run windows applications under Linux, we have Wine, the Windows Emulator (the Wine guys don’t like that name but that describes what it does.) We run into a few more complications with wine. Two major ones are spaces in file names and backslashes (\) instead of regular slashes (/) to separate directory names in a fully qualified path.
How that complicates things is that when we need to pass arguments to a program, they must be in the proper format. For example, if I wanted to use Irfanview to look at a file in my home directory on drive C under windows, I might say:
iview_32 my documents\foo.jpg
This is from the command prompt, of course. When you click on a file and have Irfanview installed as the default for JPEGs, the above style argument is passed to Irfanview when Windows Explorer starts it up. That doesn’t work in Linux because the “\” character is the escape character. That is, it tells the shell not to process the next character but to pass it on to the application. Guru talk, eh? Somewhat, but bear with me.
We might thing that something of the style:
would work. Linux is happy as a clam in sauce with that but Irfanview has severe heartburn. It doesn’t know what to do with forward slashes. It looks for a file named “/home/jgd/foo.jpg” and when it doesn’t find it, it barfs.
Fortunately, there is a solution. Like most things in Linux, there are many solutions. The simple one is a Wine helper program called “winepath”. Winepath simply converts to and from the windows format command line. You can play around with winepath in a command shell. If I type:
$ winepath -w /home/jgd/foo.jpg
By default, Z is the “drive” in wine for the root file system. Now I could do something hinky and guru-y on the command line every time I wanted to use Irfanview such as:
$ wine /home/jgd/.wine/Program\ Files/IrfanView/iview_32 `winepath -w /home/jgd/foo.jpg`
But that wouldn’t get used too often. The back-ticks (`) mean “execute this command and substitute the results for the command. Uber-guru, right.
Fortunately the BASH shell (command prompt) makes it easy to write a script once and then forget about it. Below is a script that I called iv (for (i)rfan(v)iew)
#necessary to handle files with spaces in the name. Set the file separator to null
# so that no command line processing is done.
foo=$(winepath -w $*)
# uncomment these two lines to print diagnostics in x windows
#xmessage $* &
#xmessage $foo &
wine "/home/jgd/.wine/drive_c/Program Files/IrfanView/i_view32.exe" $foo
To use this script,open a terminal window, open an editor session from the command line like this
$ sudo gedit
We use the “sudo” command to open it as superuser because we’re going to save it in a place where superuser privileges are needed to write.
Copy the above text between the dotted lines (but not the dotted lines) to the text editor. Choose save as and type in “/usr/local/bin/iv” without the quotes. Exit the editor and then do the following:
$ cd /usr/local/bin
$sudu chmod +x iv
Those two commands make the script you just wrote executable. Now BASH will run it just like any other program. Now if I want to view my file, I’d type
$ iv /home/jgd/foo.jpg
Irfanview pops up and opens the file. Slick, eh. But it gets even better.
We don’t want to use the command line every time we want to view a file. We just want to click on it from the file manager. Now we can. Here’s how.
Use the file manager to find a .jpg file, any file. Right click on it and select “Properties” You’ll see something like this:
Select the “open with” tab (4th tab over). You’ll see something like this:
Click on the “Add” button and you’ll see something like this:
You have to click the little triangle at the bottom next to “Use a custom command” to see the entry blank. Type what you see right there.
Click on the “add button and you’ll see something like this:
Notice that the “iv” application has been added and it is checked. Click on “done” because you are. That’s all there is to it. Now when you click on .jpg, Irfanview will pop right up to show you the file. You’ll have to repeat the process for .gif, .png and any other graphic file that you want Irfanview to open.
This little script is universal in that it can be used to open any windows app that needs arguments simply by copying it to another file with a new name and editing in the name of the windows app in place of iview_32.exe.
Tuck this one away and save it even if you don’t need it right now. I’ve googled literally for hours to figure out how to do this. I got a tip from WineHQ  about winepath but I had to figure out on my own how to use it.
See, this guru stuff really isn’t once it is explained properly.
Interestingly enough, though Irfanview runs almost flawlessly under Wine, I could not get the installer to work. Fortunately Irfanview is one of those apps that can be simply copied over from the windows drive. I keep my windows drive mounted on a USB adapter so that I can retrieve things. All I had to do was navigate to “Program Files”, right click on IrfanView, select “copy”, navigate to /home/jgd/.wine/drive_c/Program Files, right click, select “paste” and Irfanview is installed. Easy as that.
If you don’t already have it installed on your C: drive then you’ll need to boot up winders and install it, then come back to Linux and copy it over.