Sunday 29 April 2018

Drawing for the Web

When preparing content for the web, a common task is to create various line drawings, which need to be presented as images well integrated with the page. This means, for example, that any text present in the picture needs to have a similar size with the text in the body of the page, maybe a little smaller.

A little preparation goes a long way. Let’s consider a web page which uses a font size of 16px, and accepts pictures with a maximum width of 720px. How do we prepare a drawing to be included on the page?
  • Begin by deciding on a resolution for the drawing. I prefer to use metric units, so a nice resolution is 50 pixels/cm, or 127 pixels/inch; since this makes each CSS pixel in the future bitmap exactly 0.2 mm, so that a line thickness of 0.2 mm should be one CSS pixel, 0.3 mm one CSS pixel and a half, 0.4 mm two CSS pixels and so on. How many actual device pixels this is, it cannot be known; but browsers normally render web pages at simple ratios for device pixels per CSS pixels.
  • In these conditions, 16 CSS pixels, the chosen font size, is 9.07 pt; 15px is 8.50 pt almost exactly; and 14px is close to 8 pt.
Web size Resolution Drawing size Width for 720px
16px 127 pixels/inch 9.07pt 14.4 cm
15px 127 pixels/inch 8.50pt 14.4 cm
14px 127 pixels/inch 7.94pt 14.4 cm

Then there is the problem of transparency. Some web pages are shown with plain white backgrounds, but many prefer a pale colored background, to provide for a more pleasant experience for the readers, who quite often read the page in an environment with subdued light. This means that the picture must have a transparent background, and practically imposes choosing the PNG format.

The way do it is to have a dedicated color for the  background of the picture, something which is never used in the picture except as the background, and which will become transparent. #FFFFCC is a good choice. Export the picture to a higher resolution, taking care to tell your drawing program to avoid antialiasing; if we stick with the nominal 127 pixels/inch shown in the table above, then 762 pixels/inch (6 times higher) or even 1270 (10 times higher) works. Then,
  1. Open the exported bitmap in your favorite graphics editor, and make the chosen background color transparent.
  2. Resize the bitmap to the desired dimensions.
In these modern times we live in, it makes sense to prepare several versions of the bitmap, to cater for the massively different resolutions of display devices. When possible, have at least a version intended for display at the nominal 96 pixels/inch, and one at twice the resolution.

Saturday 28 April 2018

SanDisk Ultra Fit USB 3.1 Flash Drive

The SanDisk Ultra Fit USB 3.1 flash drive is a tiny storage device, which fits neatly into a USB port; it is available with capacities ranging from a puny 16 GB to a massive 256 GB. It measures 19.1 × 15.9 × 8.8 mm and weighs about 5 grams; at least Amazon says that is weighs 0.16 oz, and who am I to disbelieve them? Amazon sells it for some 70 USD, while in Romania Media Galaxy sells it for 400 RON, which is about 25% too much even taking VAT into account.

The device is made of two kinds of plastic, a smooth translucent material for the looping handle, and a tough and rough material, probably some sort of composite, for the part which goes into the USB port. On the top side it bears the calligraphic logo of SanDisk, nowadays a subsidiary of Western Digital. On the bottom, it bears a minute inscription stating that it was made in China, the part number, and a serial number which is different from the serial number reported to the operating system.
The diminutive yet capacious SanDisk Ultra Fit 3.1 compared with a Romanian 50 bani coin.

Formatting and usable capacity

The device comes formatted with the FAT32 file system, with 32 KiB clusters, the sole partition occupying sectors 32 to 480509951. Usable capacity is 246,021,095,424, about 246 GB or 229.1 GiB, some 26.9 GiB or 10.5% less than the advertised 256 GiB. Presumably, the missing capacity is used internally for overprovisioning in order to help the microcontroller cope with the intricate management of flash storage.

Since the FAT32 file system cannot store files greater that 4 GiB, it may be recommendable to reformat the device with the exFAT filesystem.

Performance

Running Crystal Dew World’s CrystalDiskMark to test the performance of the flash drive provides a double surprise:
  • The sequential write speed is about 17 MB/second, which is quite decent for such a small form factor device.
  • The random access write speed oscillates between 0.6 and 1.2 MB/second, which is very decent for such a small device. What this means is one can run virtual machines off the flash drive without too much pain; it is definitely good enough to run a small Linux virtual server.
Read speeds are very high; sequential read speed is over 110 MB/second, and random access read speed approaches 8 MB/second.
CrystalDiskMark results for the SanDisk Ultra Fit 3.1. Note that the results vary between the runs, notably for small I/O operations.
For a real-life test, I copied 511 high-resolution photographs, totalling 3.9 GB, to and from the drive; the results were as follows:
  • Writing 3.9 GB of data in 511 files, varying between 2.5 and 10.5 MB in size, took 6′ 7″, coming to about 10.6 MB/second.
  • Reading 3.9 GB of data in 511 files, varying between 2.5 and 10.5 MB in size, took 43″, coming to about 90.7 MB/second.
In use, the flash drive becomes hot quite quickly; this is where the small form factor doesn’t help at all. After writing some 2.5 GB, the drive’s thermal management monitor kicks in and throttles the transfer speed; for data transfers of more than a few gigabytes expect the average write speed to drop to about 8 MB/second or thereabouts.
SanDisk, SanDisk Ultra, and Western Digital are trademarks of Western Digital Corporation.

How to install Ubuntu Server 18.04 LTS 32-bit

Recent versions of the Ubuntu operating system tend to avoid admitting that a 32-bit variant of the distribution exists. Yet for many use cases the 32-bit variant is highly desirable. Don’t worry, it exists and is supported. You can get the 32-bit network-based installer in two ways:
The network-based installer works almost exactly like the ordinary text-based installed, with the following differences:
  • The computer on which the operating system is to be installed must be connected to the internet, obviously.
  • In order to install supplementary software in the installation environment, you must first download it. For example, to install parted, you must first use wget to get it from the web:
    POOL=http://archive.ubuntu.com/ubuntu/pool/main 
    wget $POOL/p/parted/parted-udeb_3.2-20_i386.udeb
The network-based installed is not limited to installing the Server edition of the operating system; you can use it to install any flavor or edition, with the advantage that the installed operating system is fully up-to-date, of course, the software packages being downloaded fresh from the repository.