def create(self): if self.time_of_day > 1: bg = resource_stream('pokeminer', 'static/assets/notification-bg-night.png') else: bg = resource_stream('pokeminer', 'static/assets/notification-bg-day.png') ims = cairo.ImageSurface.create_from_png(bg) self.context = cairo.Context(ims) pokepic = resource_stream( 'pokeminer', 'static/original-icons/{}.png'.format(self.pokemon_id)) self.draw_stats() self.draw_image(pokepic, 204, 224) self.draw_name() image = NamedTemporaryFile(suffix='.png', delete=True) ims.write_to_png(image) image.mode = 'rb' return image