3

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

Ilya Peterov
  • 1,975
  • 1
  • 16
  • 33

2 Answers2

3

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

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

Although it doesn't say explicitly, it supports viewing PGM, PPM, GIF, PNG formats, so I assume it can save to these formats as well.

Gerrat
  • 28,863
  • 9
  • 73
  • 101
2

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
  • 74,910
  • 12
  • 133
  • 166