Reply to a post by Jeremy Keith

Reply to:

Post by Jeremy Keith
at adactio.com/journal/14690

Print stylesheets are one more example of the assumption-puncturing nature of the web: don’t assume that everyone will be reading your content on a screen. News articles, blog posts, recipes, lyrics …there are many situations where a well-considered print stylesheet can make all the difference to the overall experience.

[...]

So much as I might grit my teeth, QR codes and print stylesheets make for good bedfellows.

2019-01-13

I full-heartedly agree with Jeremy: print stylesheets are one more feature of universal website design, and they go together rather well with QR codes …no matter how ugly, abused and underused they are.

There luckily is an alternative to Google’s Chart API (whose shutdown had been announced for 2015 last time I checked; that’s three years in the past). In true Indieweb manner, QR codes can be self-generated locally using the open source PHP library PHP QR Code. Its latest version is eight years old, but it still works like a charm – check out the print preview of this post for a proof of concept.

Here’s the piece of code I use with above library to generate mine, before caching them on the server for output:

<?php
if ( isset( $_REQUEST['url'] ) && trim( $_REQUEST['url'] ) != '' ) {

    include "qrlib.php";

    // a writable location, where the temp PNG files are stored
    $tempdir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR;
    if ( !file_exists( $tempdir ) )
        mkdir( $tempdir );

    // sanitize URL
    $url = filter_var( urldecode( $_REQUEST['url'] ), FILTER_SANITIZE_URL );

    // set error correction and code size
    $errcorr = 'L';   // L (low, smallest QR code) -> M -> Q -> H (highest error correction, bigger QR code)
    $size = 3;        // width/height per "QR pixel" in pixels

    // create QR code and store PNG in temp dir
    $filename = $tempdir . md5( $url .'|' . $errcorr . '|' . $size ) . '.png';
    QRcode::png( $url, $filename, $errcorr, $size, 2 );

    // open PNG file in binary mode
    $file = fopen( $filename, 'rb' );

    // send the right headers
    header( "Content-Type: image/png" );
    header( "Content-Length: " . filesize($filename) );

    // dump the picture
    fpassthru( $file );

}
?>

Jeremy, maybe this allows you to prepare your talk free from any fear over a long-declared-dead Google API going away? The library even allows for SVG output, which might be neat for presentation slides – for web print styles I believe PNG to be the format with less inconsistencies.

Responding with a post on your own blog? Submit the URL as webmention (?)
  • Bookmarked On print styles and qr

    I full-heartedly agree with Jeremy: print stylesheets are one more feature of universal website design, and they go together rather well with QR codes …no matter how ugly, abused and underused they are.
    There luckily is an alternative to Google’s Chart API (whose shutdown had been announced for ...

    Bookmarked for suggesting a good use of a QR code: put it on an artefact for people to get a printable version.

    2019-01-14