Using PHP to print an image

I have a PHP script that’s supposed to print any of five .gif pictures, with the colors of the pictures determined by its arguments. What am I doing wrong?..

/*
 Given a string of hexadecimal characters, print the binary.
 */
function printHex($str) {
    // chr() converts a byte to the ascii character
    if (strlen($str)%2) {
        throw new Exception("invalid image!");
    }
    for ($i = 0; $i < strlen($str); $i+=2) {
        $one = ord($str{$i}); // get the code of the character
        $two = ord($str{$i+1});
        if (48 <= $one && $one <= 57) {
            $one -= 48;
        } elseif (65 <= $one && $one <= 70) {
            $one -= 55;
        } elseif (97 <= $one && $one <= 102) {
            $one -= 87;
        } else {
            throw new Exception("invalid hex character!");
        }
        if (48 <= $two && $two <= 57) {
            $two -= 48;
        } elseif (65 <= $two && $two <= 70) {
            $two -= 55;
        } elseif (97 <= $two && $two <= 102) {
            $two -= 87;
        } else {
            throw new Exception("invalid hex character!");
        }
        print(chr(($one <<4)|$two));
    }
}

function isvalid($str) {
    if (strlen($str) != 6) return false;
    for ($i = 0; $i < 6; $i++) {
        $char = ord($str{$i});
        if ((48 > $char || $char > 57) && (65 > $char || $char > 70) && (97 > $char || $char > 102)) return false;
    }
    return true;
}

$img = $_GET['image'];
$color = $_GET['color'];

if (!isvalid($color)) {
    throw new Exception("invalid hex color!");
}

header('Content-type: image/gif');

if ($img == 'announce') {
    printHex('4749463839611600C000800100'.$color.'FFFFFF21F90401000001002C000000001600C0000002FF8C8FA91B70001D7BD0C4386DBD77768E3161D848CB5869DE46A627E87422A8B9AF2CAF2E99F5FE9FE0014BA621D148B10161B419538878E614D3A5D25A1C4291DC6E52AA033BC537F28F634463B7E36CA679965EBFCF70BDCDF4EA7D5BF6F1EF8722119822A85383E8944838583857631624E746978707B3977909473569675946F9C6C9771787A9A5D6631AAA7A99EAB7E92A29F789AA899B487B08F8D8DB28FAABDB093CBC2BAC88DC7A4B1C19E5295B95ABA9E49BF46C4D64328B9D257D4DCCDB298E1D166ECBDD0D1A7DFA3DBD37191C8F9E0EC95A1ADB1CACBF4F9BADDE0F20337FF704923258EF1D1267FC0E2274A7AD20BE8037BCFCABB89011437B79EB080EF40851A19E8FEC46497CE84B1A238C2C25910357E65C346BB5569D042932D7BC9929A12D7368274D488FB02E722C7A73E7CF844A7376690A1268C48E288DDA139A0F2052A4143992F42A156AD5AEC73292FDC235E0C6786ED85EA90945558BB63CF2619ADB10C723B6366F22C49AB525ACA7567D1400003B');
} elseif ($img == 'lowborder') {
    printHex('47494638396180001400910200'.$color.'000000FFFFFF00000021F90401000002002C00000000800014000002814C80A9CBED0FA39CB42A63ACDEBCFB891DDF489666129EEACA428690B5F25C62B048E77AF5DEFB0F74F430C122D026F01997B45E92C88CAA9049A5F43A7256ADD8AE45BB857AC711EAF61923AB17E6331AB756B7DD6F78FC1AA2EB6FE9FB3214B0B70768E7D7042898C847C8D8E8F80819293909A968594599A9B9C91979295000003B');
} elseif ($img == 'highborder') {
    printHex('47494638396180001400910200'.$color.'000000FFFFFF00000021F90401000002002C0000000080001400000281948F29C1ED0FA39CB4DA0B95DE0AFB0F86E2C3950704A4EACAB6EE0BC7F24CB399A939F5CEF7FEAF22E10C3AA0F188FC39868DA4F3097D354CCDA8F59A9C6EAAD8AE97A7ED04BEE4B28C911B9BD7EC6020C16DCBBFE1857A8EF7A2898CBC1FABD5F73718B527488888647897D8E8F3E018A914275979466999D952A4D969135000003B');
} elseif ($img == 'middle') {
    printHex('47494638396180000100800000'.$color.'00000021F90400000000002C000000008000010000020C4C80A9CBED0FA39CB42A5300003B');
} elseif ($img == 'background') {
    printHex('47494638396158020100800000'.$color.'00000021F90400000000002C00000000580201000002180C8EA9CBED0FA39CB4DA8BB3DEBCFB0F86E24896E6890405003B');
} else {
    throw new Exception('image is not one of announce, lowborder, highborder, middle, background.');
}

(update: accidentally switched one and two in the print statement of printHex)