links2  web 

2025-01-25

Primitivist's guide to linkology

ema and links2 popup menu

Working with images inside links2.

Most of this tutorial concerns itself with the TUI version of links2, as GUI links renders images itself. You should know however that the guide for associating file formats with external programs is handy for GUI links as well. This should become obvious with the pdf example below.

This is (not) an image

this is (not) an image

During your TUI links lifestyle you are bound to come across an image file. Selecting it will present you with this menu:

opening undefined file in TUI

Save will save the file, Display will attempt to display it inside links in binary, like so:

Display image in binary

Let's instead tell links we want to open image files in an external program.

Esc - Setup - Associations

TUI menu

By default there will be no associations. Press Add.

Next we define a bunch of image file formats and the program to open those in. The other options are for your consideration. You probably want Run in X-Window checked, if you're planning to open the image in a GUI program.

Label: image
Content-Type(s): image/png,image/jpeg,image/webp
Progam ('%' is replaced with file name): feh %

TUI associations

Now whenever you select (Enter or mouse click) an image of a format that is defined in Associations, a new option Open will be present (you could skip this prompt by checking Ask before opening). Choosing open and pressing Enter will open the image in the desired program.

DO REMEMBER: If you want any changes in links' settings to persist, you HAVE to save them. Esc - s - s (Setup - Save options)

opening image in TUI links

Note that if an image is enclosed in <a>, thus working as a url, pressing Enter will not give you this prompt to open the image. You must instead press i (or Esc - Link - View image). Keep an eye on the url preview at the bottom left to know what you're highlighting and where it leads.

TUI url preview leading to an image file

TUI url preview leading to an https address

GUI - application/pdf example

In this example a url pointing to a .pdf file is opened. Initially links doesn't know what to do with it.

gui unknown file

Just like with images, a new file association is added. Here I use mupdf to open application/pdf files.

gui associations menu

Now when the url is clicked and the option Open is selected, mupdf opens the pdf.

gui opening pdf file

Consult this file which lists a large selection of potential mime types you could parse through links, courtesy of OpenBSD's /usr/share/misc/mime.types.

Ie:

Content-Type: video/mp4,video/webm,image/gif
Program: mpv %

will open .mp4, .webm and .gif files in mpv.

Images and how to spot them

Firstly, it is vital that you enable: Display links to images, in Esc - View - Html options. With this disabled, you will not be able to see where an image that doesn't have alt defined (blame webdevs) is. This will show [IMG] where otherwise nothing would be. Additionally you can also select Display image filenames in the same menu, this will instead show the filename.

tui html options

With images disabled, know that in GUI links you cannot select an image that is not enclosed in <a> with a keyboard. You have to use a mouse. This is not an issue in TUI links, where both urls and all images can be selected with the up and down arrow keys.

The following examples show you the differences how links handles hidden images in both GUI and TUI.

The following screenshots render this code:

<h2>img with alt, no a href</h2>
<p><img src="pic.png" alt="this is an image alt of an image that is not enclosed in a href"></p>

<h2>img without alt, no a href</h2>
<p><img src="pic.png"></p>

<h2>img with alt, enclosed with a href</h2>
<p><a href="/"><img src="pic.png" alt="this is an image alt of an image that is enclosed in a href"></a></p>

<h2>img without alt, enclosed with a href</h2>
<p><a href="/"><img src="pic.png"></a></p>

TUI - Display links to images is disabled:

tui-links-links-disabled

Notice that the second image is completely missing, and cannot be selected in any way. The first image is selected.

TUI - Display links to images is enabled:

tui-links-links-enabled

The second image is now visible and can be selected with both mouse and keyboard.

GUI - Display links to images is disabled:

gui-links-links-disabled

Same as TUI, there's no way to tell there is an image.

GUI - Display links to images is enabled, Display image filenames is enabled:

gui-links-links-enabled

This example shows the difference when Display image filenames is enabled. The now visible second image is right clicked with a mouse to show the popup menu. In GUI, this can only be achieved with a mouse.

working the muscle memory

Kill all connections

For when a website is loading way too much stuff. Similar to stop loading this page in other browsers.

Press: Esc - f - t

Display/disable images

This has multiple uses. Notably if a website is downloading too many images, you can kill this process instantly. If images are disabled when a new page is opened, they are not loaded at all and will only load once images are re-enabled. This is only available in GUI links.

Press: *

and actually, I surf with images disabled

GUI Caveat

GUI links2 doesn't play animated gifs and there is currently no way to automatize opening gifs (or any other images files) externally via Associations (it works as expected in TUI links). You have to manually copy the url of the gif and open it in something else (or save it and open it locally with a different program).

Related: