2

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

Ilya Peterov
  • 1,777
  • 13
  • 31

2 Answers2

2

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).

Gerrat
  • 27,594
  • 8
  • 70
  • 98
1

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")
Kevin
  • 72,202
  • 12
  • 116
  • 152