How to make gif loop all the time in python?












0















This is my code :



from PIL import Image, ImageSequence
import os

class MyImage:
def __init__(self,file_path):
self.image = Image.open(file_path)

def get_rewind(self):
iter = ImageSequence.Iterator(self.image)
index = 1
for frame in iter:

print("image [{}] : mode {}, size {}".format(index,frame.mode,frame.size))
frame.save("./rewind-result/frame{}.png".format(index))
index += 1

sequence =

for f in ImageSequence.Iterator(self.image):
sequence.append(f.copy())

sequence.reverse()
sequence[0].save("./reverse_out.gif",save_all=True, append_images=sequence[1:])

if __name__ == '__main__':
image = MyImage("./test.gif")
image.get_rewind()


The gif is the reverse_out.gif, but it one loop once. So how to set the property of the loop?(Not by photoshop)










share|improve this question























  • What does "not by Photoshop" mean?

    – Mad Physicist
    Dec 30 '18 at 16:43











  • Also, please fix your indentation.

    – Mad Physicist
    Dec 30 '18 at 16:44











  • You don't show any code that displays the image as far asI can tell. What is the actual problem.

    – Mad Physicist
    Dec 30 '18 at 16:45
















0















This is my code :



from PIL import Image, ImageSequence
import os

class MyImage:
def __init__(self,file_path):
self.image = Image.open(file_path)

def get_rewind(self):
iter = ImageSequence.Iterator(self.image)
index = 1
for frame in iter:

print("image [{}] : mode {}, size {}".format(index,frame.mode,frame.size))
frame.save("./rewind-result/frame{}.png".format(index))
index += 1

sequence =

for f in ImageSequence.Iterator(self.image):
sequence.append(f.copy())

sequence.reverse()
sequence[0].save("./reverse_out.gif",save_all=True, append_images=sequence[1:])

if __name__ == '__main__':
image = MyImage("./test.gif")
image.get_rewind()


The gif is the reverse_out.gif, but it one loop once. So how to set the property of the loop?(Not by photoshop)










share|improve this question























  • What does "not by Photoshop" mean?

    – Mad Physicist
    Dec 30 '18 at 16:43











  • Also, please fix your indentation.

    – Mad Physicist
    Dec 30 '18 at 16:44











  • You don't show any code that displays the image as far asI can tell. What is the actual problem.

    – Mad Physicist
    Dec 30 '18 at 16:45














0












0








0








This is my code :



from PIL import Image, ImageSequence
import os

class MyImage:
def __init__(self,file_path):
self.image = Image.open(file_path)

def get_rewind(self):
iter = ImageSequence.Iterator(self.image)
index = 1
for frame in iter:

print("image [{}] : mode {}, size {}".format(index,frame.mode,frame.size))
frame.save("./rewind-result/frame{}.png".format(index))
index += 1

sequence =

for f in ImageSequence.Iterator(self.image):
sequence.append(f.copy())

sequence.reverse()
sequence[0].save("./reverse_out.gif",save_all=True, append_images=sequence[1:])

if __name__ == '__main__':
image = MyImage("./test.gif")
image.get_rewind()


The gif is the reverse_out.gif, but it one loop once. So how to set the property of the loop?(Not by photoshop)










share|improve this question














This is my code :



from PIL import Image, ImageSequence
import os

class MyImage:
def __init__(self,file_path):
self.image = Image.open(file_path)

def get_rewind(self):
iter = ImageSequence.Iterator(self.image)
index = 1
for frame in iter:

print("image [{}] : mode {}, size {}".format(index,frame.mode,frame.size))
frame.save("./rewind-result/frame{}.png".format(index))
index += 1

sequence =

for f in ImageSequence.Iterator(self.image):
sequence.append(f.copy())

sequence.reverse()
sequence[0].save("./reverse_out.gif",save_all=True, append_images=sequence[1:])

if __name__ == '__main__':
image = MyImage("./test.gif")
image.get_rewind()


The gif is the reverse_out.gif, but it one loop once. So how to set the property of the loop?(Not by photoshop)







python loops






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 30 '18 at 16:42









G.yxG.yx

238




238













  • What does "not by Photoshop" mean?

    – Mad Physicist
    Dec 30 '18 at 16:43











  • Also, please fix your indentation.

    – Mad Physicist
    Dec 30 '18 at 16:44











  • You don't show any code that displays the image as far asI can tell. What is the actual problem.

    – Mad Physicist
    Dec 30 '18 at 16:45



















  • What does "not by Photoshop" mean?

    – Mad Physicist
    Dec 30 '18 at 16:43











  • Also, please fix your indentation.

    – Mad Physicist
    Dec 30 '18 at 16:44











  • You don't show any code that displays the image as far asI can tell. What is the actual problem.

    – Mad Physicist
    Dec 30 '18 at 16:45

















What does "not by Photoshop" mean?

– Mad Physicist
Dec 30 '18 at 16:43





What does "not by Photoshop" mean?

– Mad Physicist
Dec 30 '18 at 16:43













Also, please fix your indentation.

– Mad Physicist
Dec 30 '18 at 16:44





Also, please fix your indentation.

