Discover more from hrbrmstr's Daily Drop
librsvg; icat; tv
It looks like today is "Command Line Monday" (let's see if I can manage to consistently make that "a thing" each week).
In other news, I cannot guarantee a daily edition cadence this week as I'm on a ✈️ Monday & Friday + at a company off-site Tue-Thu.
Also, no section header images today as they would have broken email distribution since I have three example images for each utility embedded in each section.
(How Substack became the dominant newsletter platform with so many quirks and limitations is beyond me.)
Convert SVG files to other image formats USAGE: rsvg-convert [FLAGS] [OPTIONS] [FILE]... FLAGS: -?, --help Prints help information -a, --keep-aspect-ratio Preserve the aspect ratio --keep-image-data Keep image data --no-keep-image-data Do not keep image data -u, --unlimited Allow huge SVG files -v, --version Prints version information OPTIONS: -l, --accept-language <languages> Languages to accept, for example "es-MX,de,en" [default uses language from the environment] -b, --background-color <color> Set the background color using a CSS color spec -i, --export-id <object id> SVG id of object to export [default is to export all objects] -f, --format <format> Output format [default: png] [possible values: Png, Pdf, Ps, Eps, Svg] --left <length> Distance between left edge of page and the image [defaults to 0] -o, --output <output> Output filename [defaults to stdout] --page-height <length> Height of output media [defaults to the height of the SVG] --page-width <length> Width of output media [defaults to the width of the SVG] -d, --dpi-x <number> Pixels per inch [default: 96] -p, --dpi-y <number> Pixels per inch [default: 96] -w, --width <length> Width [defaults to the width of the SVG] -h, --height <length> Height [defaults to the height of the SVG] -s, --stylesheet <filename.css> Filename of CSS stylesheet to apply --top <length> Distance between top edge of page and the image [defaults to 0] -z, --zoom <number> Zoom factor -x, --x-zoom <number> Horizontal zoom factor -y, --y-zoom <number> Vertical zoom factor
Here's a basic example that pulls the R SVG logo from the internet and converts it to PNG (we'll expand upon in the next section)
curl --silent https://www.r-project.org/logo/Rlogo.svg | rsvg-convert > /tmp/r.png
SVGs are becoming increasingly popular as they tend to be smaller than and scale more nicely than bitmaps, plus have much better browser support now that Internet Explorer is finally dead. Having this utility in your back pocket will make quick work of any SVG conversions you may need.
icat stands "image cat", with "cat" being a reference to the command line utility for displaying files.
icat can output images on a 256-color or 24-bit color enabled terminal with UTF-8 locale. Many modern terminals support those requirements (even Apple's basic Terminal.app), including previously mentioned Warp and WezTerm.
Let's grab and display that R SVG logo again, this time using
icat to display it:
curl --silent https://www.r-project.org/logo/Rlogo.svg | rsvg-convert > /tmp/r.png && icat /tmp/r.png
(Note that I'm using the
&& control operator vs “
icat -” for reading from stdin since it seems there's something busted in one of the
icat supporting libraries preventing it from handling stdin; this was true on both macOS and Linux when I tried it.)
icat's options are fairly straightforward:
icat (0.5) outputs an image on a 256-color or 24-bit color enabled terminal with UTF-8 locale. Usage: icat [-h|--help] [-x value] [-y value] [-w|--width value] [-k|--keep] [-m|--mode indexed|24bit|both] imagefile [imagefile...] -h | --help -- Display this message -x value -- Specify the column to print the image in (min. 1) -y value -- Specify the row to print the image in (min. 1) This is ignored when more than one image is printed. -w | --width value Instead of resizing the image to fit the terminal width, use the provided value as the desired width. -k | --keep -- Keep image size, i.e. do not automatically resize image to fit the terminal width. -m | --mode indexed|24bit|both Use indexed (256-color, the default), 24-bit color, or both. imagefile -- The image to print. If the file name is "-", the file is read from stdin. Big images are automatically resized to your terminal width, unless with the -k option.
and it's super-handy to be able to preview images without loading up another GUI tool.
curl -sL https://raw.githubusercontent.com/tidyverse/dplyr/master/data-raw/starwars.csv | tv
It does one thing, does it well, and has tons of options, so no manual page or more blathering by me.
With today's CLI run-down, you no longer need to leave the terminal to preview graphics or common data files. Hopefully, this will save some time and mouse/trackpad clicks. ☮