def create_image(self, buffer):
    try:
        img = Image.open(BytesIO(buffer))
    except DECOMPRESSION_BOMB_EXCEPTIONS as error:
        logger.warning('[PILEngine] create_image failed: %s', error)
        return None
    self.icc_profile = img.info.get('icc_profile')
    self.exif = img.info.get('exif')
    self.original_mode = img.mode
    self.subsampling = JpegImagePlugin.get_sampling(img)
    if (self.subsampling == (- 1)):
        self.subsampling = None
    self.qtables = getattr(img, 'quantization', None)
    if (self.context.config.ALLOW_ANIMATED_GIFS and (self.extension == '.gif')):
        frames = []
        for frame in ImageSequence.Iterator(img):
            frames.append(frame.convert('P'))
        img.seek(0)
        self.frame_count = len(frames)
        return frames
    return img
def create_image(self, buffer):
    try:
        img = Image.open(BytesIO(buffer))
    except DECOMPRESSION_BOMB_EXCEPTIONS as error:
        logger.warning('[PILEngine] create_image failed: %s', error)
        return None
    self.icc_profile = img.info.get('icc_profile')
    self.exif = img.info.get('exif')
    self.original_mode = img.mode
    self.subsampling = JpegImagePlugin.get_sampling(img)
    if (self.subsampling == (- 1)):
        self.subsampling = None
    self.qtables = getattr(img, 'quantization', None)
    if (self.context.config.ALLOW_ANIMATED_GIFS and (self.extension == '.gif')):
        frames = []
        for frame in ImageSequence.Iterator(img):
            frames.append(frame.convert('P'))
        img.seek(0)
        self.frame_count = len(frames)
        return frames
    return img