def image_and_format_from_data(data):
 ba = QByteArray(data)
 buf = QBuffer(ba)
 buf.open(QBuffer.ReadOnly)
 r = QImageReader(buf)
 fmt = bytes(r.format()).decode(u'utf-8')
 return (r.read(), fmt)

def image_and_format_from_data ( data ) : ba = QByteArray ( data ) buf = QBuffer ( ba ) buf . open ( QBuffer . ReadOnly ) r = QImageReader ( buf ) fmt = bytes ( r . format ( ) ) . decode ( u'utf-8' ) return ( r . read ( ) , fmt )
create an image object from the specified data which should be a bytestring and also return the format of the image .