Skip to content

Commit

Permalink
keep duration with origin gif file
Browse files Browse the repository at this point in the history
  • Loading branch information
Jian Wang committed Oct 18, 2016
1 parent d05f990 commit 96a21d7
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions MyQR/myqr.py
Expand Up @@ -22,8 +22,8 @@
def run(words, version=1, level='H', picture=None, colorized=False, contrast=1.0, brightness=1.0, save_name=None, save_dir=os.getcwd()):

supported_chars = r"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ··,.:;+-*/\~!@#$%^&`'=<>[]()?_{}|"


# check every parameter
if not isinstance(words, str) or any(i not in supported_chars for i in words):
raise ValueError('Wrong words! Make sure the characters are supported!')
Expand Down Expand Up @@ -97,6 +97,7 @@ def combine(ver, qr_name, bg_name, colorized, contrast, brightness, save_dir, sa
import imageio

im = Image.open(picture)
duration = im.info.get('duration', 0)
im.save(os.path.join(tempdir, '0.png'))
while True:
try:
Expand All @@ -113,7 +114,7 @@ def combine(ver, qr_name, bg_name, colorized, contrast, brightness, save_dir, sa

ims = [imageio.imread(pic) for pic in imsname]
qr_name = os.path.join(save_dir, os.path.splitext(os.path.basename(picture))[0] + '_qrcode.gif') if not save_name else os.path.join(save_dir, save_name)
imageio.mimsave(qr_name, ims)
imageio.mimwrite(qr_name, ims, '.gif', **{ 'duration': duration/1000 })
elif picture:
qr_name = combine(ver, qr_name, picture, colorized, contrast, brightness, save_dir, save_name)
elif qr_name:
Expand Down

0 comments on commit 96a21d7

Please sign in to comment.