Image Optimization Guide

On the forum I administer, I am forced to run a tight attachment policy. Disk space doesn’t grow on trees. Occasionally this leads to questions about the small attachment size limit of 50 KiB. This guide is intended to clarify that this is not nearly as tiny as you might think. Note that although I’ll mention commands without much explanation for the sake of brevity, you’re always recommended to further explore the possibilities offered by those commands with the --help flag as well as by running man the-command-here.

First you need to ask yourself what kind of file type is appropriate, if you have the choice. On screenshots, the main purpose of attachments on my forum, you’ll often encounter large areas of uniform background colors. PNG is therefore almost invariably the right choice. Crop out everything but what’s relevant. JPEG is appropriate for more dynamic pictures such as photographs. If you want to do a lot with photographs, you might want to consider an external hosting service. My wife likes SmugMug. Still, for thumbnails you might be able to do a fair bit more within a few hundred KiB than you might think. Finally, the vector graphics in SVG result in pictures that always look sharp. You’ll typically have drawn these in a program like Inkscape or Adobe Illustrator.

Table of Contents

  1. 1. Optimizing JPEG
  2. 2. Optimizing PNG
  3. 3. Optimizing SVG
  4. Addendum A: Scanned Documents
  5. Addendum B: Video

1. Optimizing JPEG

Often you’ll want to crop your file. Do not edit your JPEG followed by resaving it because this will result in reduced quality! You can crop losslessly with cropgui. On Windows you can use IrfanView.

If you don’t want to crop, and also potentially for some post-cropgui optimization, use jpegtran -copy none -progressive -optimize file.jpg > file-opt.jpg. Note that this will get rid of all metadata, which may be undesirable. If so, use jpegtran -copy all -progressive -optimize file.jpg > file-opt.jpg.

Of course if you want to scale down your JPEG there’s no point in mucking about with lossless cropping first. After scaling down, check how long your quality can go (also see a little helper script I wrote). In any case, you should avoid introducing any unnecessary compression steps with associated quality loss. Here are some results:

  • The original 11.jpg at 2.19 MB.
  • Losslessly cropped 11-crop.jpg at 1.11 MB.
  • Optimized with -copy all -progressive -optimize 11-crop-opt.jpg at 1.04 MB. -copy none would’ve saved an extra whopping 40-some KiB, which on this kind of filesize has little benefit, and besides, I quite like the metadata. For thumbnail-sized files the balance is likely to be different. For example, the 52.2 KiB SmugMug auto-generated thumbnail below can be insignificantly reduced to 51.1 KiB with --copy all, but to 48.2 KiB with --copy none. I think an 8% reduction is not too shabby, plus it brings the file size down to under the arbitrary 50 KiB limit on my forum.

2. Optimizing PNG

As I wrote in the introduction, for screenshots PNG is typically the right choice. If you want to use lossless PNG, use optipng -o7. In my experience it’s ever so slightly smaller than other solutions like pngcrush. But as long as you use a PNG optimizer it shouldn’t much matter which one you fancy. Also see this comparison.

If you don’t care about potentially losing some color accuracy, use pngquant instead. To top it off, if you really want to squeeze out your PNG, you can pass quality settings with --quality min-max, meaning you can pass --quality 30-50 or just --quality 10. Here are some quick results for the screenshot in the SVG section below, but be sure to check out the pngquant website for some impressive examples.


$ du -h --apparent-size inkscape-plain-svg.png
27K	inkscape-plain-svg.png

$ du -h --apparent-size inkscape-plain-svg-fs8\ default.png 
7.6K	inkscape-plain-svg-fs8 default.png

$ du -h --apparent-size inkscape-plain-svg-fs8\ quality\ 10.png 
4.3K	inkscape-plain-svg-fs8 quality 10.png

In this case there is no visual distinction between the original PNG and the default pngquant settings. The quality 10 result is almost imperceptibly worse unless you look closely, so I didn’t bother to include a sample.

3. Optimizing SVG

For using SVG on the web, I imagine I don’t have to tell you that in Inkscape, you should save your file as Plain SVG.

Save as Plain SVG in Inkscape.

