How to center image caption in ASCIIDoctor

Problem

A caption to an image is provided in ASCIIDoctor document as follows:

.This is a caption
image::foo.png[align="center"]

However, the caption is aligned to the left by default.

Applying a text-center on it does not work:

[.text-center]
.This is a caption
image::foo.png[align="center"]

Solution

This problem has been discussed in this Github issue. The solution provided to add a few lines to imageblock in the stylesheet does not work. Instead, I changed the default behavior itself in the stylesheet to be center.

  • To do this first find out where gems are installed:
$ gem environment
  • Go to the INSTALLATION DIRECTORY output in the above command and to the subdirectory holds ASCIIDoctor stylesheets:
$ cd gems/asciidoctor-1.5.2/data/stylesheets/
  • Open the asciidoctor-default.css and find the place where for imageblock the text-align attribute is set to left and change that to center. For me, this was in line 177.

  • Rebuild your ASCIIDoctor document and the rendered HTML should have centered image caption.

Tried with: ASCIIDoctor 1.5.2, Ruby 2.1.0 and Ubuntu 14.04

How to extract images from PDF

PDF files can have images embedded in them. Since PDF is the defacto format used for research papers, it can be sometimes necessary to extract these images. Images in a PDF file can be extracted easily using the pdfimages tool from the poppler-utils package.

  • Installation is easy:
$ sudo apt install poppler-utils
  • To list the details of images embedded in a PDF file:
$ pdfimages -list foo.pdf
page   num  type   width height color comp bpc  enc interp  object ID
---------------------------------------------------------------------
   1     0 image      80   100  icc     3   8  image  yes       11  0
   1     1 smask      80   100  gray    1   8  image  yes       11  0
   1     2 image      80   100  icc     3   8  image  yes       13  0
   1     3 smask      80   100  gray    1   8  image  yes       13  0
   1     4 image      80   100  icc     3   8  image  yes       15  0
   1     5 smask      80   100  gray    1   8  image  yes       15  0
   1     6 image      80   100  icc     3   8  image  yes       17  0
  • To extract the images embedded in a PDF file provide a prefix for the extracted image filenames:
$ pdfimages foo.pdf foo_img

$ ls foo_img*
foo_img-000.ppm
foo_img-001.ppm
foo_img-002.ppm
foo_img-003.ppm
foo_img-004.ppm
foo_img-005.ppm
foo_img-006.ppm

Tried with: PopplerUtils 0.24.5 and Ubuntu 14.04

How to specify size of image in LaTeX

An image is inserted into a LaTeX document using the includegraphics command. The size of the image can be specified in a variety of techniques:

  • Specify height or width or both in terms of cm:
width=5cm

height=3cm

width=3cm, height=10cm
  • Specify width as fraction of width of text column:
width=0.9\linewidth

width=0.7\textwidth
  • Specify scale of image:
scale=0.5

Tried with: Ubuntu 14.04

How to preview images in Ranger

Ranger is a great console tool to explore directories and files. You can find the instructions to install and configure it in this post. As you explore files in the center column, Ranger displays a preview of the file contents in the right column. If the file is an image, then Ranger displays a color ASCII version of the image using the Caca library.

However, if you use XTerm or a terminal with similar capabilities, Ranger can show an actual image preview with full color and pixels! Remember that this works only on XTerm or similar terminals.

To preview images like this, Ranger requires the w3mimgdisplay program. You can get it by installing:

$ sudo apt install w3m-img

After this, you need to set the preview_images option to true in the .config/ranger/rc.conf file. You will have this file only if you followed the instructions given above during Ranger installation.

Once you have done this, open an XTerm and enjoy full-color image previews! Note that this did not work in RXVT for me 🙂

Tried with: W3m-Img 0.5.3-15, Ranger 1.6.0 and Ubuntu 14.04

How to view images in terminal using ShellPic

ShellPic is a program that can be used to view images at any terminal. It renders the image using ASCII art and in color.

ShellPic is not packaged for Ubuntu yet. So, it can be installed from PyPI instead:

$ sudo pip install ShellPic

After installation, it can be invoked directly on any image:

$ shellpic foo.jpg

Tried with: ShellPic 1.6 and Ubuntu 14.04

How to view images in terminal using FBI

Framebuffer Image Viewer (fbi) is a program that can be used to view images at the terminal. However, it only works with actual terminals (/dev/tty), that is the terminals you get when you press Ctrl + Alt + F1 to Ctrl + Alt + F6. It does not work in pseudo terminals (/dev/pts) that are used by terminal programs running in X, like GNOME Terminal.

To install fbi:

$ sudo apt install fbi

Before using the viewer, your username needs to be added to the video group. For example, to add user joe:

$ sudo adduser joe video

After this, any image can be viewed at a real terminal using fbi:

$ fbi foo.jpg

Tried with: FBI 2.07-11 and Ubuntu 14.04

How to convert PDF to image

You may sometimes want to convert a PDF file into an image format like PNG or JPG. Doing this is easy using the convert application from ImageMagick.

If you do not have it, first install ImageMagick:

$ sudo apt install imagemagick

To convert a PDF with a single page into a JPG:

$ convert foo.pdf foo.jpg
$ ls
foo.pdf
foo.jpg

If the PDF has multiple pages, one image file is produced per page:

$ convert foo.pdf foo.png
$ ls
foo.pdf
foo-1.png
foo-2.png
foo-3.png

By default, the image file is produced at 96 DPI resolution of the PDF. If you need higher DPI, use the density option. For example, to generate at 300 DPI:

$ convert -density 300 foo.pdf foo.png

Note: The -density parameter has to come first. If you place it anywhere else, the program runs silently without complaining, but the output image will be in the default DPI.

Tried with: ImageMagick 6.7.7-10 and Ubuntu 14.04

Thumbnail Zoom Plus extension for Firefox

HoverZoom is a neat little extension I use on Chrome. Thumbnail Zoom Plus is a great alternative to this if you are using Firefox. It has all the same features and works on the same websites. Just hover the mouse on an image to see the fullsize version of it, if it exists.

Settings I use with this extension:

  • Set the Delay before display to 0.5 sec.
  • Set Default zoom to 100 percent.
  • Disable Show picture using all available space.
  • Turn off all keyboard shortcuts.

Tried with: Thumbnail Zoom Plus 2.7, Firefox 29.0 and Ubuntu 14.04

HoverZoom extension for Chrome

HoverZoom is one of those Chrome extensions that you wonder how you lived without! This is because a lot of images are shared today using links, like on Twitter. Most websites, like Facebook, show small size images which need to be clicked to view the full size image. HoverZoom makes viewing the full-size image hidden behind links and thumbnails a piece of cake.

On hovering the mouse cursor over any link or image, HoverZoom downloads the full size image and displays it. There is no need to click anything, which reduces the friction of using this operation.

Tried with: HoverZoom 4.29, Chrome 31.0.1650.63 and Ubuntu 12.04