def read_multiple(self, images, extension=None): gif_writer = GifWriter() img_buffer = BytesIO() duration = [] converted_images = [] xy = [] dispose = [] for im in images: duration.append(float(im.info.get('duration', 80)) / 1000) converted_images.append(im.convert("RGB")) xy.append((0, 0)) dispose.append(1) loop = int(self.image.info.get('loop', 1)) images = gif_writer.convertImagesToPIL(converted_images, False, None) gif_writer.writeGifToFile(img_buffer, images, duration, loop, xy, dispose) results = img_buffer.getvalue() img_buffer.close() tmp_fd, tmp_file_path = mkstemp() f = os.fdopen(tmp_fd, "w") f.write(results) f.close() command = [ 'gifsicle', '--colors', '256', tmp_file_path ] popen = Popen(command, stdout=PIPE) pipe = popen.stdout pipe_output = pipe.read() pipe.close() if popen.wait() == 0: results = pipe_output os.remove(tmp_file_path) return results
def read_multiple(self, images, extension=None): gif_writer = GifWriter() img_buffer = BytesIO() duration = [] converted_images = [] coordinates = [] dispose = [] for image in images: duration.append(image.info.get("duration", 80) / 1000) converted_images.append(image.convert("RGB")) coordinates.append((0, 0)) dispose.append(1) loop = int(self.image.info.get("loop", 1)) images = gif_writer.convertImagesToPIL(converted_images, False, None) gif_writer.writeGifToFile(img_buffer, images, duration, loop, coordinates, dispose) results = img_buffer.getvalue() img_buffer.close() tmp_fd, tmp_file_path = mkstemp() temp_file = os.fdopen(tmp_fd, "wb") temp_file.write(results) temp_file.close() command = ["gifsicle", "--colors", "256", tmp_file_path] popen = Popen( # pylint: disable=consider-using-with command, stdout=PIPE) pipe = popen.stdout pipe_output = pipe.read() pipe.close() if popen.wait() == 0: results = pipe_output os.remove(tmp_file_path) return results