def determine_same_file(origpath, destpath, fhc=None):
    '''
    First check if hashes of the two files match. If they don't match, they
    could still be the same image if metadata has changed so open the pixel
    data using PIL and compare hashes of that.
    '''
    if not fhc:
        fhc = FileHashCache()

    if len(fhc.file_hash_cache) > 1000:
        fhc.reset()

    orig_hash = fhc.get_file_hash(origpath, 'file')
    if not orig_hash:
        orig_hash = md5(fhc.get_file(origpath, 'orig')).hexdigest()
        fhc.set_file_hash(origpath, 'file', orig_hash)

    dest_hash = fhc.get_file_hash(destpath, 'file')
    if not dest_hash:
        dest_hash = md5(fhc.get_file(destpath, 'dest')).hexdigest()
        fhc.set_file_hash(destpath, 'file', dest_hash)

    if orig_hash == dest_hash:
        return True

    # Try matching on image data (ignoring EXIF)
    if os.path.splitext(origpath)[1][1:].lower() in ['jpg', 'jpeg', 'png', ]:
        orig_hash = fhc.get_file_hash(origpath, 'image')
        if not orig_hash:
            orig_hash = md5(Image.open(StringIO(fhc.get_file(origpath, 'orig'))).tobytes()).hexdigest()
            fhc.set_file_hash(origpath, 'image', orig_hash)

        dest_hash = fhc.get_file_hash(destpath, 'image')
        if not dest_hash:
            dest_hash = md5(Image.open(StringIO(fhc.get_file(destpath, 'dest'))).tobytes()).hexdigest()
            fhc.set_file_hash(destpath, 'image', dest_hash)

        if orig_hash == dest_hash:
            return True
    # TODO: Convert raw photos into temp jpgs to do proper comparison
    return False