How to make gif loop all the time in python?
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
add a comment |
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
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
add a comment |
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
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
python loops
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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!
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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!
add a comment |
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!
add a comment |
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!
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!
answered Dec 30 '18 at 18:18
JundullahJundullah
81210
81210
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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