Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
level3-lesson22-diy2
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
05fcec2d
authored
Mar 20, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
2b3ba018
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
12 deletions
My_GIF.py
My_GIF.py
View file @
05fcec2d
from
PIL
import
Image
from
PIL
import
Image
,
ImageSequence
from
tkinter
import
filedialog
from
tkinter
import
Tk
from
os
import
system
w
=
Tk
()
w
.
withdraw
()
path
=
filedialog
.
askopenfilenames
(
title
=
'选择图片文件'
,
filetypes
=
[(
"png"
,
".png"
)],
initialdir
=
"./"
)
sc
=
input
(
"请选择加工方式(1合成gif,2倒放gif):"
)
imgl
=
[]
for
i
in
path
:
img
=
Image
.
open
(
i
)
imgl
.
append
(
img
)
def
make_gif
():
w
=
Tk
()
w
.
withdraw
()
path
=
filedialog
.
askopenfilenames
(
title
=
'选择图片文件'
,
filetypes
=
[(
"png"
,
".png .jpg .bmp .jpeg"
)],
initialdir
=
"./"
)
imgl
=
[]
for
i
in
path
:
img
=
Image
.
open
(
i
)
imgl
.
append
(
img
)
imgl
[
0
]
.
save
(
"MyGIF.gif"
,
save_all
=
True
,
append_images
=
imgl
[
1
:])
def
replay_gif
():
w
=
Tk
()
w
.
withdraw
()
path
=
filedialog
.
askopenfilename
(
title
=
'选择动图文件'
,
filetypes
=
[(
"动态图片"
,
".gif"
)],
initialdir
=
"./"
)
img
=
Image
.
open
(
path
)
nmp
=
0
for
i
in
ImageSequence
.
Iterator
(
img
):
i
.
save
(
"./Img.TMP
\\
"
+
str
(
nmp
)
+
".tmp.png"
)
nmp
+=
1
imgl
=
[]
for
i
in
range
(
nmp
):
img
=
Image
.
open
(
"./Img.TMP
\\
"
+
str
(
i
)
+
".tmp.png"
)
imgl
.
insert
(
0
,
img
)
imgl
[
0
]
.
save
(
"MyGIF.gif"
,
save_all
=
True
,
append_images
=
imgl
[
1
:])
system
(
"del Img.TMP"
)
if
sc
==
"1"
:
make_gif
()
elif
sc
==
"2"
:
replay_gif
()
imgl
[
0
]
.
save
(
"MyGIF.gif"
,
save_all
=
True
,
append_images
=
imgl
[
1
:])
print
(
path
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment