Skip to content

Commit

Permalink
Merge pull request #10 from northlandsnow/fix/keep-duration
Browse files Browse the repository at this point in the history
keep duration with origin gif file
  • Loading branch information
x-hw authored Nov 13, 2016
2 parents d05f990 + 96a21d7 commit 0d50b3e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions MyQR/myqr.py
Original file line number Diff line number Diff line change
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 0d50b3e

Please sign in to comment.