What you may not know is that just like there are lossy PNGs, you can also create what amounts to lossy SVGs. There are some command-line tools to optimize SVGs, including (partially thanks to this SO answer):

  • Scour is probably the best command line tool for some quick optimization. You can just use the defaults like scour < in.svg > out.svg or scour -i in.svg -o out.svg. But I recommend you go further.
  • SVGO (SVG Optimizer)
  • SVG-optimiser (by Peter Collingridge)
  • SVG-editor (by Peter Collingridge

My personal preference for squeezing out every last byte goes toward the web-based version of the SVG-editor by Peter Collingridge. By running it in a browser with inferior SVG support such as Firefox, you’ll be sure that your optimized SVG still works properly afterward. The command line tools can only safely be used for basic optimizations, whereas the effects of going lossy (such as lowering precision) can only be fully appreciated graphically.

Addendum A: Scanned Documents

Scanned documents are a different item altogether. The best format for private use is DjVu, but for public sharing PDF is probably preferable. To achieve the best results, you should scan your documents in TIFF or PNG, followed by processing with unpaper or ScanTailor. If you’ve already got a PDF you’d like to improve, you can use pdfsandwich or my own readablepdf.

Addendum B: Video

I’m not aware of any lossless optimization for video compression such as offered by jpegtran, but you can often losslessly cut video. In the general purpose Avidemux, simply make sure both video and audio are set to copy. There is also a dedicated cross-platform app for lossless trimming of videos called, unsurprisingly, LosslessCut. If you do want to introduce loss for a smaller file size you can use the very same Avidemux with a different setting, ffmpeg, mpv, VLC, and so forth. You can get reasonable quality that’ll play many places with something like:

ffmpeg -i input-file.ext -c:v libx264 -crf 19 -preset slow -c:a libfaac -b:a 192k -ac 2 output-file.mp4

For the open WebM format, you can use along these lines:

ffmpeg -i input.mp4 -c:v libvpx -b:v 1M -c:a libvorbis output.webm

More examples on the ffmpeg wiki. Note that in many cases you should just copy the audio using -acodec copy, but of course that’s not always an option. Extra compression artifacts in audio detract significantly more from the experience than low-quality video.

CommentsTags:

SSD Performance in Modern Laptops

After acquiring a new laptop in October ’16, I was surprised to find how fast the old Intel Core 2 laptop still felt. To dig a little deeper, I decided to shoddily compare the performance of the first (SATA) SSD I ever bought back in 2010 to the (M2) SSD in my new 2016 ASUS UX305C. The old laptop did not feel faster than the new one as such, but between an ’09 AMD Phenom II and an Intel i7 there was a really noticeable speed increase on the same SSD. But this new laptop actually seemed to be slower at installing programs.

  • screenshot_2016-11-03_15-02-37-benchmark-ssd-120gb-2010-fs8
  • screenshot_2016-11-03_15-06-56-ssd-64gb-2015-zenbook-ux305c-fs8

Obviously in 2016 and beyond I’d strongly consider upgrading to a larger model, but that it could also be worthwhile to upgrade for performance reasons saddens me. The write rate is particularly bad, and this can be felt in software installation taking longer than on the old laptop. NB The old laptop originally came with a significantly slower HDD, so I suppose I shouldn’t be surprised that my old desktop SSD performed better… Still, I was expecting more. As long as it’s better than your average HDD I suppose I can’t complain.

CommentsTags:

Two Weeks is not Ample Time, IMDb

Ah, it’s always nice to be greeted by a message of decay on a sunny Sunday morning.

Because IMDb’s message boards continue to be utilized by a small but passionate community of IMDb users, we announced our decision to disable our message boards on February 3, 2017 but will leave them open for two additional weeks so that users will have ample time to archive any message board content they’d like to keep for personal use.

Source.

Because of my annoyance with that cavalier turn of phrase about “ample time,” I’ll share an entry from my private Zim notebook.

Monday 16 Jan 2017

Noticed Inventum on F-Droid, a simple TMDb (The Movie Database) client. This in turn led me to omdb (Open Media Database).

Something to keep in mind if IMDb ever goes bad.

Another potentially interesting website is Letterboxd.

It’s a pity that omdb isn’t the MusicBrainz of movies. The Movie DB looks like a more viable alternative with a possibly more usable website than recent IMDb to boot, but I’m not sure if it is as open. Still, you can use their API to scrape the entire DB. Note that The Movie DB is essentially a fork of 2008-era omdb data, as stated on older versions of their about page.

Comments

libGL error in Steam and Broken Age in Debian Stretch

After some update or other, Broken Age refused to start.

$ ./start.sh 
Running Broken Age
libGL error: unable to load driver: radeonsi_dri.so
libGL error: driver pointer missing
libGL error: failed to load driver: radeonsi
libGL error: unable to load driver: swrast_dri.so
libGL error: failed to load driver: swrast
X Error of failed request:  BadValue (integer parameter out of range for operation)
  Major opcode of failed request:  155 (GLX)
  Minor opcode of failed request:  3 (X_GLXCreateContext)
  Value in failed request:  0x0
  Serial number of failed request:  91
  Current serial number in output stream:  92

Oh well, let’s give it a little hand, shall we?

LD_PRELOAD='/usr/lib/i386-linux-gnu/libstdc++.so.6 /lib/i386-linux-gnu/libgpg-error.so.0' ./start.sh

This loads the included libraries before any others, in order to override the incompatible libraries shipped with the program in question. The same trick also works for Steam. If gaming is your goal, you should probably stick to whatever version of Ubuntu is supported best. I’m just pleased that I can play the occasional game like Oxenfree (no preloading required, mind you) or Broken Age on my workhorse without having to install any stability-reducing binary blobs.

Comments (1)Tags: ,

More Joyous Machine Translation Failures

Last year I wrote a little about Gmail’s interesting attempt to translate English to English. Similar failures pop up from time to time, but usually I forget to take screenshots as evidence. This time I did.

A few weeks ago, while I was reading La vie: mode d’emploi, I came across a term I didn’t know. “La pièce où nous nous trouvons maintenant — un fumoir bibliothèque — est assez représentative de son travail.” (The room in which we find ourselves now — a fumoir bibliothèque — is fairly representative of her work. At the top of p. 134 in my copy.) Obviously a bibliothèque is a library, but I was a little less sure on the smoke-related part — fumer is to smoke. Ergo, in a brief moment of madness I decided to type the phrase into Google Translate rather than to look it up in my Aard version of Wiktionary or in Le Petit Robert.

Fumoir bibliothèque (uppercase F) = fireplace

Obviously it’s not a place to burn books, now is it? Wiktionary defines a fumoir (2) as a “Pièce qui, dans les appartements, dans les hôtels, dans les entreprises, est réservée aux fumeurs.” A room that, in apartments, in hotels, in enterprises is reserved to smokers. A smoking room. Ah, that makes more sense. But the titular joyous part refers to what happens when you change that automatic uppercase letter to a lowercase one.

fumoir bibliothèque (lowercase F) = smoking room

Well, there you go. I’d say a smoking room with books or a smoking library is a distinction worth keeping, but statistics can sure do funny things.

CommentsTags:

Ricochet : word sonnets = sonnets d’un mot

Although the one-word sonnets are defended of being worthy of the name sonnet in the introduction I have some lingering doubts: sonnets have a great many rules, and here there’s only the rule of 14 words, one per line. Perhaps I’m the purist, who thinks that “le terme quatorzain, qui désigne de façon générale tout poème de quatorze vers, conviendrait mieux.” But no matter what you call these haiku-like intensely precise little poems, they’re quite good. The French translation is also outstanding. My favorites are “Sleep” (p. 58), “Substance Abuse” (p. 98) and “Anti-Semitism” (p. 112).

Seymour Mayne, Sabine Huynh (Translator) (2011). Ricochet : word sonnets = sonnets d’un mot. Freely available from http://www.oapen.org/search?identifier=515358.

★★★★

CommentsTags: ,

Magnificent Borderline Puerility: The Great Gatsby

The Great Gatsby is a terrific example of how a bunch of money-obsessed, vacuous, overall completely unsympathetic characters can still combine into an atmospheric, humorous, layered and meaningful piece of writing. Without the always present, borderline puerile ironic undertone this may well have been absolutely terrible. Minor spoilers follow.

Somehow I’d never read The Great Gatsby. Unfortunately it’s constantly and surprisingly ubiquitously referenced, and a few days ago an almost undoubtedly wrong, random Internet comment served as the straw that broke the camel’s back. It was claimed that in Gatsby’s library you could see he didn’t read his books because his bindings were intact. All that tells you is that a person is not an animal. What must’ve evidently been meant is that the pages were uncut, still held together in their signatures. To see an uncut book is a rarity these days, though I find that in my own century-old books often the first few pages remain uncut. In any event, my suspicions were quickly confirmed. Gatsby hadn’t cut his pages, but not a peep about the bindings.

F. Scott Fitzgerald, Guy Reynolds (foreword) (2001). The Great Gatsby.

★★★★½

CommentsTags:

Fix No gksu(do) Permissions Prompt on Gparted, Synaptic, Mounting Drives, Etc. in Debian

I run Debian Stretch (testing) as my daily driver, and at some point I stopped being able to start programs like start Synaptic, Gparted, Synaptic etc. without manually typing gksu(do). The solution is as simple as it is seemingly unnecessary and stupid:

sudo apt install policykit-1-gnome

The problem is apparent upon reading the description:

This implementation was originally designed for GNOME 2, but most
GNOME-based desktop environments, including GNOME 3, GNOME Flashback,
MATE and Cinnamon, have their own built-in PolicyKit agents and no
longer use this one. The remaining users of this implementation
are XFCE and Unity.

Reported as Debian bug #843224. My first?


D’oh, I wrote this on November 5, 2016. I’ll still publish it anyway in case it’ll still help someone searching for a solution.

CommentsTags: ,

A Well-Deserved Classic: Van den vos Reynaerde

Van den vos Reynaerde has it all: deception, conflict, sarcasm, violence, (homosexual) innuendo, parody, and black humor. To top it off, it’s even featured on the Index Librorum Prohibitorum — the Papal seal of quality.

Our hero in this epic is Reynaert, a wily fox. Surrounded by nobility and other animals that are lustful, voracious, miserly, and greedy, the basic moral of the story is that you can only be deceived if you’re greedy. The narrator always hints at or even tells you what the result of the next part of the story will be, but it’s all about the how, not the what.

This particular edition is very good. The introduction tells about the various Reynaert stories across Europe, and much more; the text itself seems to have the perfect amount of footnotes to make dictionary use unnecessary, unless you want to know more about the etymology of a word. Generally, though not always, the footnotes call out attention to similar words in e.g. German and English, when clarifying certain words that are no longer in use. The commentary on the text in the back gives much background information on why even seemingly innocent descriptions might carry meaning.

However, I suppose that you might want to try one of the translations into Modern Dutch, even if you’re a native speaker of Dutch, unless Middle Dutch interests you. For that purpose I hope that there’s an edition that puts the original text and the translation side by side.

F. Lulofs (ed.) (2001). Van den Vos Reynaerde.

★★★★★

I originally wrote this review on Goodreads on January 15, 2012.

Comments (1)Tags:

Of Horology and Letters

The fashionable thing to do these days would probably be to write a graphic novel based on the epistolary contacts of the Huygens family. Heck, I’d read it. But Lisa Jardine shows that just plain good writing is more than enough to keep you glued to the pages in this page-turner essay collection about archival science. Yes, you read that right, and no, there’s no irony hidden between the lines. Download the open-access book right now (clickety-click) and read chapter 3: “Never Trust a Pirate: Christiaan Huygens’s Longitude Clocks.” You can thank me later.

The first and titular essay is perhaps the worst of the collection, which is not nearly as bad a thing as you might think. Consider, after all, that it was the first essay on which I based my decision to read the rest of the book. A bigger thematic outlier is the final essay, which essentially offers a theoretical framework. This book is a paragon of intimate yet in-depth, meticulously sourced writing. As a bonus you’re given all of the relevant transcriptions in appendices at the end. The only thing which I felt was somewhat lacking, if only in a footnote, was a discussion of the deeper intricacies of the languages used in letter writing. Obviously (courtly) French was in vogue at the time, and I know that you could show off your language skills and appropriate register, but I was still somewhat surprised to see that every quoted intra-familial letter seemed to be in French. To experts I suppose this is so self-evident that it’s not the least bit remarkable. One thing is clear after reading this volume: the North Sea was referred to as the Narrow Sea with reason. England and the Netherlands were closely linked indeed.

Lisa Jardine (2015), Temptation in the Archives. DOI: 10.14324/111.9781910634035.

★★★★½

CommentsTags:

Older Entries »