Fixing the Blank Image Bug in WordPress

A recent update to this site brought a nasty bug: social networks displayed a blank image next to posts not containing any image. It was a bit tedious to manually remove them (and they can’t be removed in Flipboard).

The bug was introduced when I updated the JetPack plugin from 2.5 (if memory serves) to the latest 2.7. In a rather stupid move this version puts an og:image Open Graph tag pointing to a blank image if the post doesn’t contain one. Digging around the ‘net showed that this issue was present in 2.6 and that the folks at JetPack think that it’s good this way. Well… Leaving the offending tag’s removal the only possible way to fix it.

Fortunately this is pretty simple: add the following code to the end of the theme’s functions.php file. It will remove the og:image tag when JetPack sets the default blank image.

The code snippet fixes another issue: JetPack sets the twitter:site¬†tag to their own Twitter account – another no-no. Just don’t forget to replace my Twitter with yours ūüôā

function fix_jp_og_bugs ($og_tags)
{
    $og_tags['twitter:site'] = '@laszlop';

    if  (0 == strcmp ($og_tags['og:image'],
        "http://wordpress.com/i/blank.jpg")
    {
        unset ($og_tags['og:image']);
    }

    return $og_tags;
}

add_filter ('jetpack_open_graph_tags', 'fix_jp_og_bugs', 11);

30-bit Color Depth on the Mac

This morning I was trying to find information about 30-bit (10 bits per component) color depth support on Macs. As you might guess, I found nothing usable. Although high-end graphics cards from both AMD and NVIDIA support the OpenGL extension for 10 bpc color, Apple does not advertise their machines as such.

So I ended up creating a little tool for assessing 10 bpc color capability. The following code tries to create a window with 10 bpc and queries the result (this code is highly similar to those found in AMD’s and NVIDIA’s 10 bpc guides).

#include <stdio.h>
#include <GLUT/GLUT.h>

int main (int argc, char *argv[])
{
    glutInit (&argc, argv);

    //
    // Request a 10-bit per component bit depth and create
    // the window.
    //

    glutInitDisplayString ("red=10 green=10 blue=10 alpha=2");
    glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    int window = glutCreateWindow ("bitdepth");

    //
    // Check how many bits we have.
    //

    GLint red, green, blue;
    glGetIntegerv (GL_RED_BITS, &red);
    glGetIntegerv (GL_GREEN_BITS, &green);
    glGetIntegerv (GL_BLUE_BITS, &blue);

    //
    // Clean up and show results.
    //

    glutDestroyWindow (window);

    printf ("Bit depth is %d/%d/%d\n", red, green, blue);

    return 0;
}

You should link with the OpenGL and GLUT frameworks.

Or you can grab the compiled executable here. It runs on 10.5 and up. Just run it and it will display the assessment result:

Bit depth is 8/8/8

I currently have no access to newer Mac Pros, which I suspect to have 30-bit support. So if you have and got 10/10/10, please let us know in the comments!

Replacement for Downloader Pro on OS X

I have used Downloader Pro for ages to download and rename my photos. Downloading is the easier part, but I’m using a file naming system for uniquely naming all my original RAW files. Unfortunately, Downloader Pro is Windows only, and as I had moved to using Macs I really missed that functionality. You might say that I should use another app with the same functionality. There’s the gotcha: there is no app that can produce the exact same naming, and I don’t want to change it after having ten years in my archive.

I’m still surprised that my simple naming convention asks too much from apps like Lightroom. My file names look like the following:

BBB_YYWW_NNNN.EXT

Where BBB is the body’s identifier, such as 5D3; YY is the two digit year; WW is the week number; NNNN is the original image number and EXT is the original extension. Plain and simple. The resulting names are like 5D3_1226_0923.CR2.

Today booting Windows under Parallels proved to be too much hassle, so I spent an hour on creating a Perl script that renames the files exactly the way I want. Now I can download the cards in Finder, and then just execute my fixnames script in the download folder to produce names following my convention.

You will need to install Phil Harvey’s exiftool Perl module to run the script.

The source is below. Use and modify at your own risk, no support of any kind ūüôā

#!/usr/bin/perl -w

# Camera name abbreviation table
my %cameraNames = (
    "Canon EOS 5D Mark III", "5D3",
    "Canon EOS-1D Mark II", "1D2"
);

use strict;
use File::Basename;
use DateTime;
BEGIN { unshift @INC, "/usr/bin/lib"; }
use Image::ExifTool;

my $path;
my $exifTool = new Image::ExifTool;

$exifTool->Options (StrictDate => 1, DateFormat => "%Y%m%d");

foreach $path (<./*.[Cc][Rr]2>)
{
    # Get EXIF data
    my $info = $exifTool->ImageInfo ($path, "Model",
        "DateTimeOriginal", "FileIndex");

    # Extract the date
    my ($c, $y, $m, $d) = $$info{"DateTimeOriginal"} =~
         /^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$/;
    my $dt = new DateTime (year => $c.$y, month => $m, day => $d);

    # Get the last 4 digits of the file name in case FileIndex
    # is not available
    my $index = $$info{"FileIndex"};
    if (!$index) {
        ($index) = basename ($path) =~ /.*([0-9]{4})\.[Cc][Rr]2$/;
    }

    # Generate the new file name
    my $newName = sprintf ("%s_%02d%02d_%04d.CR2",
        $cameraNames{$$info{"Model"}}, $y, $dt->week_number (),
        $index);

    # Rename the file
    print basename ($path), " -> ", $newName, "\n";
    rename $path, dirname ($path)."/".$newName;
}