How can I save TKinter PhotoImage to .GIF?

Can I save a tkinter PhotoImage as .gif (or any other image extension) using only Python and tkinter?

Answer1:

Assuming photo is the variable holding your image, you should be able to just say:

photo.write('some_name.gif', format='gif')

I couldn't find a list of what formats are supported, but I think the list is really limited (I can confirm that gif worked for me though).

Answer2:

Looks like the method write can be used to save a PhotoImage to a file.

>>> help(Tkinter.PhotoImage.write) Help on method write in module Tkinter: write(self, filename, format=None, from_coords=None) unbound Tkinter.PhotoImage method Write image to file FILENAME in FORMAT starting from position FROM_COORDS.

Sample usage would be something like:

my_photo_image.write("output.gif")

人吐槽 人点赞

Recommend

Comment

用户名: 密码:
验证码: 匿名发表

你可以使用这些语言

查看评论:How can I save TKinter PhotoImage to .GIF?