Esempio n. 1
0
def get_meta_iptc(file_stream):
    """Returns the image IPTC metadata in a dictionary of tag:value pairs.

    @param file_stream: stream
    """
    file_stream.seek(0)
    img = Image.open(file_stream)
    iptc_raw = IptcImagePlugin.getiptcinfo(img)
    metadata = {}

    if iptc_raw is None:
        return metadata

    for code, value in iptc_raw.items():
        try:
            tag = iim_codes[code]
        except KeyError:
            continue
        if isinstance(value, list):
            value = [decode(v) for v in value]
        elif isinstance(value, bytes):
            value = decode(value)
        metadata[tag] = value
    return metadata
 def test_decode(self):
     """Test decoding with encoding detection"""
     bytes_str = "téstôù".encode('latin-1')
     decoded = text_utils.decode(bytes_str)
     self.assertEqual(decoded, "téstôù")
 def test_decode(self):
     """Test decoding with encoding detection"""
     bytes_str = "téstôù".encode('latin-1')
     decoded = text_utils.decode(bytes_str)
     self.assertEqual(decoded, "téstôù")