def METHOD_NAME(image_obj):
    '''Given the image object, get all the the licenses found for packages
    in the image. The SPDX spec requires that each license reference be
    unique for the document'''
    block = ''
    licenses = set()
    for layer in image_obj.layers:
        for package in layer.packages:
            if package.pkg_license:
                licenses.add(package.pkg_license)
            # Add debian licenses from copyright text as one license
            if package.pkg_licenses:
                licenses.add(", ".join(package.pkg_licenses))
    for lic in licenses:
        valid_expression, _ = spdx_common.is_spdx_license_expression(lic)
        if not valid_expression:
            block += spdx_formats.license_id.format(
                license_ref=spdx_common.get_license_ref(lic)) + '\n'
            block += spdx_formats.extracted_text.format(orig_license=lic) + '\n'
    return block