         return nil
     }
     
-    let thumbHeader = [headerPacketVersion, UInt8(thumbWidth), UInt8(thumbHeight)]
-    packetData.appendBytes(UnsafePointer<Void>(thumbHeader), length: 3)
+    let thumbHeader = [thumbHeaderPacketVersion, thumbHeaderDataTypeIOSJPEG, UInt8(thumbWidth), UInt8(thumbHeight)]
+    packetData.appendBytes(UnsafePointer<Void>(thumbHeader), length: thumbHeader.count)
     packetData.appendData(jpegImageData)
     log.debug("packetData.length = \(packetData.length)")
     

private let jpegSOSMarker: UInt8 = 0xDA // Start of Scan
private let jpegSOF0Marker: UInt8 = 0xC0 // Start of Frame (baseline DCT-based JPEG)

// Current thumbnail packet header version
private let headerPacketVersion: UInt8 = 0x01

/// Returns the JPEG header data, reading it from bundle if not already in memory
private func getJpegHeader() -> NSData {

/**
 Creates an image out of given thumbnail image data packet (for format, see the start of this source file).
 
 This method could be somewhat CPU intense so you might consider running it in a non-UI thread.
 
 - parameter data: thumbnail packet data
 - parameter maxSize: Max dimensions to scale the image to, retaining aspect ratio.
 - parameter imageScale: value for result image's UIImage.scale. Specify 0.0 to match the scale of the device's screen.
 - returns: Scaled-up and blurred version of the thumbnail, if successful
*/
public func jpegThumbnailDataToImage(data data: NSData, maxSize: CGSize, imageScale: CGFloat = 0.0) -> UIImage? {
    log.debug("** creating image from thumbnail **")
    
    let ptr = UnsafeMutablePointer<UInt8>(data.bytes)
    if ptr[0] != thumbHeaderPacketVersion {
        log.error("Version mismatch!")
        return nil
    }
    
    if ptr[1] != thumbHeaderDataTypeIOSJPEG {
        log.error("Invalid data type value in packet: \(ptr[1])")
        return nil
    }
    
    let thumbWidth = ptr[2]
    let thumbHeight = ptr[3]
    log.debug("Read thumb size from packet: \(thumbWidth) x \(thumbHeight)")
    
    // Construct a whole JPEG from a predefined header block, the jpeg data and EOI marker (2 bytes)
