def read(self, extension=None, quality=None):
        if quality is None:
            quality = self.context.config.QUALITY

        options = None
        extension = extension or self.extension
        try:
            if FORMATS[extension] == 'JPEG':
                options = [cv.CV_IMWRITE_JPEG_QUALITY, quality]
        except __HOLE__:
            # default is JPEG so
            options = [cv.CV_IMWRITE_JPEG_QUALITY, quality]

        data = cv.EncodeImage(extension, self.image, options or []).tostring()

        if FORMATS[extension] == 'JPEG' and self.context.config.PRESERVE_EXIF_INFO:
            if hasattr(self, 'exif'):
                img = JpegFile.fromString(data)
                img._segments.insert(0, ExifSegment(self.exif_marker, None, self.exif, 'rw'))
                data = img.writeString()

        return data
dataset/ETHPy150Open thumbor/opencv-engine/opencv_engine/engine.py/Engine.read