Elliott C. Back: Internet & Technology

Using the ImageShack XML API

Posted in Code,Graphics by Elliott Back on June 1st, 2008.

If you wanted to start a free photo uploading site, but didn’t want to pay the fixed storage and bandwidth costs of Amazon’s S3 or another CDN service, you might be interested in the free ImageShack API. Currently, it allows you to upload a photo to the ImageShack service, and get back the image’s size, a photo URL, and a thumbnail URL. You can access their API by using a simple ImageShack php class:

class ImageShack 
    var $is_url = "http://www.imageshack.us/index.php";
    var $is_result = false;
    var $is_result_parsed = false;
    public function upload( $file )
        // send the image to ImageShack
        $ch = curl_init($this->is_url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_TIMEOUT, 240);
        curl_setopt($ch, CURLOPT_POSTFIELDS, array( ‘xml’=>‘yes’, ‘fileupload’=>‘@’.$file ));
        curl_setopt($ch, CURLOPT_HTTPHEADER, array( ‘Expect: ’ ));
        $this->is_result = curl_exec($ch);
        // Parse the result
    public function get_image_url()
        return $this->get( "image_link" );
    public function get_thumb_url()
        return $this->get( "thumb_link" );
    public function get_done_page()
        return $this->get( "done_page" );

    public function get_resolution()
        return $this->get( "resolution" );
    public function get_size()
        return $this->get( "filesize" );
    private function get( $key )
        if( !$this->is_result_parsed )
            return false;
        return( $this->is_result_parsed[ $key ] );
    private function parse()
        if (strpos($this->is_result, '<'.'?xml version=”1.0″ encoding="iso-8859-1″?>') === false)
            $this->is_result_parsed = false;
        $xmlData = explode("\n",$this->is_result);
        $xmlr = array();
        foreach($xmlData as $xmlDatum){
            $xmlDatum = trim($xmlDatum);
            if($xmlDatum != "" && !eregi("links",$xmlDatum) && !eregi("xml",$xmlDatum)){
                $xmlDatum = str_replace(">","<",$xmlDatum);
                list($xmlNull,$xmlName,$xmlValue) = explode("<",$xmlDatum);
                $xmlr[$xmlName] = $xmlValue;
        $this->is_result_parsed = $xmlr;

Accepting file uploads in PHP is almost trivial. You just need a form on a web page somewhere with multipart encoding, such as:

<form enctype="multipart/form-data" id="uploadform" method="post" action="http://example.com/path/to/upload">
<input type="hidden" name="MAX_FILE_SIZE" value="1048576">
<input id="anchor_file" type="file" name="files[]" />
<input type="submit" value="" id="submitimages" name="submitimages" />

On the server side, you need to iterate through the special $_FILES array in PHP:

for($i = 1; $i < count($_FILES['files']['name']); $i++){
    $error = $_FILES['files']['error'][$i];
    if($error !== 0) break;

    $data = array(
        'name' => $_FILES['files']['name'][$i],
        'temp' => $_FILES['files']['tmp_name'][$i],
        'size' => $_FILES['files']['size'][$i]

    // do something with $data now, like upload it to ImageShack

With these bits, it’s easy to write a wraparound interface to ImageShack. In the future, I hope their API also includes being able to query for photos, comments, and ratings after uploading; at the moment I see now way to do that.

Titanic Passenger List Images For Download

Posted in History,Photo by Elliott Back on April 15th, 2007.

The RMS Titanic famously collided with an iceberg on April 14, 1912 and sunk on April 15, 1912. Of the 2,224 people on board, only 1,084 were ushered onto lifeboats, and 711 finally saved. The wreck of the ship lies at a depth of 12,500 feet (3800 m), south-east of Newfoundland at 41°43′55″N, 49°56′45″W.

Passenger lists have been available for a long time, having been published in print in newspapers after the Titanic sank in 1912. What has only recently been made public is the original documents themselves, handwritten passenger registries. Here are scans from the National Archive.

10 April 1912, departing Southampton to NYC
11 April 1912, departing Queenstown to NYC


I’ve put both ships registries into one Flickr set; beware, the full-size images are each about 5MB (think 4202 x 5997). I’m not sure what the copyright status is of this work, but seeing as it’s a historical document of great importance, and generated by the British government, it should be in the public domain.

Adsense Google Images Incorrect

Posted in Adsense,Interface,UI by Elliott Back on December 22nd, 2006.

There’s a UI bug in the new Google Adsense banners that include text links and the image logo. The problem is that the images do not inherit the correct background color:



As you can see in the contrast-enhanced image, the image retains a white background on top of whatever I specified. Where’s the famous Google attention to detail?

Next Page »