Converting HPI files

Six years ago I bought 25 000 Hemera Photo Objects. It was a bargain and I got four CD disks of high-quality photo objects ready to use. Everything worked fine until my computer crashed six months ago. Today I was about to install the photos on my new computer, but unfortunately couldn’t find the registration card for the serial number. Hemera’s photo are stored with rare HPI file extension. The abbreviation stands for Hemera Photo-Object Image and the file usually cannot be directly read without Hemera’s own software.

Surfing on the net I soon learned how to crack the cryptic file. It turned out to contain two separate image files combined into one with additional header information at the beginning. The first 32 bytes make a fixed header. After this header follows the main color image in JPEG format. A separate grayscale mask information follows the main image and is stored in PNG format. The PNG mask can be found using a distinctive string of "ø211PNG", where ø211 is an octal number for 137 decimal. Converting an HPI file is made in two phases.

File conversion

I made a short PHP script to break the HPI file into two separate files, the first one is for the color information and the other file contains the grayscale mask.

// read the file contents into a string $f = file_get_contents('TESTFILE.HPI'); // find the separator string $p = strpos($f, chr(137) . 'PNG'); // write the JPG file $fp = fopen('photo.jpg', 'w'); fwrite($fp, substr($f, 32, $p - 32)); fclose($fp); // write the PNG file $fp = fopen('mask.png', 'w'); fwrite($fp, substr($f, $p)); fclose($fp);

The code snippet above is designed for PHP 4, but in case you are using newer version 5, you could use file_put_contents()-function instead to write the file.

Applying the mask

Separating the image files is only the first step unless the rough JPG file is good enough for your purposes. The image usually has sharp edges which are smoothed with the grayscale mask. PHP also has built-in image manipulation functions in GD library and it normally needs no installation as it comes bundled in the distribution package. I used an imagemask PHP class by Andrew Collington to apply the mask. This class does the required trick by combining the original JPG file with the mask resulting a crisp image with smooth edges.

require 'class.imagemask.php'; $i = new imageMask('FFFFFF'); $i->maskOption(mdCENTRE); if ($im->loadImage('photo.jpg')) {   if ($im->applyMask('mask.png')) {     $i->saveImage('final.png');   } }

Final words

Breaking apart an HPI file is easy and quickly made with two steps. Hemera’s browsing and extracting software still has its advantages. It uses a keyword database to find the desired image and it also converts images to various formats with scaling. Although I now can use the images I purchased without the original software I still keep looking for the missing registration card in order to find the required serial number for authentic installation.

Julkaistu sunnuntaina 8.2.2009 klo 17:03.

Edellinen
New York from the Air
Seuraava
David Bowie - Pinups