– Mad Physicist
Dec 30 '18 at 16:44













You don't show any code that displays the image as far asI can tell. What is the actual problem.

– Mad Physicist
Dec 30 '18 at 16:45





You don't show any code that displays the image as far asI can tell. What is the actual problem.

– Mad Physicist
Dec 30 '18 at 16:45












1 Answer
1






active

oldest

votes


















0














a non-healthy method:



from tkinter import *

class GIF(Tk):
def __init__(self):
super().__init__()
self.geometry("500x500")
self.x = 0

self.img = PhotoImage(file="filename.gif", format=f"gif -index {self.x}")

self.canvas = Canvas(self,width=1366, height=768,bd=0,highlightthickness=0)
self.canvas.pack(expand = 1, fill = BOTH)

self._img = self.canvas.create_image(0, 0, image=self.img,anchor = NW)
self.run_gif()
self.mainloop()

def run_gif(self):
try:
self.img = PhotoImage(file="filename.gif", format=f"gif -index {self.x}")
self.canvas.itemconfigure(self._img, image=self.img)
self.x += 1
except:
self.x = 0

self.canvas.after(10, self.run_gif)

GIF()


But there are those who are healthy!






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53979484%2fhow-to-make-gif-loop-all-the-time-in-python%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    a non-healthy method:



    from tkinter import *

    class GIF(Tk):
    def __init__(self):
    super().__init__()
    self.geometry("500x500")
    self.x = 0

    self.img = PhotoImage(file="filename.gif", format=f"gif -index {self.x}")

    self.canvas = Canvas(self,width=1366, height=768,bd=0,highlightthickness=0)
    self.canvas.pack(expand = 1, fill = BOTH)

    self._img = self.canvas.create_image(0, 0, image=self.img,anchor = NW)
    self.run_gif()
    self.mainloop()

    def run_gif(self):
    try:
    self.img = PhotoImage(file="filename.gif", format=f"gif -index {self.x}")
    self.canvas.itemconfigure(self._img, image=self.img)
    self.x += 1
    except:
    self.x = 0

    self.canvas.after(10, self.run_gif)

    GIF()


    But there are those who are healthy!






    share|improve this answer




























      0














      a non-healthy method:



      from tkinter import *

      class GIF(Tk):
      def __init__(self):
      super().__init__()
      self.geometry("500x500")
      self.x = 0

      self.img = PhotoImage(file="filename.gif", format=f"gif -index {self.x}")

      self.canvas = Canvas(self,width=1366, height=768,bd=0,highlightthickness=0)
      self.canvas.pack(expand = 1, fill = BOTH)

      self._img = self.canvas.create_image(0, 0, image=self.img,anchor = NW)
      self.run_gif()
      self.mainloop()

      def run_gif(self):
      try:
      self.img = PhotoImage(file="filename.gif", format=f"gif -index {self.x}")
      self.canvas.itemconfigure(self._img, image=self.img)
      self.x += 1
      except:
      self.x = 0

      self.canvas.after(10, self.run_gif)

      GIF()


      But there are those who are healthy!






      share|improve this answer


























        0












        0








        0







        a non-healthy method:



        from tkinter import *

        class GIF(Tk):
        def __init__(self):
        super().__init__()
        self.geometry("500x500")
        self.x = 0

        self.img = PhotoImage(file="filename.gif", format=f"gif -index {self.x}")

        self.canvas = Canvas(self,width=1366, height=768,bd=0,highlightthickness=0)
        self.canvas.pack(expand = 1, fill = BOTH)

        self._img = self.canvas.create_image(0, 0, image=self.img,anchor = NW)
        self.run_gif()
        self.mainloop()

        def run_gif(self):
        try:
        self.img = PhotoImage(file="filename.gif", format=f"gif -index {self.x}")
        self.canvas.itemconfigure(self._img, image=self.img)
        self.x += 1
        except:
        self.x = 0

        self.canvas.after(10, self.run_gif)

        GIF()


        But there are those who are healthy!






        share|improve this answer













        a non-healthy method:



        from tkinter import *

        class GIF(Tk):
        def __init__(self):
        super().__init__()
        self.geometry("500x500")
        self.x = 0

        self.img = PhotoImage(file="filename.gif", format=f"gif -index {self.x}")

        self.canvas = Canvas(self,width=1366, height=768,bd=0,highlightthickness=0)
        self.canvas.pack(expand = 1, fill = BOTH)

        self._img = self.canvas.create_image(0, 0, image=self.img,anchor = NW)
        self.run_gif()
        self.mainloop()

        def run_gif(self):
        try:
        self.img = PhotoImage(file="filename.gif", format=f"gif -index {self.x}")
        self.canvas.itemconfigure(self._img, image=self.img)
        self.x += 1
        except:
        self.x = 0

        self.canvas.after(10, self.run_gif)

        GIF()


        But there are those who are healthy!







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 30 '18 at 18:18









        JundullahJundullah

        81210




        81210






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53979484%2fhow-to-make-gif-loop-all-the-time-in-python%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Mossoró

            Error while reading .h5 file using the rhdf5 package in R

            Pushsharp Apns notification error: 'InvalidToken'