如何解决使用 PIL 将屏幕截图保存为 gif
我正在尝试从我的浏览器录制 JS 动画并将其转换为高质量的 gif。
下面的代码有什么问题吗?
或者我缺少的更好的方法来做到这一点?
webbrowser.open_new('test.html')
start_time = time.time()
with mss() as sct:
# Part of the screen to capture
monitor = {"top": 350,"left": 50,"width": 500,"height": 400}
gif = []
images = []
frames = 1000
while "Screen capturing":
last_time = time.time()
# Get raw pixels from the screen,save it to a Numpy array
img = np.array(sct.grab(monitor))
images.append(img)
print("fps: {}".format(1 / (time.time() - last_time)))
frames -= 1
if frames == 0:
break
for img in images:
im = Image.fromarray(img)
gif.append(im)
print(len(gif))
gif[0].save('test' + '.gif',save_all=True,optimize=False,append_images=gif[1:],duration=10,loop=0)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。